From: Perttu Ahola Date: Sat, 12 Nov 2011 01:21:40 +0000 (+0200) Subject: Scripting WIP X-Git-Tag: 0.4.dev-20111201-0~201 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=ea8d6d7abd86b33169b8c2b80cd382d82ba84b8b;p=oweals%2Fminetest.git Scripting WIP --- diff --git a/data/scripts/default.lua b/data/scripts/default.lua index b6c6b0d89..ebd4e5ab6 100644 --- a/data/scripts/default.lua +++ b/data/scripts/default.lua @@ -140,7 +140,7 @@ local TNT = { physical = true, weight = 5, boundingbox = {-0.5,-0.5,-0.5, 0.5,0.5,0.5}, - visual = "box", + visual = "cube", textures = {"tnt_top.png","tnt_bottom.png","tnt_side.png","tnt_side.png","tnt_side.png","tnt_side.png"}, -- Initial value for our timer timer = 0, @@ -148,11 +148,6 @@ local TNT = { state_variables = {"timer"}, } --- Called after object is created -function TNT:on_create() - print("TNT:on_create()") -end - -- Called periodically function TNT:on_step(dtime) --print("TNT:on_step()") diff --git a/src/content_sao.cpp b/src/content_sao.cpp index 567b489d9..8a0e67a21 100644 --- a/src/content_sao.cpp +++ b/src/content_sao.cpp @@ -1504,8 +1504,10 @@ LuaEntitySAO::LuaEntitySAO(ServerEnvironment *env, v3f pos, ServerActiveObject(env, pos), m_init_name(name), m_init_state(state), - m_registered(false) + m_registered(false), + m_prop(new LuaEntityProperties) { + // Only register type if no environment supplied if(env == NULL){ ServerActiveObject::registerType(getType(), create); return; @@ -1518,6 +1520,7 @@ LuaEntitySAO::~LuaEntitySAO() lua_State *L = m_env->getLua(); scriptapi_luaentity_rm(L, m_id); } + delete m_prop; } void LuaEntitySAO::addedToEnvironment(u16 id) @@ -1528,6 +1531,10 @@ void LuaEntitySAO::addedToEnvironment(u16 id) m_registered = true; lua_State *L = m_env->getLua(); scriptapi_luaentity_add(L, id, m_init_name.c_str(), m_init_state.c_str()); + + // Get properties + *m_prop = scriptapi_luaentity_get_properties(L, m_id); + infostream<<"m_prop->visual="<visual<': /* end of arguments */ - goto endargs; - default: - script_error(L, "invalid option (%c)", *(sig - 1)); - } - } -endargs: - - nres = strlen(sig); /* number of expected results */ - - if (lua_pcall(L, narg, nres, 0) != 0) /* do the call */ - script_error(L, "error calling '%s': %s", func, lua_tostring(L, -1)); - - nres = -nres; /* stack index of first result */ - while (*sig) { /* repeat for each result */ - switch (*sig++) { - case 'd': /* double result */ - if (!lua_isnumber(L, nres)) - script_error(L, "wrong result type"); - *va_arg(vl, double *) = lua_tonumber(L, nres); - break; - case 'i': /* int result */ - if (!lua_isnumber(L, nres)) - script_error(L, "wrong result type"); - *va_arg(vl, int *) = lua_tointeger(L, nres); - break; - case 's': /* string result */ - if (!lua_isstring(L, nres)) - script_error(L, "wrong result type"); - *va_arg(vl, const char **) = lua_tostring(L, nres); - break; - default: - script_error(L, "invalid option (%c)", *(sig - 1)); - } - nres++; - } - - va_end(vl); -} - bool script_load(lua_State *L, const char *path) { infostream<<"Loading and running script from "< boundingbox; + std::string visual; + core::list textures; + + LuaEntityProperties(): + physical(true), + weight(5), + boundingbox(-0.5,-0.5,-0.5, 0.5,0.5,0.5), + visual("cube") + { + textures.push_back("unknown_block.png"); + textures.push_back("unknown_block.png"); + textures.push_back("unknown_block.png"); + textures.push_back("unknown_block.png"); + textures.push_back("unknown_block.png"); + textures.push_back("unknown_block.png"); + } +}; + void scriptapi_luaentity_add(lua_State *L, u16 id, const char *name, const char *init_state); void scriptapi_luaentity_rm(lua_State *L, u16 id); std::string scriptapi_luaentity_get_state(lua_State *L, u16 id); +LuaEntityProperties scriptapi_luaentity_get_properties(lua_State *L, u16 id); void scriptapi_luaentity_step(lua_State *L, u16 id, float dtime); void scriptapi_luaentity_rightclick_player(lua_State *L, u16 id, const char *playername);