From 3ad0b6fd96f1924110857f1d081c16ad6d89df61 Mon Sep 17 00:00:00 2001 From: wolfy852 Date: Fri, 10 Feb 2023 01:02:34 -0600 Subject: [PATCH] Push musname_size and musname to Lua (correctly, this time) --- src/lua_maplib.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/lua_maplib.c b/src/lua_maplib.c index a9353be0f..1497510eb 100644 --- a/src/lua_maplib.c +++ b/src/lua_maplib.c @@ -2508,12 +2508,22 @@ static int mapheaderinfo_get(lua_State *L) lua_pushinteger(L, header->typeoflevel); else if (fastcmp(field,"keywords")) lua_pushstring(L, header->keywords); - else if (fastcmp(field,"musname")) - lua_pushstring(L, header->musname); + else if (fastcmp(field,"musname")) // we create a table here because it saves us from a userdata nightmare + { + UINT8 i; + lua_createtable(L, header->musname_size, 0); + for (i = 0; i < header->musname_size; i++) + { + lua_pushstring(L, header->musname[i]); + lua_rawseti(L, -2, 1 + i); + } + } else if (fastcmp(field,"mustrack")) lua_pushinteger(L, header->mustrack); else if (fastcmp(field,"muspos")) lua_pushinteger(L, header->muspos); + else if (fastcmp(field,"musname_size")) + lua_pushinteger(L, header->musname_size); else if (fastcmp(field,"weather")) lua_pushinteger(L, header->weather); else if (fastcmp(field,"skytexture")) @@ -2774,6 +2784,14 @@ int LUA_MapLib(lua_State *L) //lua_pushcfunction(L, mapheaderinfo_num); //lua_setfield(L, -2, "__len"); lua_pop(L, 1); + +/* luaL_newmetatable(L, META_MUSNAME); + lua_pushcfunction(L, musname_get); + lua_setfield(L, -2, "__index"); + + lua_pushcfunction(L, musname_len); + lua_setfield(L, -2, "__len"); + lua_pop(L, 1);*/ luaL_newmetatable(L, META_ACTIVATOR); lua_pushcfunction(L, activator_get);