Skip to content

Lua 5.3 integer support #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 54 additions & 1 deletion types.lua
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ argtypes.index = {
end
}

for _,typename in ipairs({"real", "unsigned char", "char", "short", "int", "long", "float", "double"}) do
for _,typename in ipairs({"real", "float", "double"}) do
argtypes[typename] = {

helpname = function(arg)
Expand Down Expand Up @@ -127,6 +127,59 @@ for _,typename in ipairs({"real", "unsigned char", "char", "short", "int", "long
}
end

for _,typename in ipairs({"unsigned char", "char", "short", "int", "long"}) do
argtypes[typename] = {

helpname = function(arg)
return typename
end,

declare = function(arg)
-- if it is a number we initialize here
local default = tonumber(interpretdefaultvalue(arg)) or 0
return string.format("%s arg%d = %g;", typename, arg.i, default)
end,

check = function(arg, idx)
return string.format("lua_isnumber(L, %d)", idx)
end,

read = function(arg, idx)
return string.format("arg%d = (%s)lua_tointeger(L, %d);", arg.i, typename, idx)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wouldn't this break Lua 5.2 and Lua 5.1 support, as they do not have lua_tointeger. Can we guard it with a version check somehow?

end,

init = function(arg)
-- otherwise do it here
if arg.default then
local default = interpretdefaultvalue(arg)
if not tonumber(default) then
return string.format("arg%d = %s;", arg.i, default)
end
end
end,

carg = function(arg)
return string.format('arg%d', arg.i)
end,

creturn = function(arg)
return string.format('arg%d', arg.i)
end,

precall = function(arg)
if arg.returned then
return string.format('lua_pushinteger(L, (long)arg%d);', arg.i)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same for here and other calls to lua_*integer

end
end,

postcall = function(arg)
if arg.creturned then
return string.format('lua_pushinteger(L, (long)arg%d);', arg.i)
end
end
}
end

argtypes.byte = argtypes['unsigned char']

argtypes.boolean = {
Expand Down