mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-05 19:11:50 +00:00
add stdmin.lua
This commit is contained in:
parent
b4578cfb87
commit
6e0304248b
8 changed files with 245 additions and 246 deletions
|
|
@ -3,6 +3,8 @@
|
|||
#include <iomanip>
|
||||
#include <iostream>
|
||||
|
||||
#include "files/files.hpp"
|
||||
#include "files/engine_paths.hpp"
|
||||
#include "debug/Logger.hpp"
|
||||
#include "util/stringutil.hpp"
|
||||
#include "libs/api_lua.hpp"
|
||||
|
|
@ -104,11 +106,11 @@ void lua::init_state(State* L, StateType stateType) {
|
|||
newusertype<LuaVoxelStructure>(L);
|
||||
}
|
||||
|
||||
void lua::initialize() {
|
||||
void lua::initialize(const EnginePaths& paths) {
|
||||
logger.info() << LUA_VERSION;
|
||||
logger.info() << LUAJIT_VERSION;
|
||||
|
||||
main_thread = create_state(StateType::BASE);
|
||||
main_thread = create_state(paths, StateType::BASE);
|
||||
}
|
||||
|
||||
void lua::finalize() {
|
||||
|
|
@ -131,11 +133,15 @@ State* lua::get_main_state() {
|
|||
return main_thread;
|
||||
}
|
||||
|
||||
State* lua::create_state(StateType stateType) {
|
||||
State* lua::create_state(const EnginePaths& paths, StateType stateType) {
|
||||
auto L = luaL_newstate();
|
||||
if (L == nullptr) {
|
||||
throw luaerror("could not initialize Lua state");
|
||||
}
|
||||
init_state(L, stateType);
|
||||
|
||||
auto resDir = paths.getResourcesFolder();
|
||||
auto src = files::read_string(resDir / fs::u8path("scripts/stdmin.lua"));
|
||||
lua::pop(L, lua::execute(L, 0, src, "<stdmin>"));
|
||||
return L;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,13 +7,15 @@
|
|||
#include "logic/scripting/scripting_functional.hpp"
|
||||
#include "lua_util.hpp"
|
||||
|
||||
class EnginePaths;
|
||||
|
||||
namespace lua {
|
||||
enum class StateType {
|
||||
BASE,
|
||||
GENERATOR,
|
||||
};
|
||||
|
||||
void initialize();
|
||||
void initialize(const EnginePaths& paths);
|
||||
void finalize();
|
||||
|
||||
bool emit_event(
|
||||
|
|
@ -22,7 +24,7 @@ namespace lua {
|
|||
std::function<int(State*)> args = [](auto*) { return 0; }
|
||||
);
|
||||
State* get_main_state();
|
||||
State* create_state(StateType stateType);
|
||||
State* create_state(const EnginePaths& paths, StateType stateType);
|
||||
[[nodiscard]] scriptenv create_environment(State* L);
|
||||
|
||||
void init_state(State* L, StateType stateType);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue