diff --git a/mains/bit32lua.go b/mains/bit32lua.go deleted file mode 100644 index 52f1f3b0..00000000 --- a/mains/bit32lua.go +++ /dev/null @@ -1,14 +0,0 @@ -package mains - -import ( - "github.com/yuin/gopher-lua" - "github.com/zetamatta/nyagos/functions" -) - -func setupBit32Table(L *lua.LState) { - table := L.NewTable() - L.SetField(table, "band", L.NewFunction(lua2cmd(functions.CmdBitAnd))) - L.SetField(table, "bor", L.NewFunction(lua2cmd(functions.CmdBitOr))) - L.SetField(table, "bxor", L.NewFunction(lua2cmd(functions.CmdBitXor))) - L.SetGlobal("bit32", table) -} diff --git a/mains/lua.go b/mains/lua.go index 3d636583..49586b5f 100644 --- a/mains/lua.go +++ b/mains/lua.go @@ -9,6 +9,7 @@ import ( "runtime" "time" + "github.com/BixData/gluabit32" "github.com/yuin/gopher-lua" "github.com/zetamatta/nyagos/completion" @@ -159,7 +160,15 @@ func NewLua() (Lua, error) { L.SetGlobal("share", shareTable) setupUtf8Table(L) - setupBit32Table(L) + gluabit32.Preload(L) + L.Push(L.GetGlobal("require")) + L.Push(lua.LString("bit32")) + if err := L.PCall(1, 1, nil); err == nil { + L.SetGlobal("bit32", L.Get(-1)) + L.Pop(1) + } else { + fmt.Fprintf(os.Stderr, "bit32: %s\n", err.Error()) + } L.SetGlobal("print", L.NewFunction(lua2param(functions.CmdPrint)))