aboutsummaryrefslogtreecommitdiff
path: root/src/script/common
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/common
parent06baf05c641355ead97e9428c4455af9e8b11cef (diff)
downloadminetest-4594ba652293e776ccba2184c16502a346f4147a.tar.gz
minetest-4594ba652293e776ccba2184c16502a346f4147a.tar.bz2
minetest-4594ba652293e776ccba2184c16502a346f4147a.zip
Optimize table creation
Diffstat (limited to 'src/script/common')
-rw-r--r--src/script/common/c_content.cpp23
1 files changed, 5 insertions, 18 deletions
diff --git a/src/script/common/c_content.cpp b/src/script/common/c_content.cpp
index 65239ff1f..fd98e9480 100644
--- a/src/script/common/c_content.cpp
+++ b/src/script/common/c_content.cpp
@@ -871,26 +871,13 @@ void read_groups(lua_State *L, int index,
/******************************************************************************/
void push_items(lua_State *L, const std::vector<ItemStack> &items)
{
- lua_pushcfunction(L, script_error_handler);
- int errorhandler = lua_gettop(L);
- // Get the table insert function
- lua_getglobal(L, "table");
- lua_getfield(L, -1, "insert");
- int table_insert = lua_gettop(L);
// Create and fill table
- lua_newtable(L);
- int table = lua_gettop(L);
- for(u32 i=0; i<items.size(); i++){
- ItemStack item = items[i];
- lua_pushvalue(L, table_insert);
- lua_pushvalue(L, table);
- LuaItemStack::create(L, item);
- if(lua_pcall(L, 2, 0, errorhandler))
- script_error(L);
+ lua_createtable(L, items.size(), 0);
+ std::vector<ItemStack>::const_iterator iter = items.begin();
+ for (u32 i = 0; iter != items.end(); iter++) {
+ LuaItemStack::create(L, *iter);
+ lua_rawseti(L, -2, ++i);
}
- lua_remove(L, -2); // Remove insert
- lua_remove(L, -2); // Remove table
- lua_remove(L, -2); // Remove error handler
}
/******************************************************************************/