how to do these in 2.1.0??

Started by
6 comments, last by Deyja 18 years, 11 months ago
I always use the version 1.10, yesterday I update to the version 2.1.0, but some errors make me don't know how to fix :( 1.pEngine->RegisterGlobalFunction("void sincos(float, float & sine, float & cosine)", asFUNCTIONPR(fSinCos, (float, float&, float&), void), asCALL_CDECL); 2.pEngine->RegisterObjectMethod("File", "int Read(void *, int)", asMETHODPR(scriptFileClass, Read, (void*, int), int), asCALL_THISCALL); 3.pEngine->RegisterObjectMethod("File", "int Write(const void *, int)", asMETHODPR(scriptFileClass, Write, (const void*, int), int), asCALL_THISCALL); ...... above code is some my functions register, and are get error returned. in the version 1.10 there were no any problem, and I could not find the correct usage from the manual. I think I can not thought out what error happened :( please help me, thx.
Advertisement
In steps (2) and (3) you are registering methods for the object type "File". Before you register object methods, first you need to register the object type "File" with the method RegisterObjectType(...). I do not know if this is a requirement strictly for versions 2.x onwards of Angelscript as I've never used 1.10.

edit: Also, if you're going to register methods that use other object types in their parameter list or the return type, these object types must be registered beforehand.

[Edited by - SharkBait on May 11, 2005 4:00:55 AM]
tIDE Tile Map Editorhttp://tide.codeplex.com
Quote:In steps (2) and (3) you are registering methods...


He didn't post all the code. Chances are, registering the types didn't fail, so he didn't post them.

The problem is in the types being used as parameters to the functions. 2.0 handles it quite a bit differently. Pointers can no longer be used directly, and 'in out' keywords have been added, and all sorts of other things that involve using @. You'd best take a long walk through the app and script writers manuals again.
Indeed. Version 2.0.0 changed the script language slightly to provide a safer environment for scripting.

The registrations fail because you use the byref type modifier without one of 'in', 'out', or 'inout' keywords. The extra keyword is obligatory, because AngelScript needs to know what you intend to do with the values passed in the argument.

The pointer type modifier * is no longer available in AS 2.0.0. It has been somewhat replaced by the object handle @. An object handle is basically a reference counted pointer, and it requires the object type to have the addref and release behaviours registered.

I suggest you take a look at the sample application for more information on how things work now.

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

Duh.. my bad! :)
tIDE Tile Map Editorhttp://tide.codeplex.com
So that's why, hehe.

In steps 2 and 3, I registed the object type first, but I'm not post the full code, sorry:)

Infact, I like this script engine, because it like the C++ language. But remove the point operator, I don't know why? With my personal viewpoint, point is a very convenient thing, and same in script language, although the safety maybe a little bit bad......

However the problem is cleared up, THX:)
I agree that pointers are convenient. But unfortunately it is almost impossible to make the script environment safe and secure and still allow pointers, which is why I had to remove them.

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 simplified the move to 2.x by binding smart pointers to objects instead of actual objects. To the scripts, the change is invisible. To the app, they are still essentially pointers, with the bonus that I can pass them by value and not have to worry about screwing up AngelScript's own reference counting.

This topic is closed to new replies.

Advertisement