Here's the relevant part of my init function:
LOG_INFO << "Initialising scripting...\n"; m_pEngine = asCreateScriptEngine(ANGELSCRIPT_VERSION); if (!m_pEngine) THROW("Can't create scripting engine!"); m_pEngine->SetCommonMessageStream(&asOut); m_pEngine->SetCommonObjectMemoryFunctions(localAllocMem, localFreeMem); // register string type LOG_DEBUG << " + Registering 'string' type\n"; RegisterScriptString(m_pEngine);
You 'll see two things here:
1) I 'm using scriptstring.cpp/.h from AngelScript distribution. If there's something wrong with its registration, it's not my fault ;)
2) I use custom allocator functions "localAllocMem" and "localFreeMem" which just allocate memory using my memory manager so that it can track mem leaks. Here's their implementation, for the sake of completeness:
void* localAllocMem(asUINT size){ return MemAlloc(size);}void localFreeMem(void* mem){ MemFree(mem);}
All the mem leaks I 'm talking about, come from localAllocMem. localFreeMem is never called to free the respective memory allocated before by localAllocMem. This only happens in the case I 'm posting about, the string as a return type. For all other cases, it works fine i.e. deallocations match allocations.
Finally, here's the bound function that returns the string type:
std::string StringConverters::FromFloat(float v){ std::ostringstream ss; ss << std::setprecision(4) << v; return ss.str();}
If you still believe that something's wrong with my code, I will try to create a minimal test-case for you to try out.
But, unless there's something wrong with the string type registration, I don't believe there's something wrong with my code because it works fine in all other cases. AngelScript is the only scripting language I could pick up and embed so quickly and painlessly :)