refactor: 'lua' namespace expansion
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
#include "lua_commons.hpp"
|
||||
#include "api_lua.hpp"
|
||||
|
||||
#include "../scripting.hpp"
|
||||
#include "../../../assets/Assets.hpp"
|
||||
#include "../../../assets/AssetsLoader.hpp"
|
||||
#include "../../../files/engine_paths.hpp"
|
||||
@@ -12,10 +10,11 @@
|
||||
#include <cmath>
|
||||
#include <filesystem>
|
||||
|
||||
using namespace scripting;
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
static int l_world_get_list(lua_State* L) {
|
||||
auto paths = scripting::engine->getPaths();
|
||||
auto paths = engine->getPaths();
|
||||
auto worlds = paths->scanForWorlds();
|
||||
|
||||
lua_createtable(L, worlds.size(), 0);
|
||||
@@ -23,10 +22,10 @@ static int l_world_get_list(lua_State* L) {
|
||||
lua_createtable(L, 0, 1);
|
||||
|
||||
auto name = worlds[i].filename().u8string();
|
||||
lua_pushstring(L, name.c_str());
|
||||
lua_setfield(L, -2, "name");
|
||||
lua::pushstring(L, name);
|
||||
lua::setfield(L, "name");
|
||||
|
||||
auto assets = scripting::engine->getAssets();
|
||||
auto assets = engine->getAssets();
|
||||
std::string icon = "world:"+name+".icon";
|
||||
if (!AssetsLoader::loadExternalTexture(assets, icon, {
|
||||
worlds[i]/fs::path("icon.png"),
|
||||
@@ -34,8 +33,8 @@ static int l_world_get_list(lua_State* L) {
|
||||
})) {
|
||||
icon = "gui/no_world_icon";
|
||||
}
|
||||
lua_pushstring(L, icon.c_str());
|
||||
lua_setfield(L, -2, "icon");
|
||||
lua::pushstring(L, icon);
|
||||
lua::setfield(L, "icon");
|
||||
|
||||
lua_rawseti(L, -2, i + 1);
|
||||
}
|
||||
@@ -43,39 +42,35 @@ static int l_world_get_list(lua_State* L) {
|
||||
}
|
||||
|
||||
static int l_world_get_total_time(lua_State* L) {
|
||||
lua_pushnumber(L, scripting::level->getWorld()->totalTime);
|
||||
return 1;
|
||||
return lua::pushnumber(L, level->getWorld()->totalTime);
|
||||
}
|
||||
|
||||
static int l_world_get_day_time(lua_State* L) {
|
||||
lua_pushnumber(L, scripting::level->getWorld()->daytime);
|
||||
return 1;
|
||||
return lua::pushnumber(L, level->getWorld()->daytime);
|
||||
}
|
||||
|
||||
static int l_world_set_day_time(lua_State* L) {
|
||||
double value = lua_tonumber(L, 1);
|
||||
scripting::level->getWorld()->daytime = fmod(value, 1.0);
|
||||
auto value = lua::tonumber(L, 1);
|
||||
level->getWorld()->daytime = fmod(value, 1.0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_world_get_seed(lua_State* L) {
|
||||
lua_pushinteger(L, scripting::level->getWorld()->getSeed());
|
||||
return 1;
|
||||
return lua::pushinteger(L, level->getWorld()->getSeed());
|
||||
}
|
||||
|
||||
static int l_world_exists(lua_State* L) {
|
||||
auto name = lua_tostring(L, 1);
|
||||
auto worldsDir = scripting::engine->getPaths()->getWorldFolder(name);
|
||||
lua_pushboolean(L, fs::is_directory(worldsDir));
|
||||
return 1;
|
||||
auto name = lua::require_string(L, 1);
|
||||
auto worldsDir = engine->getPaths()->getWorldFolder(name);
|
||||
return lua::pushboolean(L, fs::is_directory(worldsDir));
|
||||
}
|
||||
|
||||
const luaL_Reg worldlib [] = {
|
||||
{"get_list", lua_wrap_errors<l_world_get_list>},
|
||||
{"get_total_time", lua_wrap_errors<l_world_get_total_time>},
|
||||
{"get_day_time", lua_wrap_errors<l_world_get_day_time>},
|
||||
{"set_day_time", lua_wrap_errors<l_world_set_day_time>},
|
||||
{"get_seed", lua_wrap_errors<l_world_get_seed>},
|
||||
{"exists", lua_wrap_errors<l_world_exists>},
|
||||
{"get_list", lua::wrap<l_world_get_list>},
|
||||
{"get_total_time", lua::wrap<l_world_get_total_time>},
|
||||
{"get_day_time", lua::wrap<l_world_get_day_time>},
|
||||
{"set_day_time", lua::wrap<l_world_set_day_time>},
|
||||
{"get_seed", lua::wrap<l_world_get_seed>},
|
||||
{"exists", lua::wrap<l_world_exists>},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user