diff options
author | kwolekr <kwolekr@minetest.net> | 2015-05-19 02:24:14 -0400 |
---|---|---|
committer | kwolekr <kwolekr@minetest.net> | 2015-05-19 16:10:49 -0400 |
commit | da34a2b33e1f600ec11172f599384b9a92835403 (patch) | |
tree | f09a158be783f0486447d0c61750a7509760d83b /src/script/lua_api | |
parent | 603297cc352cab685dd01dcd645999624ad17c0b (diff) | |
download | minetest-da34a2b33e1f600ec11172f599384b9a92835403.tar.gz minetest-da34a2b33e1f600ec11172f599384b9a92835403.tar.bz2 minetest-da34a2b33e1f600ec11172f599384b9a92835403.zip |
Replace instances of std::map<std::string, std::string> with StringMap
Also, clean up surrounding code style
Replace by-value parameter passing with const refs when possible
Fix post-increment of iterators
Diffstat (limited to 'src/script/lua_api')
-rw-r--r-- | src/script/lua_api/l_nodemeta.cpp | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/src/script/lua_api/l_nodemeta.cpp b/src/script/lua_api/l_nodemeta.cpp index 906cc3172..6cdbe5c68 100644 --- a/src/script/lua_api/l_nodemeta.cpp +++ b/src/script/lua_api/l_nodemeta.cpp @@ -190,32 +190,34 @@ int NodeMetaRef::l_to_table(lua_State *L) NodeMetaRef *ref = checkobject(L, 1); NodeMetadata *meta = getmeta(ref, true); - if(meta == NULL){ + if (meta == NULL) { lua_pushnil(L); return 1; } lua_newtable(L); + // fields lua_newtable(L); { - std::map<std::string, std::string> fields = meta->getStrings(); - for(std::map<std::string, std::string>::const_iterator - i = fields.begin(); i != fields.end(); i++){ - const std::string &name = i->first; - const std::string &value = i->second; + 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++){ + 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()); } |