🎉 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!

AngelScript 2.5.0c released

Started by
44 comments, last by WitchLord 18 years, 4 months ago

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);
Advertisement
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:

"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:

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 recently compared the performance of Angelscript (with a modded version of the tutorial app) with the one of DigitalMars &#106avascript-compatible interpreter (http://www.digitalmars.com/dscript/cppscript.html). For this I took the sieve.ds example script from DigitalMars and adapted it to AS (the languages are nearly identical so this is easy).

These are the results (Repeats are not really relevant, but the prime count affects the array size)
10 Repeats, 14713 primes found: AS 2300ms, DMDScript 3000ms
10 Repeats, 27641 primes found: AS 4770ms, DMDScript 6950ms
5 Repeats, 71301 primes found: AS 6850ms, DMDScript 13200ms
5 Repeats, 71301 primes found: AS no linecallback: 4400ms!

The larger the amount of data is, the more AS's fixed types are paying off :-)

But obviously, the normally crucial linecallback function is a real bottleneck.
Maybe you could introduce the possibility that the function is only called every X ms or only after JUMP-like commands (loops, function calls) or something like that. It seems like pure waste to call the callback function after EVERY trivial script command.
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

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Now if someone only does the same test with LUA =)
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.





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

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