Skip to content

Commit 4d6f945

Browse files
committedJul 6, 2015
Fixed Lua 5.3 compatibility
1 parent 44c5805 commit 4d6f945

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed
 

Diff for: ‎selene/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ This is a list of the functions available on wrapped tables or strings as specif
9999
- `checkArg(n:number, obj:anything, types:string...)` This function errors when `obj` does not match any of the specified types. `n` is the index of the parameter, used for a more descriptive error message.
100100

101101
###bit32
102-
Firstly, Selene adds two convenient functions to the `bit32` library, called fish-or or `for`:
102+
Firstly, Selene adds two convenient functions to the `bit32` library (these functions are not available in Lua 5.3+), called fish-or or `for`:
103103
- `bit32.bfor(n1:number, n2:number, n3:number):number` This functions returns the bitwise fish-or of its operands. A bit will be 1 if two out of three of the operands' bits are 1.
104104
- `bit32.nfor(n1:anything, n2:anything, n3:anything):boolean` This returns `true` if two out of three of the operands are not `nil` and not `false`
105105

Diff for: ‎selene/lib/selene/init.lua

+9-4
Original file line numberDiff line numberDiff line change
@@ -832,6 +832,7 @@ local function bfor(one, two, three)
832832
checkArg(1, one, "number")
833833
checkArg(2, two, "number")
834834
checkArg(3, three, "number")
835+
if not bit32 then return end
835836
return bit32.bor(bit32.band(bit32.bnot(one), two, three), bit32.band(one, bit32.bnot(two), three), bit32.band(one, two, bit32.bnot(three)))
836837
end
837838

@@ -899,8 +900,10 @@ local function loadSelene(env)
899900
env.table.range = tbl_range
900901
env.table.zipped = tbl_zipped
901902

902-
env.bit32.bfor = bfor
903-
env.bit32.nfor = nfor
903+
if env.bit32 then
904+
env.bit32.bfor = bfor
905+
env.bit32.nfor = nfor
906+
end
904907

905908
_Table.concat = tbl_concat
906909
_Table.foreach = tbl_foreach
@@ -1009,8 +1012,10 @@ local function unloadSelene(env)
10091012
env.table.range = nil
10101013
env.table.zipped = nil
10111014

1012-
env.bit32.bfor = nil
1013-
env.bit32.nfor = nil
1015+
if env.bit32 then
1016+
env.bit32.bfor = nil
1017+
env.bit32.nfor = nil
1018+
end
10141019
end
10151020

10161021
if not _selene or not _selene.initDone then

0 commit comments

Comments
 (0)
Please sign in to comment.