Keep tostring on the stack to avoid looking it up multiple times in the
__tostring loop.
This commit is contained in:
parent
dadbf86640
commit
e7e59d4b0e
20
limmutable.c
20
limmutable.c
@ -261,33 +261,35 @@ static int Ltostring(lua_State *L)
|
||||
// Stack: [mt, buckets, bucket, inst_udata]
|
||||
lua_rawget(L, -2);
|
||||
// Stack: [mt, buckets, bucket, inst_table]
|
||||
|
||||
lua_getglobal(L, "tostring");
|
||||
// Stack: [mt, buckets, bucket, inst_table, tostring]
|
||||
lua_getfield(L, -4, "__fields");
|
||||
// Stack: [mt, buckets, bucket, inst_table, fields]
|
||||
// Stack: [mt, buckets, bucket, inst_table, tostring, fields]
|
||||
|
||||
lua_pushnil(L);
|
||||
int needs_comma = 0;
|
||||
while (lua_next(L, -2) != 0) {
|
||||
// Stack: [mt, buckets, bucket, inst_table, fields, i, fieldname]
|
||||
// Stack: [mt, buckets, bucket, inst_table, tostring, fields, i, fieldname]
|
||||
if (needs_comma) {
|
||||
luaL_addstring(&b, ", ");
|
||||
} else {
|
||||
needs_comma = 1;
|
||||
}
|
||||
// Stack: [mt, buckets, bucket, inst_table, fields, i, fieldname]
|
||||
lua_getglobal(L, "tostring");
|
||||
// Stack: [mt, buckets, bucket, inst_table, tostring, fields, i, fieldname]
|
||||
lua_pushvalue(L, -4);
|
||||
// Stack: [mt, buckets, bucket, inst_table, tostring, fields, i, fieldname, tostring]
|
||||
lua_insert(L, -2);
|
||||
lua_call(L, 1, 1);
|
||||
luaL_addvalue(&b);
|
||||
// Stack: [mt, buckets, bucket, inst_table, fields, i]
|
||||
// Stack: [mt, buckets, bucket, inst_table, tostring, fields, i]
|
||||
luaL_addstring(&b, "=");
|
||||
lua_rawgeti(L, -3, lua_tonumber(L, -1));
|
||||
// Stack: [mt, buckets, bucket, inst_table, fields, i, value]
|
||||
lua_getglobal(L, "tostring");
|
||||
// Stack: [mt, buckets, bucket, inst_table, tostring, fields, i, value]
|
||||
lua_pushvalue(L, -4);
|
||||
lua_insert(L, -2);
|
||||
lua_call(L, 1, 1);
|
||||
luaL_addvalue(&b);
|
||||
// Stack: [mt, buckets, bucket, inst_table, fields, i]
|
||||
// Stack: [mt, buckets, bucket, inst_table, tostring, fields, i]
|
||||
}
|
||||
luaL_addstring(&b, ")");
|
||||
luaL_pushresult(&b);
|
||||
|
Loading…
Reference in New Issue
Block a user