Skip to content

Commit

Permalink
copy nyagos.bitand -> bit32.band, nyagos.bitor -> bit32.bor for #319
Browse files Browse the repository at this point in the history
  • Loading branch information
hymkor committed Jun 11, 2018
1 parent e84b2eb commit 36d69d4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 17 deletions.
19 changes: 3 additions & 16 deletions mains/bit32lua.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,12 @@ package mains

import (
"github.com/yuin/gopher-lua"
"github.com/zetamatta/nyagos/functions"
)

func bit32and(L *lua.LState) int {
result := ^0
for n := L.GetTop(); n > 0; n-- {
value, ok := L.Get(n).(lua.LNumber)
if !ok {
L.Push(lua.LNil)
L.Push(lua.LString("bit32.and: found NaN"))
return 2
}
result = result & int(value)
}
L.Push(lua.LNumber(result))
return 1
}

func SetupBit32Table(L *lua.LState) {
table := L.NewTable()
L.SetField(table, "band", L.NewFunction(bit32and))
L.SetField(table, "band", L.NewFunction(lua2cmd(functions.CmdBitAnd)))
L.SetField(table, "bor", L.NewFunction(lua2cmd(functions.CmdBitOr)))
L.SetGlobal("bit32", table)
}
3 changes: 2 additions & 1 deletion t/tst_bit32.lua
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
print( bit32.band(1,3) == 1 )
print( "bit32.band(1,3) ==" , bit32.band(1,3) )
print( "bit32.bor(1,3) ==" ,bit32.bor(1,3))

0 comments on commit 36d69d4

Please sign in to comment.