From ea8d6d7abd86b33169b8c2b80cd382d82ba84b8b Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Sat, 12 Nov 2011 03:21:40 +0200 Subject: Scripting WIP --- src/content_sao.cpp | 9 +++++- src/content_sao.h | 3 +- src/script.cpp | 62 ------------------------------------- src/script.h | 1 - src/scriptapi.cpp | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++--- src/scriptapi.h | 24 +++++++++++++++ 6 files changed, 117 insertions(+), 70 deletions(-) (limited to 'src') 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); -- cgit v1.2.3