Skip to content

Commit

Permalink
experiment with <const> global function declarations
Browse files Browse the repository at this point in the history
  • Loading branch information
jaromil committed Oct 4, 2023
1 parent edad7c9 commit 53b6c13
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/lua/zenroom_common.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,27 @@
--]]

-- override type to recognize zenroom's types
luatype = type
_G['type'] = function(var)
local _luatype <const> = _G['type']
_G['luatype'] = _luatype

local _type <const> = function(var)
local simple = luatype(var)
if simple == "userdata" then
local meta = getmetatable(var)
if meta then return(meta.__name)
else return("unknown") end
else return(simple) end
end
_G['type'] = _type

-- TODO: optimise in C
function iszen(n)
local _iszen <const> = function(n)
for _ in n:gmatch("zenroom") do
return true
end
return false
end
_G['iszen'] = _iszen

-- workaround for a ternary conditional operator
function fif(condition, if_true, if_false)
Expand Down

0 comments on commit 53b6c13

Please sign in to comment.