diff --git a/src/lua_infolib.c b/src/lua_infolib.c index 3764acf6a..ddcd1aeea 100644 --- a/src/lua_infolib.c +++ b/src/lua_infolib.c @@ -22,6 +22,7 @@ #include "r_patch.h" #include "r_picformats.h" #include "r_things.h" +#include "r_translation.h" #include "r_draw.h" // R_GetColorByName #include "doomstat.h" // luabanks[] @@ -1899,6 +1900,32 @@ static int colorramp_len(lua_State *L) return 1; } +////////////////////// +// TRANSLATION INFO // +////////////////////// + +// Arbitrary translations[] table index -> colormap_t * +static int lib_getTranslation(lua_State *L) +{ + lua_remove(L, 1); + + const char *name = luaL_checkstring(L, 1); + remaptable_t *tr = R_GetTranslationByID(R_FindCustomTranslation(name)); + if (tr) + LUA_PushUserdata(L, &tr->remap, META_COLORMAP); + else + lua_pushnil(L); + + return 1; +} + +// #translations -> R_GetNumTranslations() +static int lib_translationslen(lua_State *L) +{ + lua_pushinteger(L, R_NumCustomTranslations()); + return 1; +} + ////////////////////////////// // // Now push all these functions into the Lua state! @@ -2076,6 +2103,16 @@ int LUA_InfoLib(lua_State *L) lua_setmetatable(L, -2); lua_setglobal(L, "skincolors"); + lua_newuserdata(L, 0); + lua_createtable(L, 0, 2); + lua_pushcfunction(L, lib_getTranslation); + lua_setfield(L, -2, "__index"); + + lua_pushcfunction(L, lib_translationslen); + lua_setfield(L, -2, "__len"); + lua_setmetatable(L, -2); + lua_setglobal(L, "translations"); + lua_newuserdata(L, 0); lua_createtable(L, 0, 2); lua_pushcfunction(L, lib_getSfxInfo); diff --git a/src/r_translation.c b/src/r_translation.c index 18106f0aa..f43ff53d2 100644 --- a/src/r_translation.c +++ b/src/r_translation.c @@ -689,6 +689,11 @@ void R_AddCustomTranslation(const char *name, int trnum) tr->hash = quickncasehash(name, strlen(name)); } +unsigned R_NumCustomTranslations(void) +{ + return numcustomtranslations; +} + remaptable_t *R_GetTranslationByID(int id) { if (id < 0 || id >= (signed)numpaletteremaps) diff --git a/src/r_translation.h b/src/r_translation.h index d54adffa0..e9ca0219f 100644 --- a/src/r_translation.h +++ b/src/r_translation.h @@ -43,6 +43,7 @@ struct PaletteRemapParseResult *PaletteRemap_ParseTranslation(remaptable_t *tr, int R_FindCustomTranslation(const char *name); void R_AddCustomTranslation(const char *name, int trnum); +unsigned R_NumCustomTranslations(void); remaptable_t *R_GetTranslationByID(int id); void R_LoadTrnslateLumps(void);