diff --git a/CHANGELOG.md b/CHANGELOG.md index 3d6a1f9..0fa784c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ # Changelog All notable changes to this project will be documented in this file. -The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] @@ -13,4 +13,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Removed - BASS and BASS_fx support. + +### Deprecated - `.MID` support due to crashes. (God dammit SoLoud) \ No newline at end of file diff --git a/src/libflixel.hpp b/src/libflixel.hpp index 9604c67..2d98bc9 100644 --- a/src/libflixel.hpp +++ b/src/libflixel.hpp @@ -29,6 +29,7 @@ #include "SDL2/SDL_stbimage.h" +#include "sdfml_lua.hpp" #include "toml.hpp" #include @@ -404,6 +405,8 @@ namespace sdfml { static GPU_Camera camera; + static LuaHandler lua; + inline int init(float width = DEFAULT_WINDOW_WIDTH, float height = DEFAULT_WINDOW_HEIGHT, string window_name = "Unknown", int win_flags = SDL_WINDOW_OPENGL|SDL_WINDOW_ALLOW_HIGHDPI|SDL_WINDOW_SHOWN) { std::ofstream logFile; diff --git a/src/lua/sol.hpp b/src/lua/sol.hpp index 1fbe681..d11bde4 100644 --- a/src/lua/sol.hpp +++ b/src/lua/sol.hpp @@ -27239,7 +27239,7 @@ namespace sol { using iterator = typename global_table::iterator; using const_iterator = typename global_table::const_iterator; - state_view(lua_State* Ls) : L(Ls), reg(Ls, LUA_REGISTRYINDEX), global(Ls, global_tag) { + state_view(lua_State* Ls = NULL) : L(Ls), reg(Ls, LUA_REGISTRYINDEX), global(Ls, global_tag) { } state_view(this_state Ls) : state_view(Ls.L) { diff --git a/src/sdfml/sdfml_lua.cpp b/src/sdfml/sdfml_lua.cpp index 4e2b36c..816e19a 100644 --- a/src/sdfml/sdfml_lua.cpp +++ b/src/sdfml/sdfml_lua.cpp @@ -1,6 +1,19 @@ #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; @@ -16,15 +29,18 @@ int sdfml::LuaHandler::run_state() { template 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 TName sdfml::LuaHandler::get_variable(std::string var_name) { + if (_prefer_view) return _lua_state.get(var_name); return _lua_state.get(var_name); } template void sdfml::LuaHandler::add_libraries(Args&&... libraries) { + if (_prefer_view) _lua_view.open_libraries(libraries...); return; _lua_state.open_libraries(libraries...); } \ No newline at end of file diff --git a/src/sdfml/sdfml_lua.hpp b/src/sdfml/sdfml_lua.hpp index 0aad606..5d0afcb 100644 --- a/src/sdfml/sdfml_lua.hpp +++ b/src/sdfml/sdfml_lua.hpp @@ -1,6 +1,7 @@ #ifndef LUA_SDFML_IMPLEMENTATION #define LUA_SDFML_IMPLEMENTATION +#include #include #include #include "../lua/sol.hpp" @@ -13,9 +14,20 @@ namespace sdfml { sol::state _lua_state; sol::state_view _lua_view; sol::load_result _cur_result; + bool _prefer_view = false; public: + LuaHandler() { + sol::state_view temp(NULL); + _lua_view = temp; + } int open_state(std::string path, bool immediate = false); + int create_from_lua_state(lua_State* L, std::string path, bool immediate = false); + + int open_from_lua_state(lua_State* L, std::string path, bool immediate = false) { + return create_from_lua_state(L, path, immediate); + } + int run_state(); template