aboutsummaryrefslogtreecommitdiff
path: root/src/script/lua_api
diff options
context:
space:
mode:
Diffstat (limited to 'src/script/lua_api')
-rw-r--r--src/script/lua_api/l_env.cpp26
-rw-r--r--src/script/lua_api/l_env.h3
-rw-r--r--src/script/lua_api/l_mainmenu.cpp32
-rw-r--r--src/script/lua_api/l_mainmenu.h6
-rw-r--r--src/script/lua_api/l_object.cpp6
-rw-r--r--src/script/lua_api/l_util.cpp15
-rw-r--r--src/script/lua_api/l_util.h3
7 files changed, 71 insertions, 20 deletions
diff --git a/src/script/lua_api/l_env.cpp b/src/script/lua_api/l_env.cpp
index dbb0a5ab7..d6dc79ca8 100644
--- a/src/script/lua_api/l_env.cpp
+++ b/src/script/lua_api/l_env.cpp
@@ -743,6 +743,31 @@ int ModApiEnvMod::l_get_objects_inside_radius(lua_State *L)
return 1;
}
+// get_objects_in_area(pos, minp, maxp)
+int ModApiEnvMod::l_get_objects_in_area(lua_State *L)
+{
+ GET_ENV_PTR;
+ ScriptApiBase *script = getScriptApiBase(L);
+
+ v3f minp = read_v3f(L, 1) * BS;
+ v3f maxp = read_v3f(L, 2) * BS;
+ aabb3f box(minp, maxp);
+ box.repair();
+ std::vector<ServerActiveObject *> objs;
+
+ auto include_obj_cb = [](ServerActiveObject *obj){ return !obj->isGone(); };
+ env->getObjectsInArea(objs, box, include_obj_cb);
+
+ int i = 0;
+ lua_createtable(L, objs.size(), 0);
+ for (const auto obj : objs) {
+ // Insert object reference into table
+ script->objectrefGetOrCreate(L, obj);
+ lua_rawseti(L, -2, ++i);
+ }
+ return 1;
+}
+
// set_timeofday(val)
// val = 0...1
int ModApiEnvMod::l_set_timeofday(lua_State *L)
@@ -1571,6 +1596,7 @@ void ModApiEnvMod::Initialize(lua_State *L, int top)
API_FCT(get_node_timer);
API_FCT(get_connected_players);
API_FCT(get_player_by_name);
+ API_FCT(get_objects_in_area);
API_FCT(get_objects_inside_radius);
API_FCT(set_timeofday);
API_FCT(get_timeofday);
diff --git a/src/script/lua_api/l_env.h b/src/script/lua_api/l_env.h
index ad9a0f509..29044c0e8 100644
--- a/src/script/lua_api/l_env.h
+++ b/src/script/lua_api/l_env.h
@@ -114,6 +114,9 @@ private:
// get_objects_inside_radius(pos, radius)
static int l_get_objects_inside_radius(lua_State *L);
+
+ // get_objects_in_area(pos, minp, maxp)
+ static int l_get_objects_in_area(lua_State *L);
// set_timeofday(val)
// val = 0...1
diff --git a/src/script/lua_api/l_mainmenu.cpp b/src/script/lua_api/l_mainmenu.cpp
index 2cf4a979b..3ea5eb4ba 100644
--- a/src/script/lua_api/l_mainmenu.cpp
+++ b/src/script/lua_api/l_mainmenu.cpp
@@ -687,6 +687,14 @@ int ModApiMainMenu::l_get_mapgen_names(lua_State *L)
/******************************************************************************/
+int ModApiMainMenu::l_get_user_path(lua_State *L)
+{
+ std::string path = fs::RemoveRelativePathComponents(porting::path_user);
+ lua_pushstring(L, path.c_str());
+ return 1;
+}
+
+/******************************************************************************/
int ModApiMainMenu::l_get_modpath(lua_State *L)
{
std::string modpath = fs::RemoveRelativePathComponents(
@@ -796,6 +804,15 @@ int ModApiMainMenu::l_copy_dir(lua_State *L)
}
/******************************************************************************/
+int ModApiMainMenu::l_is_dir(lua_State *L)
+{
+ const char *path = luaL_checkstring(L, 1);
+
+ lua_pushboolean(L, fs::IsDir(path));
+ return 1;
+}
+
+/******************************************************************************/
int ModApiMainMenu::l_extract_zip(lua_State *L)
{
const char *zipfile = luaL_checkstring(L, 1);
@@ -1070,7 +1087,15 @@ int ModApiMainMenu::l_get_max_supp_proto(lua_State *L)
int ModApiMainMenu::l_open_url(lua_State *L)
{
std::string url = luaL_checkstring(L, 1);
- lua_pushboolean(L, porting::openURL(url));
+ lua_pushboolean(L, porting::open_url(url));
+ return 1;
+}
+
+/******************************************************************************/
+int ModApiMainMenu::l_open_dir(lua_State *L)
+{
+ std::string path = luaL_checkstring(L, 1);
+ lua_pushboolean(L, porting::open_directory(path));
return 1;
}
@@ -1116,6 +1141,7 @@ void ModApiMainMenu::Initialize(lua_State *L, int top)
API_FCT(set_background);
API_FCT(set_topleft_text);
API_FCT(get_mapgen_names);
+ API_FCT(get_user_path);
API_FCT(get_modpath);
API_FCT(get_clientmodpath);
API_FCT(get_gamepath);
@@ -1125,6 +1151,7 @@ void ModApiMainMenu::Initialize(lua_State *L, int top)
API_FCT(create_dir);
API_FCT(delete_dir);
API_FCT(copy_dir);
+ API_FCT(is_dir);
API_FCT(extract_zip);
API_FCT(may_modify_path);
API_FCT(get_mainmenu_path);
@@ -1137,6 +1164,7 @@ void ModApiMainMenu::Initialize(lua_State *L, int top)
API_FCT(get_min_supp_proto);
API_FCT(get_max_supp_proto);
API_FCT(open_url);
+ API_FCT(open_dir);
API_FCT(do_async_callback);
}
@@ -1147,6 +1175,7 @@ void ModApiMainMenu::InitializeAsync(lua_State *L, int top)
API_FCT(get_games);
API_FCT(get_favorites);
API_FCT(get_mapgen_names);
+ API_FCT(get_user_path);
API_FCT(get_modpath);
API_FCT(get_clientmodpath);
API_FCT(get_gamepath);
@@ -1156,6 +1185,7 @@ void ModApiMainMenu::InitializeAsync(lua_State *L, int top)
API_FCT(create_dir);
API_FCT(delete_dir);
API_FCT(copy_dir);
+ API_FCT(is_dir);
//API_FCT(extract_zip); //TODO remove dependency to GuiEngine
API_FCT(may_modify_path);
API_FCT(download_file);
diff --git a/src/script/lua_api/l_mainmenu.h b/src/script/lua_api/l_mainmenu.h
index 5a16b3bfe..0b02ed892 100644
--- a/src/script/lua_api/l_mainmenu.h
+++ b/src/script/lua_api/l_mainmenu.h
@@ -112,6 +112,8 @@ private:
static int l_get_mainmenu_path(lua_State *L);
+ static int l_get_user_path(lua_State *L);
+
static int l_get_modpath(lua_State *L);
static int l_get_clientmodpath(lua_State *L);
@@ -130,6 +132,8 @@ private:
static int l_copy_dir(lua_State *L);
+ static int l_is_dir(lua_State *L);
+
static int l_extract_zip(lua_State *L);
static int l_may_modify_path(lua_State *L);
@@ -148,6 +152,8 @@ private:
// other
static int l_open_url(lua_State *L);
+ static int l_open_dir(lua_State *L);
+
// async
static int l_do_async_callback(lua_State *L);
diff --git a/src/script/lua_api/l_object.cpp b/src/script/lua_api/l_object.cpp
index bc59bd55c..f52e4892e 100644
--- a/src/script/lua_api/l_object.cpp
+++ b/src/script/lua_api/l_object.cpp
@@ -110,7 +110,7 @@ int ObjectRef::l_remove(lua_State *L)
sao->clearParentAttachment();
verbosestream << "ObjectRef::l_remove(): id=" << sao->getId() << std::endl;
- sao->m_pending_removal = true;
+ sao->markForRemoval();
return 0;
}
@@ -1409,7 +1409,7 @@ int ObjectRef::l_set_physics_override(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;
ObjectRef *ref = checkobject(L, 1);
- PlayerSAO *playersao = (PlayerSAO *) getobject(ref);
+ PlayerSAO *playersao = getplayersao(ref);
if (playersao == nullptr)
return 0;
@@ -1449,7 +1449,7 @@ int ObjectRef::l_get_physics_override(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;
ObjectRef *ref = checkobject(L, 1);
- PlayerSAO *playersao = (PlayerSAO *)getobject(ref);
+ PlayerSAO *playersao = getplayersao(ref);
if (playersao == nullptr)
return 0;
diff --git a/src/script/lua_api/l_util.cpp b/src/script/lua_api/l_util.cpp
index 4595dc1c1..e2730c6d9 100644
--- a/src/script/lua_api/l_util.cpp
+++ b/src/script/lua_api/l_util.cpp
@@ -239,15 +239,6 @@ int ModApiUtil::l_is_yes(lua_State *L)
return 1;
}
-// is_nan(arg)
-int ModApiUtil::l_is_nan(lua_State *L)
-{
- NO_MAP_LOCK_REQUIRED;
-
- lua_pushboolean(L, isNaN(L, 1));
- return 1;
-}
-
// get_builtin_path()
int ModApiUtil::l_get_builtin_path(lua_State *L)
{
@@ -493,7 +484,6 @@ void ModApiUtil::Initialize(lua_State *L, int top)
API_FCT(get_password_hash);
API_FCT(is_yes);
- API_FCT(is_nan);
API_FCT(get_builtin_path);
@@ -526,8 +516,7 @@ void ModApiUtil::InitializeClient(lua_State *L, int top)
API_FCT(write_json);
API_FCT(is_yes);
- API_FCT(is_nan);
-
+
API_FCT(compress);
API_FCT(decompress);
@@ -538,7 +527,7 @@ void ModApiUtil::InitializeClient(lua_State *L, int top)
API_FCT(get_version);
API_FCT(sha1);
-
+
LuaSettings::create(L, g_settings, g_settings_path);
lua_setfield(L, top, "settings");
}
diff --git a/src/script/lua_api/l_util.h b/src/script/lua_api/l_util.h
index 9ff91bb53..b6c1b58af 100644
--- a/src/script/lua_api/l_util.h
+++ b/src/script/lua_api/l_util.h
@@ -65,9 +65,6 @@ private:
// is_yes(arg)
static int l_is_yes(lua_State *L);
- // is_nan(arg)
- static int l_is_nan(lua_State *L);
-
// get_builtin_path()
static int l_get_builtin_path(lua_State *L);