#include <angelscript.h>
#include <iostream>
class ScriptManager
{
public:
ScriptManager() { m_engine=asCreateScriptEngine(ANGELSCRIPT_VERSION); m_engine->SetMessageCallback(asMETHOD(ScriptManager,MessageCallback),this,asCALL_THISCALL); }
~ScriptManager() { m_engine->Release(); }
asIScriptEngine *GetEngine() { return m_engine; }
private:
void MessageCallback(const asSMessageInfo *message, void *param) { std::cout << message->message << std::endl; }
asIScriptEngine *m_engine;
};
int main()
{
std::string script;
ScriptManager sm;
// script with intentional error
script="void main() { 5 }";
sm.GetEngine()->AddScriptSection(NULL,NULL,script.c_str(),script.size());
sm.GetEngine()->Build(0);
return 0;
}
🎉 Celebrating 25 Years of GameDev.net! 🎉
Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!
message callback as class method
I'm trying to set the message callback function of the engine to a method of a class. It seems like it should work, and I can compile the program fine. The callback is run, but after the method returns the program crashes with a run-time check failure. The message says the value of ESP was not properly saved across a function call, and the debugger drops me in as_scriptengine.cpp inside the function void asCScriptEngine::CallObjectMethod(void *obj, void *param, asSSystemFunctionInterface *i, asCScriptFunction *s).
Here is a small sample that demonstrates the problem. Is there something wrong with how I'm setting the callback?
It should work if you take off the void * parameter for the message callback. i.e.:
void MessageCallback(const asSMessageInfo *message);
Thanks. That worked fine. I guess you can't pass a parameter when using a non-static class method as a callback.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement