fix: forget arargs for toasts - too complex, will implement string formatting in AngelScript instead
All checks were successful
CI / build-and-test (push) Successful in 2m19s
All checks were successful
CI / build-and-test (push) Successful in 2m19s
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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<std::string*>(gen->GetArgAddress(0));
|
||||
|
||||
// Handle variadic arguments
|
||||
int argCount = gen->GetArgCount();
|
||||
std::vector<std::string> args;
|
||||
|
||||
for (int i = 1; i < argCount; ++i)
|
||||
{
|
||||
// For simplicity, assume all extra args are strings
|
||||
std::string arg = *reinterpret_cast<std::string*>(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<std::string*>(gen->GetArgAddress(0));
|
||||
int argCount = gen->GetArgCount();
|
||||
std::vector<std::string> args;
|
||||
|
||||
for (int i = 1; i < argCount; ++i)
|
||||
args.push_back(*reinterpret_cast<std::string*>(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<std::string*>(gen->GetArgAddress(0));
|
||||
int argCount = gen->GetArgCount();
|
||||
std::vector<std::string> args;
|
||||
|
||||
for (int i = 1; i < argCount; ++i)
|
||||
args.push_back(*reinterpret_cast<std::string*>(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<std::string*>(gen->GetArgAddress(0));
|
||||
int argCount = gen->GetArgCount();
|
||||
std::vector<std::string> args;
|
||||
|
||||
for (int i = 1; i < argCount; ++i)
|
||||
args.push_back(*reinterpret_cast<std::string*>(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("");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user