aboutsummaryrefslogtreecommitdiff
path: root/src/script/cpp_api
ModeNameSize
-rw-r--r--CMakeLists.txt639logplain
-rw-r--r--s_async.cpp7504logplain
-rw-r--r--s_async.h4117logplain
-rw-r--r--s_base.cpp9550logplain
-rw-r--r--s_base.h3951logplain
-rw-r--r--s_client.cpp5922logplain
-rw-r--r--s_client.h1937logplain
-rw-r--r--s_entity.cpp8714logplain
-rw-r--r--s_entity.h1616logplain
-rw-r--r--s_env.cpp7320logplain
-rw-r--r--s_env.h1505logplain
-rw-r--r--s_internal.h2929logplain
-rw-r--r--s_inventory.cpp7745logplain
-rw-r--r--s_inventory.h2342logplain
-rw-r--r--s_item.cpp7083logplain
-rw-r--r--s_item.h1978logplain
-rw-r--r--s_mainmenu.cpp2660logplain
-rw-r--r--s_mainmenu.h1454logplain
-rw-r--r--s_node.cpp8013logplain
-rw-r--r--s_node.h2016logplain
-rw-r--r--s_nodemeta.cpp8155logplain
-rw-r--r--s_nodemeta.h2220logplain
-rw-r--r--s_player.cpp5481logplain
-rw-r--r--s_player.h1830logplain
-rw-r--r--s_security.cpp18722logplain
-rw-r--r--s_security.h2807logplain
-rw-r--r--s_server.cpp4532logplain
-rw-r--r--s_server.h1559logplain
t">(lua_State *L, int narg) { luaL_checktype(L, narg, LUA_TUSERDATA); void *ud = luaL_checkudata(L, narg, className); if(!ud) luaL_typerror(L, narg, className); return *(NodeMetaRef**)ud; // unbox pointer } NodeMetadata* NodeMetaRef::getmeta(NodeMetaRef *ref, bool auto_create) { NodeMetadata *meta = ref->m_env->getMap().getNodeMetadata(ref->m_p); if(meta == NULL && auto_create) { meta = new NodeMetadata(ref->m_env->getGameDef()->idef()); if(!ref->m_env->getMap().setNodeMetadata(ref->m_p, meta)) { delete meta; return NULL; } } return meta; } void NodeMetaRef::reportMetadataChange(NodeMetaRef *ref) { // NOTE: This same code is in rollback_interface.cpp // Inform other things that the metadata has changed v3s16 blockpos = getNodeBlockPos(ref->m_p); MapEditEvent event; event.type = MEET_BLOCK_NODE_METADATA_CHANGED; event.p = blockpos; ref->m_env->getMap().dispatchEvent(&event); // Set the block to be saved MapBlock *block = ref->m_env->getMap().getBlockNoCreateNoEx(blockpos); if (block) { block->raiseModified(MOD_STATE_WRITE_NEEDED, MOD_REASON_REPORT_META_CHANGE); } } // Exported functions // garbage collector int NodeMetaRef::gc_object(lua_State *L) { NodeMetaRef *o = *(NodeMetaRef **)(lua_touserdata(L, 1)); delete o; return 0; } // get_string(self, name) int NodeMetaRef::l_get_string(lua_State *L) { MAP_LOCK_REQUIRED; NodeMetaRef *ref = checkobject(L, 1); std::string name = luaL_checkstring(L, 2); NodeMetadata *meta = getmeta(ref, false); if(meta == NULL){ lua_pushlstring(L, "", 0); return 1; } std::string str = meta->getString(name); lua_pushlstring(L, str.c_str(), str.size()); return 1; } // set_string(self, name, var) int NodeMetaRef::l_set_string(lua_State *L) { MAP_LOCK_REQUIRED; NodeMetaRef *ref = checkobject(L, 1); std::string name = luaL_checkstring(L, 2); size_t len = 0; const char *s = lua_tolstring(L, 3, &len); std::string str(s, len); NodeMetadata *meta = getmeta(ref, !str.empty()); if(meta == NULL || str == meta->getString(name)) return 0; meta->setString(name, str); reportMetadataChange(ref); return 0; } // get_int(self, name) int NodeMetaRef::l_get_int(lua_State *L) { MAP_LOCK_REQUIRED; NodeMetaRef *ref = checkobject(L, 1); std::string name = lua_tostring(L, 2); NodeMetadata *meta = getmeta(ref, false); if(meta == NULL){ lua_pushnumber(L, 0); return 1; } std::string str = meta->getString(name); lua_pushnumber(L, stoi(str)); return 1; } // set_int(self, name, var) int NodeMetaRef::l_set_int(lua_State *L) { MAP_LOCK_REQUIRED; NodeMetaRef *ref = checkobject(L, 1); std::string name = lua_tostring(L, 2); int a = lua_tointeger(L, 3); std::string str = itos(a); NodeMetadata *meta = getmeta(ref, true); if(meta == NULL || str == meta->getString(name)) return 0; meta->setString(name, str); reportMetadataChange(ref); return 0; } // get_float(self, name) int NodeMetaRef::l_get_float(lua_State *L) { MAP_LOCK_REQUIRED; NodeMetaRef *ref = checkobject(L, 1); std::string name = lua_tostring(L, 2); NodeMetadata *meta = getmeta(ref, false); if(meta == NULL){ lua_pushnumber(L, 0); return 1; } std::string str = meta->getString(name); lua_pushnumber(L, stof(str)); return 1; } // set_float(self, name, var) int NodeMetaRef::l_set_float(lua_State *L) { MAP_LOCK_REQUIRED; NodeMetaRef *ref = checkobject(L, 1); std::string name = lua_tostring(L, 2); float a = lua_tonumber(L, 3); std::string str = ftos(a); NodeMetadata *meta = getmeta(ref, true); if(meta == NULL || str == meta->getString(name)) return 0; meta->setString(name, str); reportMetadataChange(ref); return 0; } // get_inventory(self) int NodeMetaRef::l_get_inventory(lua_State *L) { MAP_LOCK_REQUIRED; NodeMetaRef *ref = checkobject(L, 1); getmeta(ref, true); // try to ensure the metadata exists InvRef::createNodeMeta(L, ref->m_p); return 1; } // to_table(self) int NodeMetaRef::l_to_table(lua_State *L) { MAP_LOCK_REQUIRED; NodeMetaRef *ref = checkobject(L, 1); NodeMetadata *meta = getmeta(ref, true); if (meta == NULL) { lua_pushnil(L); return 1; } lua_newtable(L); // fields lua_newtable(L); { StringMap fields = meta->getStrings(); for (StringMap::const_iterator it = fields.begin(); it != fields.end(); ++it) { const std::string &name = it->first; const std::string &value = it->second; lua_pushlstring(L, name.c_str(), name.size()); lua_pushlstring(L, value.c_str(), value.size()); lua_settable(L, -3); } } lua_setfield(L, -2, "fields"); // inventory lua_newtable(L); Inventory *inv = meta->getInventory(); if (inv) { std::vector<const InventoryList *> lists = inv->getLists(); for(std::vector<const InventoryList *>::const_iterator i = lists.begin(); i != lists.end(); i++) { push_inventory_list(L, inv, (*i)->getName().c_str()); lua_setfield(L, -2, (*i)->getName().c_str()); } }