aboutsummaryrefslogtreecommitdiff
path: root/src/script/common/c_content.cpp
diff options
context:
space:
mode:
authorJude Melton-Houghton <jwmhjwmh@gmail.com>2022-10-18 18:01:44 -0400
committerGitHub <noreply@github.com>2022-10-18 18:01:44 -0400
commitb38ffdec279bcded98e34f5116c8d676aa9f73a7 (patch)
tree31cafdb009b2f81b61a96286a3800a8e408f8f3d /src/script/common/c_content.cpp
parent23e9f5db4330a6efee5270160a3959422926ce77 (diff)
downloadminetest-b38ffdec279bcded98e34f5116c8d676aa9f73a7.tar.xz
Implement vector and node conversion in Lua (#12609)
Co-authored-by: sfan5 <sfan5@live.de>
Diffstat (limited to 'src/script/common/c_content.cpp')
-rw-r--r--src/script/common/c_content.cpp44
1 files changed, 14 insertions, 30 deletions
diff --git a/src/script/common/c_content.cpp b/src/script/common/c_content.cpp
index 928717a05..cbe2d328c 100644
--- a/src/script/common/c_content.cpp
+++ b/src/script/common/c_content.cpp
@@ -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);
}
/******************************************************************************/