Hello,
I stumbled upon a very weird bug today.
When using the standard script dictionary addon, you cannot store values as uints.
If you store it as an int it works fine, but as an uint it always returns 0.
I have attached the reproduction code here:
#include "../deps/angelscript/include/angelscript.h"
#include "../deps/angelscript/addon/scriptbuilder/scriptbuilder.h"
#include "../deps/angelscript/addon/scriptstdstring/scriptstdstring.h"
#include "../deps/angelscript/addon/scriptdictionary/scriptdictionary.h"
#include "../deps/angelscript/addon/scriptarray/scriptarray.h"
#include <iostream>
#define CHECK_RETURN(error) \
if(r < 0) { std::cout << error << std::endl; return 0; }
static asIScriptEngine* engine = nullptr;
static void MessageCallback(const asSMessageInfo * msg, void* param)
{
std::cout << msg->message << std::endl;
}
static const char* code = R"(
void Main()
{
dictionary dict = GetDict();
int64 intTest = int64(dict["test"]);
uint64 uintTest = uint64(dict["test2"]);
Print(formatInt(intTest));
Print(formatUInt(uintTest));
}
)";
static void Print(const std::string& str)
{
std::cout << str << std::endl;
}
static CScriptDictionary* GetDict()
{
CScriptDictionary* dict = CScriptDictionary::Create(engine);
int64_t testInt = 5;
uint64_t testUint = 7;
dict->Set("test", &testInt, asTYPEID_INT64);
dict->Set("test2", &testUint, asTYPEID_UINT64);
return dict;
}
int main()
{
engine = asCreateScriptEngine();
engine->SetMessageCallback(asFUNCTION(MessageCallback), nullptr, asCALL_CDECL);
RegisterScriptArray(engine, true);
RegisterStdString(engine);
RegisterStdStringUtils(engine);
RegisterScriptDictionary(engine);
engine->RegisterGlobalFunction("void Print(const string&in msg)", asFUNCTION(Print), asCALL_CDECL);
engine->RegisterGlobalFunction("dictionary@ GetDict()", asFUNCTION(GetDict), asCALL_CDECL);
CScriptBuilder builder;
int r = builder.StartNewModule(engine, "Module");
CHECK_RETURN("Failed to start new module");
asIScriptModule* mod = builder.GetModule();
r = builder.AddSectionFromMemory("Main", code);
CHECK_RETURN("Failed to add section");
r = builder.BuildModule();
CHECK_RETURN("Failed to build module");
asIScriptContext* context = engine->CreateContext();
asIScriptFunction* func = mod->GetFunctionByDecl("void Main()");
r = context->Prepare(func);
CHECK_RETURN("Failed to prepare context");
r = context->Execute();
CHECK_RETURN("Failed to execute");
context->Unprepare();
mod->Discard();
engine->ShutDownAndRelease();
return 0;
}
The output is:5
0