From 9e1c4533b8a67ee8c90f4aa70f6974b25b55640d Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Tue, 15 Nov 2011 02:03:28 +0200 Subject: Move tool definitions to script --- src/scriptapi.cpp | 97 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 96 insertions(+), 1 deletion(-) (limited to 'src/scriptapi.cpp') diff --git a/src/scriptapi.cpp b/src/scriptapi.cpp index 7b9a89f57..1bfe337ea 100644 --- a/src/scriptapi.cpp +++ b/src/scriptapi.cpp @@ -35,6 +35,7 @@ extern "C" { //#include "luna.h" #include "luaentity_common.h" #include "content_sao.h" // For LuaEntitySAO +#include "tooldef.h" /* TODO: @@ -141,8 +142,8 @@ v3f readFloatPos(lua_State *L, int index) static int l_register_entity(lua_State *L) { const char *name = luaL_checkstring(L, 1); - luaL_checktype(L, 2, LUA_TTABLE); infostream<<"register_entity: "<getWritableToolDefManager(); + + tooldef->clear(); + + return 0; /* number of results */ +} +#endif + +// register_tool(name, {lots of stuff}) +static int l_register_tool(lua_State *L) +{ + const char *name = luaL_checkstring(L, 1); + infostream<<"register_tool: "<getWritableToolDefManager(); + + int table = 2; + + ToolDefinition def; + + lua_getfield(L, table, "image"); + if(lua_isstring(L, -1)) + def.imagename = lua_tostring(L, -1); + lua_pop(L, 1); + + lua_getfield(L, table, "basetime"); + def.properties.basetime = lua_tonumber(L, -1); + lua_pop(L, 1); + + lua_getfield(L, table, "dt_weight"); + def.properties.dt_weight = lua_tonumber(L, -1); + lua_pop(L, 1); + + lua_getfield(L, table, "dt_crackiness"); + def.properties.dt_crackiness = lua_tonumber(L, -1); + lua_pop(L, 1); + + lua_getfield(L, table, "dt_crumbliness"); + def.properties.dt_crumbliness = lua_tonumber(L, -1); + lua_pop(L, 1); + + lua_getfield(L, table, "dt_cuttability"); + def.properties.dt_cuttability = lua_tonumber(L, -1); + lua_pop(L, 1); + + lua_getfield(L, table, "basedurability"); + def.properties.basedurability = lua_tonumber(L, -1); + lua_pop(L, 1); + + lua_getfield(L, table, "dd_weight"); + def.properties.dd_weight = lua_tonumber(L, -1); + lua_pop(L, 1); + + lua_getfield(L, table, "dd_crackiness"); + def.properties.dd_crackiness = lua_tonumber(L, -1); + lua_pop(L, 1); + + lua_getfield(L, table, "dd_crumbliness"); + def.properties.dd_crumbliness = lua_tonumber(L, -1); + lua_pop(L, 1); + + lua_getfield(L, table, "dd_cuttability"); + def.properties.dd_cuttability = lua_tonumber(L, -1); + lua_pop(L, 1); + + tooldef->registerTool(name, def); + + return 0; /* number of results */ +} + static const struct luaL_Reg minetest_f [] = { {"register_entity", l_register_entity}, {"register_globalstep", l_register_globalstep}, + //{"deregister_tools", l_deregister_tools}, + {"register_tool", l_register_tool}, {NULL, NULL} }; @@ -581,6 +672,10 @@ void scriptapi_export(lua_State *L, Server *server) assert(lua_checkstack(L, 20)); infostream<<"scriptapi_export"<