diff --git a/src/lua_baselib.c b/src/lua_baselib.c index 0a35559f..a536593b 100644 --- a/src/lua_baselib.c +++ b/src/lua_baselib.c @@ -1719,6 +1719,26 @@ static int lib_rSetPlayerSkin(lua_State *L) return 0; } +// R_DATA +//////////// + +// This also doesn't exist, but we need it for texture find+replace to not be a horrible chore. +static int lib_rGetTextureName(lua_State *L) +{ + INT32 texnum = luaL_checkinteger(L, 1); + texture_t *texture; + UINT8 i; + //HUDSAFE + if (texnum < 0 || texnum >= numtextures) + return luaL_error(L, "texture number %d out of range (0 - %d)", texnum, numtextures-1); + texture = textures[texnum]; + for (i = 0; i < 8; i++) + if (!texture->name[i]) + break; + lua_pushlstring(L, texture->name, i); + return 1; +} + // S_SOUND //////////// @@ -2564,6 +2584,9 @@ static luaL_Reg lib[] = { {"R_Frame2Char",lib_rFrame2Char}, {"R_SetPlayerSkin",lib_rSetPlayerSkin}, + // r_data + {"R_GetTextureName",lib_rGetTextureName}, + // s_sound {"S_StartSound",lib_sStartSound}, {"S_StartSoundAtVolume",lib_sStartSoundAtVolume}, diff --git a/src/lua_maplib.c b/src/lua_maplib.c index a550bc8f..0b60c9c9 100644 --- a/src/lua_maplib.c +++ b/src/lua_maplib.c @@ -645,7 +645,6 @@ static int side_get(lua_State *L) { side_t *side = *((side_t **)luaL_checkudata(L, 1, META_SIDE)); enum side_e field = luaL_checkoption(L, 2, side_opt[0], side_opt); - UINT8 i; if (!side) { @@ -668,32 +667,14 @@ static int side_get(lua_State *L) lua_pushfixed(L, side->rowoffset); return 1; case side_toptexture: - { - texture_t *texture = textures[side->toptexture]; - for (i = 0; i < 8; i++) - if (!texture->name[i]) - break; - lua_pushlstring(L, texture->name, i); + lua_pushinteger(L, side->toptexture); return 1; - } case side_bottomtexture: - { - texture_t *texture = textures[side->bottomtexture]; - for (i = 0; i < 8; i++) - if (!texture->name[i]) - break; - lua_pushlstring(L, texture->name, i); + lua_pushinteger(L, side->bottomtexture); return 1; - } case side_midtexture: - { - texture_t *texture = textures[side->midtexture]; - for (i = 0; i < 8; i++) - if (!texture->name[i]) - break; - lua_pushlstring(L, texture->name, i); + lua_pushinteger(L, side->midtexture); return 1; - } case side_sector: LUA_PushUserdata(L, side->sector, META_SECTOR); return 1; @@ -739,16 +720,22 @@ static int side_set(lua_State *L) side->rowoffset = luaL_checkfixed(L, 3); break; case side_toptexture: - if (R_CheckTextureNumForName(luaL_checkstring(L, 3)) != -1) - side->toptexture = R_TextureNumForName(luaL_checkstring(L, 3)); + if (lua_isstring(L, 3)) + side->toptexture = R_TextureNumForName(lua_tostring(L, 3)); + else + side->toptexture = luaL_checkinteger(L, 3); break; case side_bottomtexture: - if (R_CheckTextureNumForName(luaL_checkstring(L, 3)) != -1) - side->bottomtexture = R_TextureNumForName(luaL_checkstring(L, 3)); + if (lua_isstring(L, 3)) + side->bottomtexture = R_TextureNumForName(lua_tostring(L, 3)); + else + side->bottomtexture = luaL_checkinteger(L, 3); break; case side_midtexture: - if (R_CheckTextureNumForName(luaL_checkstring(L, 3)) != -1) - side->midtexture = R_TextureNumForName(luaL_checkstring(L, 3)); + if (lua_isstring(L, 3)) + side->midtexture = R_TextureNumForName(lua_tostring(L, 3)); + else + side->midtexture = luaL_checkinteger(L, 3); break; case side_repeatcnt: side->repeatcnt = luaL_checkinteger(L, 3);