Skip to content

Commit bbdc708

Browse files
authored
Preserve ordering of generated Lua code (#1646)
* Preserve ordering of generated Lua code This fixes #1645, and (partially) reverts 68ac28.
1 parent 23a1ad3 commit bbdc708

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

3rdparty/toluapp/src/bin/lua/all.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ dofile(path.."basic.lua")
66
dofile(path.."code.lua")
77
dofile(path.."typedef.lua")
88
dofile(path.."container.lua")
9+
dofile(path.."ordered_pairs.lua")
910
dofile(path.."package.lua")
1011
dofile(path.."module.lua")
1112
dofile(path.."namespace.lua")
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
local P = {}
2+
op = P
3+
4+
function P:ordered_pairs(t)
5+
local i = {}
6+
for k in next, t do
7+
table.insert(i, k)
8+
end
9+
table.sort(i)
10+
return function()
11+
local k = table.remove(i)
12+
if k ~= nil then
13+
return k, t[k]
14+
end
15+
end
16+
end
17+
18+
return op

3rdparty/toluapp/src/bin/lua/package.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ function classPackage:preamble ()
133133
output('\n')
134134
output('/* function to release collected object via destructor */')
135135
output('#ifdef __cplusplus\n')
136-
for i,v in ipairs(_collect) do
136+
for i,v in op:ordered_pairs(_collect) do
137137
output('\nstatic int '..v..' (lua_State* tolua_S)')
138138
output('{')
139139
output(' '..i..'* self = ('..i..'*) tolua_tousertype(tolua_S,1,0);')
@@ -152,7 +152,7 @@ function classPackage:preamble ()
152152
if flags.t then
153153
output("#ifndef Mtolua_typeid\n#define Mtolua_typeid(L,TI,T)\n#endif\n")
154154
end
155-
for n,v in ipairs(_usertype) do
155+
for n,v in op:ordered_pairs(_usertype) do
156156
if (not _global_classes[v]) or _global_classes[v]:check_public_access() then
157157
output(' tolua_usertype(tolua_S,"',v,'");')
158158
if flags.t then

0 commit comments

Comments
 (0)