aboutsummaryrefslogtreecommitdiff
path: root/src/script/cpp_api
ModeNameSize
-rw-r--r--CMakeLists.txt686logplain
-rw-r--r--s_async.cpp6554logplain
-rw-r--r--s_async.h3890logplain
-rw-r--r--s_base.cpp12547logplain
-rw-r--r--s_base.h4363logplain
-rw-r--r--s_client.cpp6503logplain
-rw-r--r--s_client.h1986logplain
-rw-r--r--s_entity.cpp9026logplain
-rw-r--r--s_entity.h1988logplain
-rw-r--r--s_env.cpp7655logplain
-rw-r--r--s_env.h1461logplain
-rw-r--r--s_internal.h2896logplain
-rw-r--r--s_inventory.cpp7313logplain
-rw-r--r--s_inventory.h1943logplain
-rw-r--r--s_item.cpp7237logplain
-rw-r--r--s_item.h2112logplain
-rw-r--r--s_mainmenu.cpp2660logplain
-rw-r--r--s_mainmenu.h1396logplain
-rw-r--r--s_modchannels.cpp1690logplain
-rw-r--r--s_modchannels.h1124logplain
-rw-r--r--s_node.cpp7690logplain
-rw-r--r--s_node.h1964logplain
-rw-r--r--s_nodemeta.cpp8097logplain
-rw-r--r--s_nodemeta.h1966logplain
-rw-r--r--s_player.cpp10907logplain
-rw-r--r--s_player.h3395logplain
-rw-r--r--s_security.cpp18653logplain
-rw-r--r--s_security.h2925logplain
-rw-r--r--s_server.cpp5476logplain
-rw-r--r--s_server.h1712logplain
); } void push_v2f(lua_State *L, v2f p) { lua_newtable(L); lua_pushnumber(L, p.X); lua_setfield(L, -2, "x"); lua_pushnumber(L, p.Y); lua_setfield(L, -2, "y"); } v2s16 read_v2s16(lua_State *L, int index) { v2s16 p; luaL_checktype(L, index, LUA_TTABLE); lua_getfield(L, index, "x"); p.X = lua_tonumber(L, -1); lua_pop(L, 1); lua_getfield(L, index, "y"); p.Y = lua_tonumber(L, -1); lua_pop(L, 1); return p; } v2s32 read_v2s32(lua_State *L, int index) { v2s32 p; luaL_checktype(L, index, LUA_TTABLE); lua_getfield(L, index, "x"); p.X = lua_tonumber(L, -1); lua_pop(L, 1); lua_getfield(L, index, "y"); p.Y = lua_tonumber(L, -1); lua_pop(L, 1); return p; } v2f read_v2f(lua_State *L, int index) { v2f p; luaL_checktype(L, index, LUA_TTABLE); lua_getfield(L, index, "x"); p.X = lua_tonumber(L, -1); lua_pop(L, 1); lua_getfield(L, index, "y"); p.Y = lua_tonumber(L, -1); lua_pop(L, 1); return p; } v3f read_v3f(lua_State *L, int index) { v3f pos; luaL_checktype(L, index, LUA_TTABLE); lua_getfield(L, index, "x"); pos.X = lua_tonumber(L, -1); lua_pop(L, 1); lua_getfield(L, index, "y"); pos.Y = lua_tonumber(L, -1); lua_pop(L, 1); lua_getfield(L, index, "z"); pos.Z = lua_tonumber(L, -1); lua_pop(L, 1); return pos; } v3f check_v3f(lua_State *L, int index) { v3f pos; luaL_checktype(L, index, LUA_TTABLE); lua_getfield(L, index, "x"); pos.X = luaL_checknumber(L, -1); lua_pop(L, 1); lua_getfield(L, index, "y"); pos.Y = luaL_checknumber(L, -1); lua_pop(L, 1); lua_getfield(L, index, "z"); pos.Z = luaL_checknumber(L, -1); lua_pop(L, 1); return pos; } void pushFloatPos(lua_State *L, v3f p) { p /= BS; push_v3f(L, p); } v3f checkFloatPos(lua_State *L, int index) { return check_v3f(L, index) * BS; } void push_v3s16(lua_State *L, v3s16 p) { lua_newtable(L); lua_pushnumber(L, p.X); lua_setfield(L, -2, "x"); lua_pushnumber(L, p.Y); lua_setfield(L, -2, "y"); lua_pushnumber(L, p.Z); lua_setfield(L, -2, "z"); } v3s16 read_v3s16(lua_State *L, int index) { // Correct rounding at <0 v3f pf = read_v3f(L, index); return floatToInt(pf, 1.0); } v3s16 check_v3s16(lua_State *L, int index) { // Correct rounding at <0 v3f pf = check_v3f(L, index); return floatToInt(pf, 1.0); } video::SColor readARGB8(lua_State *L, int index) { video::SColor color(0); luaL_checktype(L, index, LUA_TTABLE); lua_getfield(L, index, "a"); if(lua_isnumber(L, -1)) color.setAlpha(lua_tonumber(L, -1)); lua_pop(L, 1); lua_getfield(L, index, "r"); color.setRed(lua_tonumber(L, -1)); lua_pop(L, 1); lua_getfield(L, index, "g"); color.setGreen(lua_tonumber(L, -1)); lua_pop(L, 1); lua_getfield(L, index, "b"); color.setBlue(lua_tonumber(L, -1)); lua_pop(L, 1); return color; } aabb3f read_aabb3f(lua_State *L, int index, f32 scale) { aabb3f box; if(lua_istable(L, index)){ lua_rawgeti(L, index, 1); box.MinEdge.X = lua_tonumber(L, -1) * scale; lua_pop(L, 1); lua_rawgeti(L, index, 2); box.MinEdge.Y = lua_tonumber(L, -1) * scale; lua_pop(L, 1); lua_rawgeti(L, index, 3); box.MinEdge.Z = lua_tonumber(L, -1) * scale; lua_pop(L, 1); lua_rawgeti(L, index, 4); box.MaxEdge.X = lua_tonumber(L, -1) * scale; lua_pop(L, 1); lua_rawgeti(L, index, 5); box.MaxEdge.Y = lua_tonumber(L, -1) * scale; lua_pop(L, 1); lua_rawgeti(L, index, 6); box.MaxEdge.Z = lua_tonumber(L, -1) * scale; lua_pop(L, 1); } return box; } std::vector<aabb3f> read_aabb3f_vector(lua_State *L, int index, f32 scale) { std::vector<aabb3f> boxes; if(lua_istable(L, index)){ int n = lua_objlen(L, index); // Check if it's a single box or a list of boxes bool possibly_single_box = (n == 6); for(int i = 1; i <= n && possibly_single_box; i++){ lua_rawgeti(L, index, i); if(!lua_isnumber(L, -1)) possibly_single_box = false; lua_pop(L, 1); } if(possibly_single_box){ // Read a single box boxes.push_back(read_aabb3f(L, index, scale)); } else { // Read a list of boxes for(int i = 1; i <= n; i++){ lua_rawgeti(L, index, i); boxes.push_back(read_aabb3f(L, -1, scale)); lua_pop(L, 1); } } } return boxes; } /* Table field getters */ bool getstringfield(lua_State *L, int table, const char *fieldname, std::string &result) { lua_getfield(L, table, fieldname); bool got = false; if(lua_isstring(L, -1)){ size_t len = 0; const char *ptr = lua_tolstring(L, -1, &len); if (ptr) { result.assign(ptr, len); got = true; } } lua_pop(L, 1); return got; } bool getintfield(lua_State *L, int table, const char *fieldname, int &result) { lua_getfield(L, table, fieldname); bool got = false; if(lua_isnumber(L, -1)){ result = lua_tonumber(L, -1); got = true; } lua_pop(L, 1); return got; } bool getfloatfield(lua_State *L, int table, const char *fieldname, float &result) { lua_getfield(L, table, fieldname); bool got = false; if(lua_isnumber(L, -1)){ result = lua_tonumber(L, -1); got = true; } lua_pop(L, 1); return got; } bool getboolfield(lua_State *L, int table, const char *fieldname, bool &result) { lua_getfield(L, table, fieldname); bool got = false; if(lua_isboolean(L, -1)){ result = lua_toboolean(L, -1); got = true; } lua_pop(L, 1); return got; } std::string checkstringfield(lua_State *L, int table, const char *fieldname) { lua_getfield(L, table, fieldname); std::string s = luaL_checkstring(L, -1); lua_pop(L, 1); return s; } std::string getstringfield_default(lua_State *L, int table, const char *fieldname, const std::string &default_) { std::string result = default_; getstringfield(L, table, fieldname, result); return result; } int getintfield_default(lua_State *L, int table, const char *fieldname, int default_) { int result = default_; getintfield(L, table, fieldname, result); return result; } float getfloatfield_default(lua_State *L, int table, const char *fieldname, float default_) { float result = default_; getfloatfield(L, table, fieldname, result); return result; } bool getboolfield_default(lua_State *L, int table, const char *fieldname, bool default_) { bool result = default_; getboolfield(L, table, fieldname, result); return result; } void setintfield(lua_State *L, int table, const char *fieldname, int value) { lua_pushinteger(L, value); if(table < 0) table -= 1; lua_setfield(L, table, fieldname); } void setfloatfield(lua_State *L, int table, const char *fieldname, float value) { lua_pushnumber(L, value); if(table < 0) table -= 1;