aboutsummaryrefslogtreecommitdiff
path: root/src/script/lua_api
diff options
context:
space:
mode:
authorsfan5 <sfan5@live.de>2020-04-14 20:44:18 +0200
committerGitHub <noreply@github.com>2020-04-14 20:44:18 +0200
commit2d5bd3bf794672285cfc796edebab2f672f2cab0 (patch)
treef4922fa8689156f33e9e37c32163cb719bd390e2 /src/script/lua_api
parent7c43cf47c37b0204e34d12670d2e6975eb36b45a (diff)
downloadminetest-2d5bd3bf794672285cfc796edebab2f672f2cab0.tar.gz
minetest-2d5bd3bf794672285cfc796edebab2f672f2cab0.tar.bz2
minetest-2d5bd3bf794672285cfc796edebab2f672f2cab0.zip
scriptapi: Some small optimizations to value pushing (#9669)
Diffstat (limited to 'src/script/lua_api')
-rw-r--r--src/script/lua_api/l_env.cpp8
-rw-r--r--src/script/lua_api/l_mapgen.cpp15
-rw-r--r--src/script/lua_api/l_noise.cpp14
-rw-r--r--src/script/lua_api/l_object.cpp9
-rw-r--r--src/script/lua_api/l_vmanip.cpp6
5 files changed, 22 insertions, 30 deletions
diff --git a/src/script/lua_api/l_env.cpp b/src/script/lua_api/l_env.cpp
index e3afe1862..8c45a1510 100644
--- a/src/script/lua_api/l_env.cpp
+++ b/src/script/lua_api/l_env.cpp
@@ -73,7 +73,7 @@ void LuaABM::trigger(ServerEnvironment *env, v3s16 p, MapNode n,
lua_remove(L, -2); // Remove core
// Get registered_abms[m_id]
- lua_pushnumber(L, m_id);
+ lua_pushinteger(L, m_id);
lua_gettable(L, -2);
if(lua_isnil(L, -1))
FATAL_ERROR("");
@@ -116,7 +116,7 @@ void LuaLBM::trigger(ServerEnvironment *env, v3s16 p, MapNode n)
lua_remove(L, -2); // Remove core
// Get registered_lbms[m_id]
- lua_pushnumber(L, m_id);
+ lua_pushinteger(L, m_id);
lua_gettable(L, -2);
FATAL_ERROR_IF(lua_isnil(L, -1), "Entry with given id not found in registered_lbms table");
lua_remove(L, -2); // Remove registered_lbms
@@ -550,7 +550,7 @@ int ModApiEnvMod::l_find_nodes_with_meta(lua_State *L)
std::vector<v3s16> positions = env->getMap().findNodesWithMetadata(
check_v3s16(L, 1), check_v3s16(L, 2));
- lua_newtable(L);
+ lua_createtable(L, positions.size(), 0);
for (size_t i = 0; i != positions.size(); i++) {
push_v3s16(L, positions[i]);
lua_rawseti(L, -2, i + 1);
@@ -1197,7 +1197,7 @@ int ModApiEnvMod::l_find_path(lua_State *L)
searchdistance, max_jump, max_drop, algo);
if (!path.empty()) {
- lua_newtable(L);
+ lua_createtable(L, path.size(), 0);
int top = lua_gettop(L);
unsigned int index = 1;
for (const v3s16 &i : path) {
diff --git a/src/script/lua_api/l_mapgen.cpp b/src/script/lua_api/l_mapgen.cpp
index cb0d6ac95..afe77826a 100644
--- a/src/script/lua_api/l_mapgen.cpp
+++ b/src/script/lua_api/l_mapgen.cpp
@@ -710,7 +710,7 @@ int ModApiMapgen::l_get_mapgen_object(lua_State *L)
if (!mg->heightmap)
return 0;
- lua_newtable(L);
+ lua_createtable(L, maplen, 0);
for (size_t i = 0; i != maplen; i++) {
lua_pushinteger(L, mg->heightmap[i]);
lua_rawseti(L, -2, i + 1);
@@ -722,7 +722,7 @@ int ModApiMapgen::l_get_mapgen_object(lua_State *L)
if (!mg->biomegen)
return 0;
- lua_newtable(L);
+ lua_createtable(L, maplen, 0);
for (size_t i = 0; i != maplen; i++) {
lua_pushinteger(L, mg->biomegen->biomemap[i]);
lua_rawseti(L, -2, i + 1);
@@ -736,7 +736,7 @@ int ModApiMapgen::l_get_mapgen_object(lua_State *L)
BiomeGenOriginal *bg = (BiomeGenOriginal *)mg->biomegen;
- lua_newtable(L);
+ lua_createtable(L, maplen, 0);
for (size_t i = 0; i != maplen; i++) {
lua_pushnumber(L, bg->heatmap[i]);
lua_rawseti(L, -2, i + 1);
@@ -751,7 +751,7 @@ int ModApiMapgen::l_get_mapgen_object(lua_State *L)
BiomeGenOriginal *bg = (BiomeGenOriginal *)mg->biomegen;
- lua_newtable(L);
+ lua_createtable(L, maplen, 0);
for (size_t i = 0; i != maplen; i++) {
lua_pushnumber(L, bg->humidmap[i]);
lua_rawseti(L, -2, i + 1);
@@ -761,13 +761,12 @@ int ModApiMapgen::l_get_mapgen_object(lua_State *L)
}
case MGOBJ_GENNOTIFY: {
std::map<std::string, std::vector<v3s16> >event_map;
- std::map<std::string, std::vector<v3s16> >::iterator it;
mg->gennotify.getEvents(event_map);
- lua_newtable(L);
- for (it = event_map.begin(); it != event_map.end(); ++it) {
- lua_newtable(L);
+ lua_createtable(L, 0, event_map.size());
+ for (auto it = event_map.begin(); it != event_map.end(); ++it) {
+ lua_createtable(L, it->second.size(), 0);
for (size_t j = 0; j != it->second.size(); j++) {
push_v3s16(L, it->second[j]);
diff --git a/src/script/lua_api/l_noise.cpp b/src/script/lua_api/l_noise.cpp
index e38d319f4..9aeb15709 100644
--- a/src/script/lua_api/l_noise.cpp
+++ b/src/script/lua_api/l_noise.cpp
@@ -171,9 +171,9 @@ int LuaPerlinNoiseMap::l_get_2d_map(lua_State *L)
Noise *n = o->noise;
n->perlinMap2D(p.X, p.Y);
- lua_newtable(L);
+ lua_createtable(L, n->sy, 0);
for (u32 y = 0; y != n->sy; y++) {
- lua_newtable(L);
+ lua_createtable(L, n->sx, 0);
for (u32 x = 0; x != n->sx; x++) {
lua_pushnumber(L, n->result[i++]);
lua_rawseti(L, -2, x + 1);
@@ -200,7 +200,7 @@ int LuaPerlinNoiseMap::l_get_2d_map_flat(lua_State *L)
if (use_buffer)
lua_pushvalue(L, 3);
else
- lua_newtable(L);
+ lua_createtable(L, maplen, 0);
for (size_t i = 0; i != maplen; i++) {
lua_pushnumber(L, n->result[i]);
@@ -224,11 +224,11 @@ int LuaPerlinNoiseMap::l_get_3d_map(lua_State *L)
Noise *n = o->noise;
n->perlinMap3D(p.X, p.Y, p.Z);
- lua_newtable(L);
+ lua_createtable(L, n->sz, 0);
for (u32 z = 0; z != n->sz; z++) {
- lua_newtable(L);
+ lua_createtable(L, n->sy, 0);
for (u32 y = 0; y != n->sy; y++) {
- lua_newtable(L);
+ lua_createtable(L, n->sx, 0);
for (u32 x = 0; x != n->sx; x++) {
lua_pushnumber(L, n->result[i++]);
lua_rawseti(L, -2, x + 1);
@@ -260,7 +260,7 @@ int LuaPerlinNoiseMap::l_get_3d_map_flat(lua_State *L)
if (use_buffer)
lua_pushvalue(L, 3);
else
- lua_newtable(L);
+ lua_createtable(L, maplen, 0);
for (size_t i = 0; i != maplen; i++) {
lua_pushnumber(L, n->result[i]);
diff --git a/src/script/lua_api/l_object.cpp b/src/script/lua_api/l_object.cpp
index fa34260bf..bb1456ac9 100644
--- a/src/script/lua_api/l_object.cpp
+++ b/src/script/lua_api/l_object.cpp
@@ -123,14 +123,7 @@ int ObjectRef::l_get_pos(lua_State *L)
ObjectRef *ref = checkobject(L, 1);
ServerActiveObject *co = getobject(ref);
if (co == NULL) return 0;
- v3f pos = co->getBasePosition() / BS;
- lua_newtable(L);
- lua_pushnumber(L, pos.X);
- lua_setfield(L, -2, "x");
- lua_pushnumber(L, pos.Y);
- lua_setfield(L, -2, "y");
- lua_pushnumber(L, pos.Z);
- lua_setfield(L, -2, "z");
+ push_v3f(L, co->getBasePosition() / BS);
return 1;
}
diff --git a/src/script/lua_api/l_vmanip.cpp b/src/script/lua_api/l_vmanip.cpp
index fd73d21d1..b99b1d98c 100644
--- a/src/script/lua_api/l_vmanip.cpp
+++ b/src/script/lua_api/l_vmanip.cpp
@@ -72,7 +72,7 @@ int LuaVoxelManip::l_get_data(lua_State *L)
if (use_buffer)
lua_pushvalue(L, 2);
else
- lua_newtable(L);
+ lua_createtable(L, volume, 0);
for (u32 i = 0; i != volume; i++) {
lua_Integer cid = vm->m_data[i].getContent();
@@ -261,7 +261,7 @@ int LuaVoxelManip::l_get_light_data(lua_State *L)
u32 volume = vm->m_area.getVolume();
- lua_newtable(L);
+ lua_createtable(L, volume, 0);
for (u32 i = 0; i != volume; i++) {
lua_Integer light = vm->m_data[i].param1;
lua_pushinteger(L, light);
@@ -309,7 +309,7 @@ int LuaVoxelManip::l_get_param2_data(lua_State *L)
if (use_buffer)
lua_pushvalue(L, 2);
else
- lua_newtable(L);
+ lua_createtable(L, volume, 0);
for (u32 i = 0; i != volume; i++) {
lua_Integer param2 = vm->m_data[i].param2;