#pragma once #include "CEngine.h" #include "CScriptingManager.h" #include "U_Scripting.h" #include "U_FixedString.h" #include template int InvokeRegisterFunction(sol::table tabl, sol::this_state ts) { std::string_view roottype_sv(RootType); sol::object typenm = tabl["type"]; sol::object root_typenm = tabl["root_type"]; if(!typenm.valid() || !typenm.is()) { return 1; } std::string _strtypenm = typenm.as(); std::string strtypenm = _strtypenm; std::transform(strtypenm.begin(), strtypenm.end(), strtypenm.begin(), ::tolower); if(!root_typenm.valid() || !root_typenm.is()) { return 2; } std::string _strroottypenm = root_typenm.as(); std::string strroottypenm = _strroottypenm; std::transform(strroottypenm.begin(), strroottypenm.end(), strroottypenm.begin(), ::tolower); if(strroottypenm != roottype_sv) { return 3; } if(strtypenm.empty()) { return 4; } auto man = CEngine::GetInstance()->Components.GetComponentTyped(); auto engine = man->GetEngine(ts); bool isRegistered = man->ScriptClassesFactory.IsClassRegistered(strtypenm); if(isRegistered) { return 5; } std::map _functions; for(auto& kv : tabl) { if(kv.second.valid() && kv.second.is()) { _functions.insert({ kv.first.as(), kv.second.as() }); } } auto State = ScriptUtils::GetStateSharedPtr(ts); man->ScriptClassesFactory.RegisterClassInfo({ strtypenm, State, _functions, engine }); return 0; }