Skip to content

Commit

Permalink
Preserve ordering of generated Lua code (#1646)
Browse files Browse the repository at this point in the history
* Preserve ordering of generated Lua code

This fixes #1645, and (partially) reverts 68ac28.
  • Loading branch information
brndnmtthws authored Oct 13, 2023
1 parent 23a1ad3 commit bbdc708
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
1 change: 1 addition & 0 deletions 3rdparty/toluapp/src/bin/lua/all.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ dofile(path.."basic.lua")
dofile(path.."code.lua")
dofile(path.."typedef.lua")
dofile(path.."container.lua")
dofile(path.."ordered_pairs.lua")
dofile(path.."package.lua")
dofile(path.."module.lua")
dofile(path.."namespace.lua")
Expand Down
18 changes: 18 additions & 0 deletions 3rdparty/toluapp/src/bin/lua/ordered_pairs.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
local P = {}
op = P

function P:ordered_pairs(t)
local i = {}
for k in next, t do
table.insert(i, k)
end
table.sort(i)
return function()
local k = table.remove(i)
if k ~= nil then
return k, t[k]
end
end
end

return op
4 changes: 2 additions & 2 deletions 3rdparty/toluapp/src/bin/lua/package.lua
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ function classPackage:preamble ()
output('\n')
output('/* function to release collected object via destructor */')
output('#ifdef __cplusplus\n')
for i,v in ipairs(_collect) do
for i,v in op:ordered_pairs(_collect) do
output('\nstatic int '..v..' (lua_State* tolua_S)')
output('{')
output(' '..i..'* self = ('..i..'*) tolua_tousertype(tolua_S,1,0);')
Expand All @@ -152,7 +152,7 @@ function classPackage:preamble ()
if flags.t then
output("#ifndef Mtolua_typeid\n#define Mtolua_typeid(L,TI,T)\n#endif\n")
end
for n,v in ipairs(_usertype) do
for n,v in op:ordered_pairs(_usertype) do
if (not _global_classes[v]) or _global_classes[v]:check_public_access() then
output(' tolua_usertype(tolua_S,"',v,'");')
if flags.t then
Expand Down

0 comments on commit bbdc708

Please sign in to comment.