:face_with_raised_eyebrow:

bruh
This commit is contained in:
/nick haya 2022-02-22 13:45:18 +08:00
parent 8749aac2fd
commit 05b57124bf
2 changed files with 1 additions and 20 deletions

View file

@ -1,19 +1,6 @@
#include "sdfml_lua.hpp"
int sdfml::LuaHandler::create_from_lua_state(lua_State *L, std::string path, bool immediate) {
_prefer_view = true;
sol::state_view temp(L);
_lua_view = temp;
_cur_result = _lua_view.load_file(path.c_str());
if (immediate)
return 0;
sol::protected_function_result result = _cur_result();
return 1 - result.valid();
}
int sdfml::LuaHandler::open_state(std::string path, bool immediate) {
_prefer_view = false;
_cur_result = _lua_state.load_file(path.c_str());
if (immediate)
return 0;
@ -29,18 +16,15 @@ int sdfml::LuaHandler::run_state() {
template <typename TName>
void sdfml::LuaHandler::set_variable(std::string var_name, TName value) {
if (_prefer_view) _lua_view[var_name] = value; return;
_lua_state[var_name] = value;
}
template <typename TName>
TName sdfml::LuaHandler::get_variable(std::string var_name) {
if (_prefer_view) return _lua_state.get<TName>(var_name);
return _lua_state.get<TName>(var_name);
}
template <typename... Args>
void sdfml::LuaHandler::add_libraries(Args&&... libraries) {
if (_prefer_view) _lua_view.open_libraries(libraries...); return;
_lua_state.open_libraries(libraries...);
}

View file

@ -12,14 +12,11 @@ namespace sdfml {
class LuaHandler {
protected:
sol::state _lua_state;
sol::state_view _lua_view = NULL;
sol::load_result _cur_result;
bool _prefer_view = false;
public:
int open_state(std::string path, bool immediate = false);
int create_from_lua_state(lua_State* L, std::string path, bool immediate = false);
int run_state();
template <typename TName = int>
@ -32,7 +29,7 @@ namespace sdfml {
void add_libraries(Args&&... libraries);
};
//static LuaHandler lua;
static LuaHandler lua;
}
#endif