diff --git a/imgui.ini b/imgui.ini index 187746c..4dcc263 100644 --- a/imgui.ini +++ b/imgui.ini @@ -30,6 +30,11 @@ Pos=1062,576 Size=198,57 Collapsed=0 +[Window][##TOAST2] +Pos=1062,509 +Size=198,57 +Collapsed=0 + [Docking][Data] DockSpace ID=0x9076BACA Window=0x34F970D7 Pos=8,25 Size=1264,687 Split=Y Selected=0x27A02DAA DockNode ID=0x00000001 Parent=0x9076BACA SizeRef=1264,579 CentralNode=1 Selected=0x27A02DAA diff --git a/scripts/as.predefined b/scripts/as.predefined index 0b7b961..1b40eb8 100644 --- a/scripts/as.predefined +++ b/scripts/as.predefined @@ -11,5 +11,7 @@ int LOG_FATAL; namespace Toast { void Info(const string&in); - void Info(const string&in, const ?&in ...); + void Warning(const string&in); + void Error(const string&in); + void Success(const string&in); } diff --git a/src/ScriptBindings.cpp b/src/ScriptBindings.cpp index d1fb0d3..5d149c0 100644 --- a/src/ScriptBindings.cpp +++ b/src/ScriptBindings.cpp @@ -13,107 +13,29 @@ static int AS_LOG_WARNING = 4; static int AS_LOG_ERROR = 5; static int AS_LOG_FATAL = 6; -void ToastInfo_Generic(asIScriptGeneric* gen) +static void AS_ToastInfo(const std::string& message) { - // First argument is the format string - std::string fmt = *reinterpret_cast(gen->GetArgAddress(0)); - - // Handle variadic arguments - int argCount = gen->GetArgCount(); - std::vector args; - - for (int i = 1; i < argCount; ++i) - { - // For simplicity, assume all extra args are strings - std::string arg = *reinterpret_cast(gen->GetArgAddress(i)); - args.push_back(arg); - } - - // Simple formatting: replace %s sequentially - std::string result = fmt; - size_t pos = 0; - for (const auto& a : args) - { - pos = result.find("%s", pos); - if (pos == std::string::npos) break; - result.replace(pos, 2, a); - pos += a.size(); - } - - Toast::Info(result); + Toast::Info(message); } -void ToastWarning_Generic(asIScriptGeneric* gen) +static void AS_ToastWarning(const std::string& message) { - std::string fmt = *reinterpret_cast(gen->GetArgAddress(0)); - int argCount = gen->GetArgCount(); - std::vector args; - - for (int i = 1; i < argCount; ++i) - args.push_back(*reinterpret_cast(gen->GetArgAddress(i))); - - std::string result = fmt; - size_t pos = 0; - for (const auto& a : args) - { - pos = result.find("%s", pos); - if (pos == std::string::npos) break; - result.replace(pos, 2, a); - pos += a.size(); - } - - Toast::Warning(result); + Toast::Warning(message); } -void ToastError_Generic(asIScriptGeneric* gen) +static void AS_ToastError(const std::string& message) { - std::string fmt = *reinterpret_cast(gen->GetArgAddress(0)); - int argCount = gen->GetArgCount(); - std::vector args; - - for (int i = 1; i < argCount; ++i) - args.push_back(*reinterpret_cast(gen->GetArgAddress(i))); - - std::string result = fmt; - size_t pos = 0; - for (const auto& a : args) - { - pos = result.find("%s", pos); - if (pos == std::string::npos) break; - result.replace(pos, 2, a); - pos += a.size(); - } - - Toast::Error(result); + Toast::Error(message); } -void ToastSuccess_Generic(asIScriptGeneric* gen) +static void AS_ToastSuccess(const std::string& message) { - std::string fmt = *reinterpret_cast(gen->GetArgAddress(0)); - int argCount = gen->GetArgCount(); - std::vector args; - - for (int i = 1; i < argCount; ++i) - args.push_back(*reinterpret_cast(gen->GetArgAddress(i))); - - std::string result = fmt; - size_t pos = 0; - for (const auto& a : args) - { - pos = result.find("%s", pos); - if (pos == std::string::npos) break; - result.replace(pos, 2, a); - pos += a.size(); - } - - Toast::Success(result); + Toast::Success(message); } - - void ScriptBindings::RegisterAll(asIScriptEngine *engine) { // Register Print function with generic calling convention to access context - int r = engine->RegisterGlobalFunction("void Print(const string &in)", + [[maybe_unused]] int r = engine->RegisterGlobalFunction("void Print(const string &in)", asFUNCTION(Print), asCALL_GENERIC); assert(r >= 0); @@ -138,11 +60,17 @@ void ScriptBindings::RegisterAll(asIScriptEngine *engine) // Toast functions engine->SetDefaultNamespace("Toast"); - r = engine->RegisterGlobalFunction("void Info(const string &in, const ?&in ...)", - asFUNCTION(ToastInfo_Generic), asCALL_GENERIC); - assert(r >= 0); r = engine->RegisterGlobalFunction("void Info(const string &in)", - asFUNCTION(ToastInfo_Generic), asCALL_GENERIC); + asFUNCTION(AS_ToastInfo), asCALL_CDECL); + assert(r >= 0); + r = engine->RegisterGlobalFunction("void Warning(const string &in)", + asFUNCTION(AS_ToastWarning), asCALL_CDECL); + assert(r >= 0); + r = engine->RegisterGlobalFunction("void Error(const string &in)", + asFUNCTION(AS_ToastError), asCALL_CDECL); + assert(r >= 0); + r = engine->RegisterGlobalFunction("void Success(const string &in)", + asFUNCTION(AS_ToastSuccess), asCALL_CDECL); assert(r >= 0); engine->SetDefaultNamespace("");