mirror of
https://github.com/DrBeef/Raze.git
synced 2024-11-16 01:11:28 +00:00
Lunatic: fix passing some string members to con.action(), rewrite conststruct().
... by creating a struct with 'static const int' members, as recommended on http://www.freelists.org/post/luajit/Performance-implications-of-large-FFI-constants,4 git-svn-id: https://svn.eduke32.com/eduke32@4029 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
parent
008334e7a9
commit
0a06ca29f2
3 changed files with 10 additions and 11 deletions
|
@ -123,9 +123,11 @@ local function def_action_or_move(what, tab)
|
||||||
if (what=="action") then
|
if (what=="action") then
|
||||||
-- Special default values or checking of actor members.
|
-- Special default values or checking of actor members.
|
||||||
-- KEEPINSYNC with ACTOR_CHECK in lunacon.lua for consistency.
|
-- KEEPINSYNC with ACTOR_CHECK in lunacon.lua for consistency.
|
||||||
local numframes, viewtype, incval = tab[2], tab[3], tab[4]
|
local numframes = tab[2] or tab.numframes
|
||||||
|
local viewtype = tab[3] or tab.viewtype
|
||||||
|
local incval = tab[4] or tab.incval
|
||||||
|
|
||||||
if (numframes==nil and tab.numframes==nil) then
|
if (numframes==nil) then
|
||||||
am.numframes = 1
|
am.numframes = 1
|
||||||
else
|
else
|
||||||
check_number(numframes, 4)
|
check_number(numframes, 4)
|
||||||
|
@ -134,7 +136,7 @@ local function def_action_or_move(what, tab)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if (viewtype==nil and tab.viewtype==nil) then
|
if (viewtype==nil) then
|
||||||
am.viewtype = 1
|
am.viewtype = 1
|
||||||
else
|
else
|
||||||
check_number(viewtype, 4)
|
check_number(viewtype, 4)
|
||||||
|
@ -143,7 +145,7 @@ local function def_action_or_move(what, tab)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if (incval==nil and tab.incval==nil) then
|
if (incval==nil) then
|
||||||
am.incval = 1
|
am.incval = 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -801,17 +801,14 @@ end
|
||||||
|
|
||||||
-- Construct const struct from table
|
-- Construct const struct from table
|
||||||
function conststruct(tab)
|
function conststruct(tab)
|
||||||
local strtab = { "const struct { int32_t " }
|
local strtab = { "struct {" }
|
||||||
local vals = {}
|
|
||||||
|
|
||||||
for member, val in pairs(tab) do
|
for member, val in pairs(tab) do
|
||||||
strtab[#strtab+1] = member..","
|
strtab[#strtab+1] = "static const int "..member.."="..val..";"
|
||||||
vals[#vals+1] = val
|
|
||||||
end
|
end
|
||||||
strtab[#strtab] = strtab[#strtab]:gsub(',',';')
|
|
||||||
strtab[#strtab+1] = "}"
|
strtab[#strtab+1] = "}"
|
||||||
|
|
||||||
return ffi.new(table.concat(strtab), vals)
|
return ffi.new(table.concat(strtab))
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Static, non-instance members. Used to hold constants, for example
|
-- Static, non-instance members. Used to hold constants, for example
|
||||||
|
|
|
@ -163,7 +163,7 @@ checkfail('print(sprite._nextspritesect[4].whatfield)', "attempt to index a numb
|
||||||
-- our 'require' has only safe stuff
|
-- our 'require' has only safe stuff
|
||||||
--checkfail("require('os')")
|
--checkfail("require('os')")
|
||||||
|
|
||||||
-- we must declare globals with 'gamevar'
|
-- gamevars are created using a special different mechanism
|
||||||
checkfail("new_global = 345", "attempt to write into the global environment")
|
checkfail("new_global = 345", "attempt to write into the global environment")
|
||||||
|
|
||||||
-- can't redefine constants in 'gv'
|
-- can't redefine constants in 'gv'
|
||||||
|
|
Loading…
Reference in a new issue