LuaJIT compatibility.

This commit is contained in:
jussi
2023-07-02 17:44:24 +03:00
parent 0e77452a1b
commit 8ad7254292
23 changed files with 966 additions and 53 deletions

View File

@@ -0,0 +1,23 @@
local bitlib = {}
function bitlib.setBit( v, i, b )
if b then
return v | 1 << i
else
return v & ~( 1 << i )
end
end
function bitlib.toggleBit( v, i )
return v ~ ( 1 << i )
end
function bitlib.getBit( v, i )
if v == nil then
return false
end
return v & ( 1 << i ) > 0
end
return bitlib

View File

@@ -41,27 +41,6 @@ function utillib.clamp( val, min, max )
return math.max( min, math.min( val, max ) )
end
-- Returns changed value ( value to be changed, index, state( bool ) )
function utillib.setBit( v, i, b )
if b then
return v | 1 << i
else
return v & ~( 1 << i )
end
end
function utillib.toggleBit( v, i )
return v ~ ( 1 << i )
end
function utillib.getBit( v, i )
if v == nil then
return false
end
return v & ( 1 << i ) > 0
end
function utillib.utf8Sub( s, i, j )
i = i or 1
j = j or -1
@@ -114,9 +93,6 @@ function utillib.split( str, sep )
for str in string.gmatch( str, "([^"..sep.."]+)" ) do
table.insert( t, str )
end
-- for s in string.gmatch( str, "([^"..sep.."]+)" ) do
-- table.insert( t, s )
-- end
return t
end

View File

@@ -1,3 +1,8 @@
-- For luaJit compatibility.
if table.unpack == nil then
table.unpack = unpack
end
Vector2 = {}
Vector2.meta = {
__index = Vector2,
@@ -25,9 +30,6 @@ Vector2.meta = {
__unm = function( v )
return Vector2:new( -v.x, -v.y )
end,
__idiv = function( v, value )
return Vector2:new( v.x // value, v.y // value )
end,
__len = function( v )
local len = 0
@@ -90,6 +92,14 @@ function Vector2:max( v2 )
return Vector2:new( math.max( self.x, v2.x ), math.max( self.y, v2.y ) )
end
function Vector2:floor()
return Vector2:new( math.floor( self.x ), math.floor( self.y ) )
end
function Vector2:ceil()
return Vector2:new( math.ceil( self.x ), math.ceil( self.y ) )
end
function Vector2:addValue( value )
return Vector2:new( RL.Vector2AddValue( self, value ) )
end

View File

@@ -1,3 +1,8 @@
-- For luaJit compatibility.
if table.unpack == nil then
table.unpack = unpack
end
Vector3 = {}
Vector3.meta = {
__index = Vector3,
@@ -25,9 +30,6 @@ Vector3.meta = {
__unm = function( v )
return Vector3:new( -v.x, -v.y, -v.z )
end,
__idiv = function( v, value )
return Vector3:new( v.x // value, v.y // value, v.z // value )
end,
__len = function( v )
local len = 0
@@ -94,6 +96,14 @@ function Vector3:max( v2 )
return Vector3:new( RL.Vector3Max( self, v2 ) )
end
function Vector3:floor()
return Vector3:new( math.floor( self.x ), math.floor( self.y ), math.floor( self.z ) )
end
function Vector3:ceil()
return Vector3:new( math.ceil( self.x ), math.ceil( self.y ), math.ceil( self.z ) )
end
function Vector3:addValue( value )
return Vector3:new( RL.Vector3AddValue( self, value ) )
end