bad argument #2 to '__newindex' (not a number in proper range)

未关闭
#110 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

@efegokdemir 已经在做这个了。

开始于 2026年11月7日。

  • #154 来自 @efegokdemir —— 未关闭

评估

难度
4/5
预计耗时
3-5 天
新手友好度
30/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
go
领域
backend

调研方向

Reproduce with the Lua line string.format("%012d", 34567890121111) from test1.lua, first on amd64 and then cross-compiled with GOOS=linux GOARCH=arm GOARM=7, and compare the two results. The reported error is 'bad argument #2 to '__newindex' (not a number in proper range)'. Done means the value formats correctly on 32-bit ARM, or the 32-bit integer limit is documented. The issue has no maintainer reply, so the scope is unconfirmed.

由索引模型根据 Issue 内容生成。

描述

is go-lua can only run in 64bit machine?
when i run my lua script on ubuntu 64 bit, it works ok( lua test.lua), and i run my golang code using go run main.go,int works ok too,
but when i just cross compile the same golang code using GOOS=linux GOARCH=arm GOARM=7 go build main.go
error occured,
i hope to use go-lua on my 32bit arm board,
root@b503_lcd:# uname -a
Linux b503_lcd 4.1.15-2.1.0+g37e48c8 #90 SMP PREEMPT Fri Oct 26 11:41:29 CST 2018 armv7l GNU/Linux
root@b503_lcd:
# ./main
test go lua...
this is CONNECT,127.0.0.15050
panic: runtime error: test.lua:34: bad argument #2 to '__newindex' (not a number in proper range)
goroutine 1 [running]:
main.main()
/mnt/hgfs/b503/gopath/src/golua/main.go:11 +0xa0

the 34 line is string.format("%012d",34567890121111)
why? is go-lua can only run in 64bit machine?

Here's my test:
package main
import "github.com/Shopify/go-lua"
import "fmt"
var arg1 = 1
var arg2 = 2
func add(x, y int) int {
fmt.Printf("this is go func add\n")
return x + y
}

var luatestGofunc0 = func(l *lua.State) int {
fmt.Printf("this is a go func-0 called by lua script!\n")
top := l.Top()
fmt.Printf("top:%d\n", top)
a0 := l.ToUserData(0)
a1 := l.ToUserData(1)
a2 := l.ToUserData(2)
fmt.Printf("ao,a1,a2=%#v,%#v,%#v\n", a0, a1, a2)
return 2
}

func main() {
fmt.Printf("hello golang,test lua script...\n")
l := lua.NewState()
l.Register("LtestGofunc0", luatestGofunc0)
l.Register("LtestGofunc1", func(l *lua.State) int {
fmt.Printf("this is a go func 1...\n")
return 0
})
lua.OpenLibraries(l)
if err := lua.DoFile(l, "test1.lua"); err != nil {
panic(err)
}
}

bellow is test1.lua:
this is a lua script demo:

ip= "127.0.0.1"
port = 5050

function CONNECT( ip,port )
print("this is CONNECT,"..ip..port)
end

function TxData( tx )
print("this is TxData,"..tx)
end

function DISCONNECT( ... )
print("this is DISCONNECT")
end

ret = CONNECT(ip,port)

MTI = 'B001' --
STI = '52' --
DBL = '0000001C' --
DATA = '' --

shanghu = string.format("%012d",34567890121111) ----------------------the 34 line
poscode = string.format("%016d",34567890112233)
samcode = '313233343536'
optcode = '3132333435363738'

DATA = shanghu..poscode..samcode..optcode
DBL = string.format("%08x",string.len(DATA)/2)
TX = MTI .. STI .. DBL .. DATA

ret,rcv = TxData(TX)
print(rcv)

MTI = 'B004'
blackver = '00000000'
DATA = blackver .. poscode
DBL = string.format("%02x",string.len(DATA)/2)
TX = MTI .. STI .. DBL .. DATA

ret,rcv = TxData(TX)
print(rcv)

DISCONNECT()

主要语言
Go
星标
3.5k
派生
217
PR 合并指标
30 天内没有已合并 PR

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

Shopify/go-lua 的其他 Issue

查看 Shopify/go-lua 的全部 Issue

相似的 Issue

更多 Go Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。