Skip to content
Snippets Groups Projects
Commit 4545f954 authored by Lactozilla's avatar Lactozilla :speech_balloon:
Browse files

Add translations[] to Lua

parent 799bbe62
Branches
No related tags found
2 merge requests!2355fix newer versions of mixerx,!2190ZDoom translations
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include "r_patch.h" #include "r_patch.h"
#include "r_picformats.h" #include "r_picformats.h"
#include "r_things.h" #include "r_things.h"
#include "r_translation.h"
#include "r_draw.h" // R_GetColorByName #include "r_draw.h" // R_GetColorByName
#include "doomstat.h" // luabanks[] #include "doomstat.h" // luabanks[]
...@@ -1899,6 +1900,32 @@ static int colorramp_len(lua_State *L) ...@@ -1899,6 +1900,32 @@ static int colorramp_len(lua_State *L)
return 1; 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! // Now push all these functions into the Lua state!
...@@ -2076,6 +2103,16 @@ int LUA_InfoLib(lua_State *L) ...@@ -2076,6 +2103,16 @@ int LUA_InfoLib(lua_State *L)
lua_setmetatable(L, -2); lua_setmetatable(L, -2);
lua_setglobal(L, "skincolors"); 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_newuserdata(L, 0);
lua_createtable(L, 0, 2); lua_createtable(L, 0, 2);
lua_pushcfunction(L, lib_getSfxInfo); lua_pushcfunction(L, lib_getSfxInfo);
......
...@@ -689,6 +689,11 @@ void R_AddCustomTranslation(const char *name, int trnum) ...@@ -689,6 +689,11 @@ void R_AddCustomTranslation(const char *name, int trnum)
tr->hash = quickncasehash(name, strlen(name)); tr->hash = quickncasehash(name, strlen(name));
} }
unsigned R_NumCustomTranslations(void)
{
return numcustomtranslations;
}
remaptable_t *R_GetTranslationByID(int id) remaptable_t *R_GetTranslationByID(int id)
{ {
if (id < 0 || id >= (signed)numpaletteremaps) if (id < 0 || id >= (signed)numpaletteremaps)
......
...@@ -43,6 +43,7 @@ struct PaletteRemapParseResult *PaletteRemap_ParseTranslation(remaptable_t *tr, ...@@ -43,6 +43,7 @@ struct PaletteRemapParseResult *PaletteRemap_ParseTranslation(remaptable_t *tr,
int R_FindCustomTranslation(const char *name); int R_FindCustomTranslation(const char *name);
void R_AddCustomTranslation(const char *name, int trnum); void R_AddCustomTranslation(const char *name, int trnum);
unsigned R_NumCustomTranslations(void);
remaptable_t *R_GetTranslationByID(int id); remaptable_t *R_GetTranslationByID(int id);
void R_LoadTrnslateLumps(void); void R_LoadTrnslateLumps(void);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment