Sign in to follow this  

Construct Angelscript object in memory

This topic is 683 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I would like to construct a user defined Angelscript type (defined in a script file) in a pre-allocated memory buffer, using the type name and a parameter list. For example:

// In Angelscript
class SomeClass
{
    SomeClass(int a, int b)
    {
        ...
    }

    int value;
}

Then the type name and some construction parameters are passed in from some other text file. Something like this:

 

"SomeClass", "(2, 5)"

 

Then I will allocate memory according to size of SomeClass

asUINT uiSize = pkEngine->GetObjectTypeByName("SomeClass")->GetSize();
// allocate some memory

Am I able to call the constructor "SomeClass(2, 5)" in that memory location? Do I need to know the parameter types?

 

Edit: GetObjectTypeByName("SomeClass") is not working actually; SomeClass does not seem to be recognised as an object type. If I iterate over all types, it is only picking up types I have registered through the c++ api.

Edited by Wolfbrother

Share this post


Link to post
Share on other sites

I figured out that I need to find the type within the module I loaded the scripts into:

asUINT uiSize = pkEngine->GetModule("Module")->GetObjectTypeByName("SomeClass")->GetSize();

I found a couple of functions that might allow me to create a default constructed object, and then copy it to my buffer. But this does not let me call a non-default constructor.

void* pvObject = pkEngine->CreateScriptObject(type);
pkEngine->AssignScriptObject(pvMemory, pvObject, type);
pkEngine->ReleaseScriptObject(pvObject, type);

Share this post


Link to post
Share on other sites

This topic is 683 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this