Advertisement

New AngelScript Bind

Started by August 20, 2007 10:43 AM
5 comments, last by SiCrane 17 years, 3 months ago
Hi all!! I'm new to this forum but I'm working with AngelScript for a couple of months. My first experiences with script languages was mainly with Lua and Squirrel, but I don't like them. I used them because they have beautiful binding systems =) ( I prefer SqAdd over LuaBind because the compilation times =/ ). I fell in love with AngelScript BUT it doesn't have any binding system, so I decided to start one, based on the ideas from LuaBind and SqPlus. I firmly belive that I am not as best as the coders of these binding systems, so I KNOW there are thousands of things that could be improved a lot, so don't be so hard with me, please =) I made a little modification to the AngelScript library in order to add the binding system ( only a user pointer data here and there =P ), so I upload AngelScript 2.9.1 ( the latest release ) with these changes, just in case you want to test the binding system with your current project. I'm so sorry because there isn't any documentation about the code, so I upload a simple example too. With the binding system you can: - Register global C functions with parameters ( limited to 6 ) and return value. - Register methods of a class providing a pointer to an instance of it ( for singletons, for example ). - Register classes - Constructors - Methods - Variable members - Operators - There are some policies ( not polished at all ) when registering a class. - Create AngelScript class instances from C++ - Call methods of AngelScript class instances I think that's all by now. I must to say that the binding script only works with generic calls by now, because my project is running on Nintendo DS ( ARM ) and it isn't supported with native calling conventions. It should be easy to add native calling conventions to the binding system, but I don't have the time ( sorry =/ ). I think I'm making this boring... =P Well, the link to the file is: http://www.yourfilelink.com/get.php?fid=376397 I hope you like it and find it useful. Please, give me your feedback to see if my work is worth ( mmm.. I think this is not correct =P ) Thanks to all, and sorry for my english ;( < MChiz >
This looks very good to me. Of course I would prefer if the binding system could support directed parameter references (∈, &out), and also object handles. But if you limit the application interface to not use these, then that's not a problem.

I'd like to hear what SiCrane, midnite and Deyja have to say as well, since they have all written their own binding systems.

So, you're programming for the Nintendo DS. Can I add this as a supported platform then (without native calling conventions, of course)?

I heard that the ARM processors don't have floats, how are you handling this? Or is this not true?

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

Advertisement
I would look at it, except it's in a rar, not a zip.

Witchlord, my macro-based binder supports all that stuff, but it's not really designed to replace the registration stuff there already - all it does is wrap it up so it can be moved to individual CPP files, instead of having a single 'register everything with the script engine' function that is dependent on everything. This way, everything that is registered is dependent on the scripting module, rather than the scripting module being dependent on everything that is registered. Also it's macro-based, which kind of sucks.

The problem with doing this is that, without proper reflection in C++, you still end up having to enumerate everything about a class. I personally delight in the control this gives me, but I know it would be nice if I could just register foo, and have all it's methods show up. I don't think this is possible in C++.
You can unpack .rar files with 7zip. It's open source and, in my opinion, better than WinZip and WinRar.

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

Implementation-wise is seems fairly similar to the binding system I use. There are some differences: namely the lack of support of non-default calling convention function pointers and lack of support for arbitrary function objects, but most of the template principles are the same.

I'm a little suspicious of the storeAddress() functionality. It seems to be a hack to get member function pointers to fit happily in the added void * user data section. However, if you're going to go that route you might as well use a macro to create a unique static member function pointer at point of call and use the address of that. That avoids the need to register with a global and reduces heap fragmentation.

I'm also not certain what effect registering dummy functions would have on AngelScript. For example, as far as I can tell, registering an AddRef() function with AngelScript modifies in a fundamental way how the virtual machine handles the class, even if you register a no-op function. Similarly, it seems the the class binding fails to allow registering value types with the system like Deyja's favorite smart pointers.

Some primitive specializations also seem to be missing such as char (which is a separate type from signed char and unsigned char, wchar_t and long double.
WitchLord:

Sorry for that big delay in posting the binding system. I was offline ( no internet conection =/ ) and with a lot of work.
I use object handles when the parameter is a pointer ( I found this to fit on all my cases ). Since I didn't want to think too much about '∈' and '&out' because I didn't have the time, I decided to force references to '&inout', at least by now.
I'm happy that you like the binding system. Of course you can add the platform to your list =) Nowadays we aren't developing any game, I'm the only programmer and I'm doing research about the platform. When we start a game, I'll tell you =)
If you want to put the binding system ( as you can see it has no name yet =P ) on your web ( if you think it has sufficient level ), I'll be so glad.
I'd like to be capable to code the calling conventions for the ARM, but as I said to you some months before, I don't have the level =(
EDIT: I forgot your question about floats, sorry. It is true, Nintendo DS ( and all ARMs, I think but I'm not sure ) doesn't support floats, but they can emulate them. I use floats with AngelScript without problems, but only at load times and things like that, where this problem is not a problem =P When I need to do some heavier things I use a fixed point class which I published to AngelScript without any problem.

Deyja:
Do you want that I upload the file in ZIP? You only have to say it =)

SiCrane:
The storeAddress function is only a function that writes in a pool all the extra data I need doing the calls ( as you have seen ). If you don't want fragmentation you can register all the functions you want, see how big is the buffer and then, in some point of your initialization code, do a resize of that size ( even you can automate this writing the value to a file and read it back later ). I really don't see which is the problem with that method... I thought it was not too dirty. I don't understand your solution, sorry... maybe you could put an example =) that would be great to learn!
The dummy AddRef is only used when you have an instance that is managed entirely in C++, but can be created from script. I don't know if it doesn't work with AngelScript. Maybe WitchLord could help with that =)

The fact which I decided to do my own binding system was that I couldn't find one on Internet. Can I download your binding systems from somewhere? I'd like to give them a try and use them if they are better, and I'd like to learn too =)

Thanks to all!!

< MChiz >
Advertisement
For the static member pointer I mean something like:
#define METHOD(type, name, ptr)   {    static asMETHOD_t method_ptr = (asMETHOD_t)ptr;    type.method(name, ptr, &method_ptr);  }

This obviously doesn't allow the function chaining that you had.

In any case, I've mentioned my wrapper in a couple places in the AngelCode forum in the last few weeks. The most recent upload being in this thread. It's not production quality - consider it to be alphaware. I'm also in the process of rewriting it for 2.9.1. since Witchlord was kind enough to integrate my AngelScript change requests into the code base.

This topic is closed to new replies.

Advertisement