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

Declare a type

Started by
7 comments, last by dxj19831029 15 years, 10 months ago
I have a problem: here is the code: nRet = pScriptEngine->RegisterObjectMethod("__RECT", "long getDistanceX(__RECT ▭)", asMETHODPR(__RECT, getDistanceX, (tagRect ▭), LONG), asCALL_THISCALL); I want to declare this, but I do not want script to handle the ref object creation or deletion. So should I declare as: asOBJ_REF | asOBJ_NOHANDLE if I do, this still not working for ▭ arguements. I know if I declared this as a asObj_ref, and give all the constructor and deconstructor, it will works. Just wonder if this is the only way to make this works? Buy the way, __RECT contains left, top, right, bottom. The method to declared is: long __RECT::getDistanceX(__RECT ▭); Thanks for ur help.
Advertisement
You should declare the method with the function signature "long getDistanceX(const __RECT ∈ rect)". I added the 'const' and 'in' keywords. This will allow you to continue to register the __RECT type as asOBJ_VALUE.

The 'in' keyword tells AngelScript that the value in the reference is for input only, thus it can assure the safety of the reference in all circumstances.

The 'const' keyword gives a bit more assurance, and let's AngelScript optimize the code even further in that it doesn't have to make a copy of the original value in order to guarantee that it is not modified by the function.


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

Thanks for ur help.
I will give a try on that.
Now, I knew y the const and in in the angelscript.
:)


Quote: Original post by WitchLord
You should declare the method with the function signature "long getDistanceX(const __RECT ∈ rect)". I added the 'const' and 'in' keywords. This will allow you to continue to register the __RECT type as asOBJ_VALUE.

The 'in' keyword tells AngelScript that the value in the reference is for input only, thus it can assure the safety of the reference in all circumstances.

The 'const' keyword gives a bit more assurance, and let's AngelScript optimize the code even further in that it doesn't have to make a copy of the original value in order to guarantee that it is not modified by the function.


Ai~~~!

Still not working.
My version is newest version from repository.

Class __RECT {
long left;
long right;
long top;
long bottom;
long getDistanceX(__RECT &c);
}

I register this with:
asOBJ_APP_CLASS | asOBJ_VALUE
or asOBJ_VALUE
or asOBJ_APP_CLASS | asOBJ_VALUE | asOBJ_POD
or any combination with them.
not working.

assertion always failed.

Here is the code:
nRet = pScriptEngine->RegisterObjectMethod("__RECT", "long getDistanceX(const __RECT ∈ rect)", asMETHODPR(__RECT, getDistanceX, (__RECT ▭), long), asCALL_THISCALL);
assert( nRet >= 0);

Can u help me to correct it?

I am not sure the others, but for me if u can provide more full examples on register class, that would be great for me to follow. Just suggestion.

:)



Quote: Original post by WitchLord
You should declare the method with the function signature "long getDistanceX(const __RECT ∈ rect)". I added the 'const' and 'in' keywords. This will allow you to continue to register the __RECT type as asOBJ_VALUE.

The 'in' keyword tells AngelScript that the value in the reference is for input only, thus it can assure the safety of the reference in all circumstances.

The 'const' keyword gives a bit more assurance, and let's AngelScript optimize the code even further in that it doesn't have to make a copy of the original value in order to guarantee that it is not modified by the function.


Sorry, My bad.
I think I used long in the script, but it does not support it.

Can we match the type into script internal type?
for example: define long as int32 in the script.

From my understanding, if I want to do this, I need to define all the operation for long type. Isn't it? but If we can simply match it, it will be easy.

Think about the real project, we alwasy define our type as LONG, UINT, INT and so on. In this case, we can control the type matching between different machines, how can angelscript do this for us?

I tried asOBJ_VALUE | asOBJ_APP_PRIMITIVE, failed.


:). I really love angelscript, because it is simple. If we can make a GUI interface, and extract class information from source file. Inside of GUI interface, let user to choose which class is going to be used inside of the script, that would be great.

Wat do u think? I believe there are a lot of work for this.



Quote: Original post by dxj19831029
Ai~~~!

Still not working.
My version is newest version from repository.

Class __RECT {
long left;
long right;
long top;
long bottom;
long getDistanceX(__RECT &c);
}

I register this with:
asOBJ_APP_CLASS | asOBJ_VALUE
or asOBJ_VALUE
or asOBJ_APP_CLASS | asOBJ_VALUE | asOBJ_POD
or any combination with them.
not working.

assertion always failed.

Here is the code:
nRet = pScriptEngine->RegisterObjectMethod("__RECT", "long getDistanceX(const __RECT ∈ rect)", asMETHODPR(__RECT, getDistanceX, (__RECT ▭), long), asCALL_THISCALL);
assert( nRet >= 0);

Can u help me to correct it?

I am not sure the others, but for me if u can provide more full examples on register class, that would be great for me to follow. Just suggestion.

:)



Quote: Original post by WitchLord
You should declare the method with the function signature "long getDistanceX(const __RECT ∈ rect)". I added the 'const' and 'in' keywords. This will allow you to continue to register the __RECT type as asOBJ_VALUE.

The 'in' keyword tells AngelScript that the value in the reference is for input only, thus it can assure the safety of the reference in all circumstances.

The 'const' keyword gives a bit more assurance, and let's AngelScript optimize the code even further in that it doesn't have to make a copy of the original value in order to guarantee that it is not modified by the function.


[Edited by - dxj19831029 on September 9, 2008 2:21:02 AM]
long has a direct match in AngelScript, either int or int64 depending on the platform your using. You could just use either of these in your declarations.

However, if you want to be able to use long as a type in AngelScript, the easiest way is to register it as a typedef.

int r = engine->RegisterTypedef("long", "int"); assert( r >= 0 );


It can also be done in the scripts as follows:

// AngelScripttypedef int long;


A GUI application for parsing C++ projects and generating code for binding the classes with AngelScript would definitely be possible. However, I don't think I'll invest any time in that right now, I'm having a hard time finding enough time to work on the library itself as it is, one more large project like this will only slow down further progress on the library.

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

Cool.

Thanks.


Can u check my another problem?
Quote: Original post by WitchLord
long has a direct match in AngelScript, either int or int64 depending on the platform your using. You could just use either of these in your declarations.

However, if you want to be able to use long as a type in AngelScript, the easiest way is to register it as a typedef.

int r = engine->RegisterTypedef("long", "int"); assert( r >= 0 );


It can also be done in the scripts as follows:

// AngelScripttypedef int long;


Regards,
Andreas


What is the other problem?

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 think it is a bug, I write in another thread

Quote: Original post by WitchLord
What is the other problem?


This topic is closed to new replies.

Advertisement