diff --git a/src/TLuaFile.cpp b/src/TLuaFile.cpp index dbfe81b..4328bea 100644 --- a/src/TLuaFile.cpp +++ b/src/TLuaFile.cpp @@ -707,52 +707,44 @@ int lua_TempFix(lua_State* L) { } template -struct fun_ptr_helper -{ +struct fun_ptr_helper { public: typedef std::function function_type; - static void bind(function_type&& f) - { instance().fn_.swap(f); } + static void bind(function_type&& f) { instance().fn_.swap(f); } - static void bind(const function_type& f) - { instance().fn_=f; } + static void bind(const function_type& f) { instance().fn_ = f; } - static Res invoke(ArgTypes... args) - { return instance().fn_(args...); } + static Res invoke(ArgTypes... args) { return instance().fn_(args...); } typedef decltype(&fun_ptr_helper::invoke) pointer_type; - static pointer_type ptr() - { return &invoke; } + static pointer_type ptr() { return &invoke; } private: - static fun_ptr_helper& instance() - { + static fun_ptr_helper& instance() { static fun_ptr_helper inst_; return inst_; } - fun_ptr_helper() {} + fun_ptr_helper() { } function_type fn_; }; template typename fun_ptr_helper<_UniqueId, _Res, _ArgTypes...>::pointer_type -get_fn_ptr(const std::function<_Res(_ArgTypes...)>& f) -{ +get_fn_ptr(const std::function<_Res(_ArgTypes...)>& f) { fun_ptr_helper<_UniqueId, _Res, _ArgTypes...>::bind(f); return fun_ptr_helper<_UniqueId, _Res, _ArgTypes...>::ptr(); } - int lua_Register(lua_State* L) { - if(lua_isstring(L, 1)){ + if (lua_isstring(L, 1)) { std::string Name(lua_tolstring(L, 1, nullptr)); lua_getglobal(L, Name.c_str()); if (lua_isfunction(L, -1)) { for (auto& Script : Engine().LuaFiles()) { - if(Script->GetState() != L){ + if (Script->GetState() != L) { lua_CFunction Func = get_fn_ptr<0>(std::function([=](lua_State* A) { lua_getglobal(L, Name.c_str()); if (lua_isfunction(L, -1)) { @@ -860,6 +852,7 @@ int lua_GetOSName(lua_State* L) { #else lua_pushstring(L, "Unknown"); #endif + return 1; } void TLuaFile::Load() { @@ -884,7 +877,7 @@ void TLuaFile::Load() { LuaTable::InsertFunction(mLuaState, "GetPlayerGuest", lua_GetGuest); LuaTable::InsertFunction(mLuaState, "StopThread", lua_StopThread); LuaTable::InsertFunction(mLuaState, "DropPlayer", lua_dropPlayer); - lua_register(mLuaState, "Register", lua_Register); + LuaTable::InsertFunction(mLuaState, "Register", lua_Register); LuaTable::InsertFunction(mLuaState, "GetPlayerHWID", lua_HWID); LuaTable::InsertFunction(mLuaState, "Sleep", lua_Sleep); LuaTable::InsertFunction(mLuaState, "Set", lua_Set); @@ -967,7 +960,6 @@ void SendError(TLuaEngine& Engine, lua_State* L, const std::string& msg) { warn(a + (" | Incorrect Call of ") + msg); } - void TLuaArg::PushArgs(lua_State* State) { for (std::any arg : args) { if (!arg.has_value()) { @@ -992,4 +984,4 @@ void TLuaArg::PushArgs(lua_State* State) { error("what in the hell is " + std::string(arg.type().name())); } } -} \ No newline at end of file +}