Original Post
Heya - I'm currently experimenting with the library what I want to do and how to do it - and already got a problem :) In short, what I understood from object registration is when I don't register any behaviour and set the object to 0 size, it is available to the script only via a) function parameter when called from C or b) as a return parameter from a C function, right? b) I yet haven't tried since I already failed at a) ;) The output I'm getting from Out() is any integer, but never 0x1000. What am I doing wrong? (having an obj from ObjectBase has the same (wrong) result - but I didn't expect it to be the problem anyway...)
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <angelscript.h>
// ---------------------------------------------------------------------------
class ObjectBase
{
public:
ObjectBase() { mInteger = 0x1000; }
virtual ~ObjectBase() { }
int getInteger() { return mInteger; }
private:
int mInteger;
};
// ---------------------------------------------------------------------------
class ObjectChild: public ObjectBase
{
public:
ObjectChild() { }
virtual ~ObjectChild() { }
};
// ---------------------------------------------------------------------------
void Out(int i)
{
printf("Out() i = 0x%08X\n", i);
}
// ---------------------------------------------------------------------------
int main(void)
{
asIScriptEngine *pEngine = asCreateScriptEngine(ANGELSCRIPT_VERSION);
{ // set up
char const *test =
"void test(Object obj)"
"{"
" Out(obj.getInteger());"
"}";
pEngine->RegisterObjectType("Object", 0, asOBJ_CLASS);
pEngine->RegisterObjectMethod("Object", "int getInteger()", asMETHOD(ObjectBase, getInteger), asCALL_THISCALL);
pEngine->RegisterGlobalFunction("void Out(int i)", asFUNCTION(Out), asCALL_CDECL);
pEngine->AddScriptSection(0, "test", test, strlen(test), 0, false);
pEngine->Build(0);
}
{ // execution
ObjectChild obj;
asIScriptContext *pContext = pEngine->CreateContext();
int id = pEngine->GetFunctionIDByDecl(0, "void test(Object obj)");
pContext->Prepare(id);
pContext->SetArgObject(0, &obj);
pContext->Execute();
pContext->Release();
}
pEngine->Release();
return 0;
}