From 900a2c65ba12a06c9b479748fd8b5d89bbf45a76 Mon Sep 17 00:00:00 2001 From: shevernitskiy Date: Mon, 14 Aug 2023 09:02:37 +0300 Subject: [PATCH] invalid texpos is nil for lua --- library/LuaApi.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/library/LuaApi.cpp b/library/LuaApi.cpp index d61786feb..174bedb56 100644 --- a/library/LuaApi.cpp +++ b/library/LuaApi.cpp @@ -1719,13 +1719,25 @@ static int textures_loadTileset(lua_State *state) return 1; } +static int textures_getTexposByHandle(lua_State *state) +{ + auto handle = luaL_checkunsigned(state, 1); + auto texpos = Textures::getTexposByHandle(handle); + if (texpos == -1) { + lua_pushnil(state); + } else { + Lua::Push(state, texpos); + } + return 1; +} + static const LuaWrapper::FunctionReg dfhack_textures_module[] = { - WRAPM(Textures, getTexposByHandle), { NULL, NULL } }; static const luaL_Reg dfhack_textures_funcs[] = { { "loadTileset", textures_loadTileset }, + { "getTexposByHandle", textures_getTexposByHandle }, { NULL, NULL } };