1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Implement vector and node conversion in Lua (#12609)

Co-authored-by: sfan5 <sfan5@live.de>
This commit is contained in:
Jude Melton-Houghton 2022-10-18 18:01:44 -04:00 committed by GitHub
parent 23e9f5db43
commit b38ffdec27
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
29 changed files with 191 additions and 167 deletions

View file

@ -1175,43 +1175,27 @@ NodeBox read_nodebox(lua_State *L, int index)
}
/******************************************************************************/
MapNode readnode(lua_State *L, int index, const NodeDefManager *ndef)
MapNode readnode(lua_State *L, int index)
{
lua_getfield(L, index, "name");
if (!lua_isstring(L, -1))
throw LuaError("Node name is not set or is not a string!");
std::string name = lua_tostring(L, -1);
lua_pop(L, 1);
u8 param1 = 0;
lua_getfield(L, index, "param1");
if (!lua_isnil(L, -1))
param1 = lua_tonumber(L, -1);
lua_pop(L, 1);
u8 param2 = 0;
lua_getfield(L, index, "param2");
if (!lua_isnil(L, -1))
param2 = lua_tonumber(L, -1);
lua_pop(L, 1);
content_t id = CONTENT_IGNORE;
if (!ndef->getId(name, id))
throw LuaError("\"" + name + "\" is not a registered node!");
return {id, param1, param2};
lua_pushvalue(L, index);
lua_rawgeti(L, LUA_REGISTRYINDEX, CUSTOM_RIDX_READ_NODE);
lua_insert(L, -2);
lua_call(L, 1, 3);
content_t content = lua_tointeger(L, -3);
u8 param1 = lua_tointeger(L, -2);
u8 param2 = lua_tointeger(L, -1);
lua_pop(L, 3);
return MapNode(content, param1, param2);
}
/******************************************************************************/
void pushnode(lua_State *L, const MapNode &n, const NodeDefManager *ndef)
void pushnode(lua_State *L, const MapNode &n)
{
lua_createtable(L, 0, 3);
lua_pushstring(L, ndef->get(n).name.c_str());
lua_setfield(L, -2, "name");
lua_rawgeti(L, LUA_REGISTRYINDEX, CUSTOM_RIDX_PUSH_NODE);
lua_pushinteger(L, n.getContent());
lua_pushinteger(L, n.getParam1());
lua_setfield(L, -2, "param1");
lua_pushinteger(L, n.getParam2());
lua_setfield(L, -2, "param2");
lua_call(L, 3, 1);
}
/******************************************************************************/