pixwerx/src/binding/src/runtime_lua.hpp
2020-12-04 22:05:04 +01:00

47 lines
1,000 B
C++

#ifndef PW_SCRIPTING_RUNTIME_LUA_HPP
#define PW_SCRIPTING_RUNTIME_LUA_HPP
// needed for migrating to Lua 5.4.x while keeping sol2 2.20.x
//
// #define lua_newuserdata(L, sz) lua_newuserdatauv((L), (sz), 0)
#include <lua.hpp>
#include "sol/sol.hpp"
#include <map>
#include <pw/core/debug.hpp>
namespace pw {
class runtime_lua {
public:
typedef std::function<void(sol::state&,sol::table&)> register_function_t;
typedef std::map<std::string,register_function_t> register_func_list_t;
static runtime_lua& get();
register_func_list_t register_functions() { return _register_function_list; }
void add(const std::string& name,register_function_t f);
protected:
runtime_lua();
register_func_list_t _register_function_list;
};
#define PW_REGISTER_LUA(name) void register_##name##_lua() { runtime_lua::get().add(#name,register_##name##_function); }
#define PW_REGISTER_DECL_LUA(name) void register_##name##_lua();
#define PW_REGISTER_USE_LUA(name) register_##name##_lua();
}
#endif