From 831e0a682517a66685f57724240c1f703ba1ec7e Mon Sep 17 00:00:00 2001 From: Kaoru HAYAMA Date: Wed, 4 Jul 2018 02:44:47 +0900 Subject: [PATCH] Support bit32.* all by github.com/BixData/gluabit32 for #319 --- mains/bit32lua.go | 14 -------------- mains/lua.go | 11 ++++++++++- 2 files changed, 10 insertions(+), 15 deletions(-) delete mode 100644 mains/bit32lua.go 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)))