summaryrefslogtreecommitdiff
path: root/src/script/lua_api/l_server.cpp
diff options
context:
space:
mode:
authorShadowNinja <shadowninja@minetest.net>2013-11-30 12:11:07 -0500
committerShadowNinja <shadowninja@minetest.net>2013-11-30 13:05:13 -0500
commit4594ba652293e776ccba2184c16502a346f4147a (patch)
tree19713fac8de559ba86cd9d08d9c07cb1c7241e37 /src/script/lua_api/l_server.cpp
parent06baf05c641355ead97e9428c4455af9e8b11cef (diff)
downloadminetest-4594ba652293e776ccba2184c16502a346f4147a.tar.gz
minetest-4594ba652293e776ccba2184c16502a346f4147a.tar.bz2
minetest-4594ba652293e776ccba2184c16502a346f4147a.zip
Optimize table creation
Diffstat (limited to 'src/script/lua_api/l_server.cpp')
-rw-r--r--src/script/lua_api/l_server.cpp32
1 files changed, 8 insertions, 24 deletions
diff --git a/src/script/lua_api/l_server.cpp b/src/script/lua_api/l_server.cpp
index 19e2f1bcb..9d3575a72 100644
--- a/src/script/lua_api/l_server.cpp
+++ b/src/script/lua_api/l_server.cpp
@@ -229,16 +229,13 @@ int ModApiServer::l_get_modnames(lua_State *L)
// mods_sorted; not great performance but the number of mods on a
// server will likely be small.
for(std::list<std::string>::iterator i = mods_unsorted.begin();
- i != mods_unsorted.end(); ++i)
- {
+ i != mods_unsorted.end(); ++i) {
bool added = false;
for(std::list<std::string>::iterator x = mods_sorted.begin();
- x != mods_sorted.end(); ++x)
- {
+ x != mods_sorted.end(); ++x) {
// I doubt anybody using Minetest will be using
// anything not ASCII based :)
- if((*i).compare(*x) <= 0)
- {
+ if(i->compare(*x) <= 0) {
mods_sorted.insert(x, *i);
added = true;
break;
@@ -248,25 +245,12 @@ int ModApiServer::l_get_modnames(lua_State *L)
mods_sorted.push_back(*i);
}
- // Get the table insertion function from Lua.
- lua_getglobal(L, "table");
- lua_getfield(L, -1, "insert");
- int insertion_func = lua_gettop(L);
-
// Package them up for Lua
- lua_newtable(L);
- int new_table = lua_gettop(L);
- std::list<std::string>::iterator i = mods_sorted.begin();
- while(i != mods_sorted.end())
- {
- lua_pushvalue(L, insertion_func);
- lua_pushvalue(L, new_table);
- lua_pushstring(L, (*i).c_str());
- if(lua_pcall(L, 2, 0, 0) != 0)
- {
- script_error(L);
- }
- ++i;
+ lua_createtable(L, mods_sorted.size(), 0);
+ std::list<std::string>::iterator iter = mods_sorted.begin();
+ for (u16 i = 0; iter != mods_sorted.end(); iter++) {
+ lua_pushstring(L, iter->c_str());
+ lua_rawseti(L, -2, ++i);
}
return 1;
}