AngelScript 2.5.0c released
i have a method that returns a pointer to a point.
long CScript::GetData (long scriptNum, scriptObjectType **object)
{ .... }
previously, i can register it as scriptObjectType*&
does a && works ?
r = scriptEngine->RegisterObjectMethod("srScript", "int GetData(int, scriptObjectType&&)", asMETHOD(CScript, GetData), asCALL_THISCALL);
A reference to a reference is illegal in C++. It probably is in AS, too.
Assuming the scriptObjectType supports object handles, then you should be able to register the function like this:
(out is a keyword, not the parameter name)
To C++ this would look like **. You just need to make sure the object handle returned in the parameter has the reference accounted for.
In a future release I intend to reintroduce support for pointers again, in which case you would be able to register the function exactly as it is in C++. But it will probably be a while before I can get that done.
"int GetData(int, scriptObjectType @ &out)"
(out is a keyword, not the parameter name)
To C++ this would look like **. You just need to make sure the object handle returned in the parameter has the reference accounted for.
In a future release I intend to reintroduce support for pointers again, in which case you would be able to register the function exactly as it is in C++. But it will probably be a while before I can get that done.
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game
scriptObjectType is not a class, so i cannot handle the referencing.
any other ways to do it ?
typedef struct
{
string name;
asIScriptContext* script;
long armourType;
long weaponType;
} scriptObjectType;
You have two options. Either change the implementation of scriptObjectType to support object handles, or write wrapper functions for the function that take a pointer to a pointer.
Alternative 1:
Alternative 2:
Then register this as
Alternative 1:
typedef struct{ string name; asIScriptContext* script; long armourType; long weaponType; int refCount; scriptObjectType() {refCount = 1;} void AddRef() {refCount++;} void Release() {if( --refCount == 0 ) delete this;} scriptObjectType &operator=(const scriptObjectType &other) { ... copy everything except the refCount ... }} scriptObjectType;Then when registering the type register the constructor, assignment operator, and the addref and release behaviours.
Alternative 2:
long GetData_wrap(int a, scriptObjectType &ot){ scriptObjectType *tmp = 0; long r = GetData(a, &tmp); ot = *tmp; delete tmp; return r;}
Then register this as
"int GetData(int, scriptObjectType &out)"
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game
I'm very pleased to see those results. [smile] Though it doesn't really surprise me. It's only common sense that fixed types are faster than dynamic types as the VM has less to do.
In regards to your suggestion; This is already implemented. You just have to compile the library with the flag BUILD_WITHOUT_LINE_CUES defined. This will remove most of the BC_SUSPEND byte codes, while still guaranteeing at least one per loop so that endless loops can be broken with a timeout.
This flag and others are documented in the as_config.h file.
Regards,
Andreas
In regards to your suggestion; This is already implemented. You just have to compile the library with the flag BUILD_WITHOUT_LINE_CUES defined. This will remove most of the BC_SUSPEND byte codes, while still guaranteeing at least one per loop so that endless loops can be broken with a timeout.
This flag and others are documented in the as_config.h file.
Regards,
Andreas
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game
okay, i used the second method.
long GetData_wrap(int a, scriptObjectType &ot)
{
scriptObjectType *tmp = 0;
long r = GetData(a, &tmp);
ot = *tmp;
delete tmp;
return r;
}
Then register this as
"int GetData(int, scriptObjectType &out)"
when i use it in script, it crashes.
scriptObjectType &myData
int r = GetData(2, &myData);
i still want to point to the original data in memory.
btw, how do i know which line has error? in the previous version, i can get a string during the Build stage.
long GetData_wrap(int a, scriptObjectType &ot)
{
scriptObjectType *tmp = 0;
long r = GetData(a, &tmp);
ot = *tmp;
delete tmp;
return r;
}
Then register this as
"int GetData(int, scriptObjectType &out)"
when i use it in script, it crashes.
scriptObjectType &myData
int r = GetData(2, &myData);
i still want to point to the original data in memory.
btw, how do i know which line has error? in the previous version, i can get a string during the Build stage.
If you need the original object that was allocated by the C++ function, then you cannot use that way of wrapping the call.
Instead you could wrap the scriptObjectType, in a sort of smart pointer. Kind of like how the asCScriptString (in the add_on directory) has been implemented, except that your wrapper class would hold a pointer to the allocated memory, instead of keeping a local member of the object.
You can still get the line number. There are various functions for doing this depending on the situation:
GetCurrentLineNumber - The line that is currently being executed
GetExceptionLineNumber - Gets the line where the script raised an exception
GetCallstackLineNumber - Allows you to examine the call stack
Regards,
Andreas
Instead you could wrap the scriptObjectType, in a sort of smart pointer. Kind of like how the asCScriptString (in the add_on directory) has been implemented, except that your wrapper class would hold a pointer to the allocated memory, instead of keeping a local member of the object.
You can still get the line number. There are various functions for doing this depending on the situation:
GetCurrentLineNumber - The line that is currently being executed
GetExceptionLineNumber - Gets the line where the script raised an exception
GetCallstackLineNumber - Allows you to examine the call stack
Regards,
Andreas
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement