Advertisement

Try Angelscript live!

Started by December 08, 2012 06:48 PM
8 comments, last by WitchLord 11 years, 11 months ago
Hi,

here's something cool I wrote up this weekend. With your modern browser with WebGL enabled, visit this page: MathGeoLib live test site. It is a project consisting of a few parts:

  • Uses my native C++ graphics rendering engine gfxapi. Utilizes the emscripten compiler to deploy the application to HTML5.
  • Integrates Angelscript as the live scripting engine.
  • Uses my MathGeoLib library for scripting primitives and geometry manipulation.
  • Interop between C++ MathGeoLib classes and Angelscript is achieved using an automatic bindings generator based on juj/CodeStructure.

    The application allows writing Angelscript live on a web page, and render stuff on the screen by using constructs from MathGeoLib and gfxapi. I really must congratulate Andreas Jönsson for the Angelscript project - it is a very fine piece of technology! I have previously written C++ - script bindings interop for MathGeoLib for QtScript and Javascript, and using Angelscript is the most mature, easist and convenient one of them to work with! I evaluated Python, Lua and Mono to replace my previous JavaScript-based scripting engines, but Angelscript is the king of the hill. The support for strong typing and ability to do value types with function and operator overloading is exactly what is needed for good interop and convenient games scripting, and something where the whole competition falls short :)
It's really cool to see different techs come together like this. Thanks for sharing.

I'll have to look into these other projects you link to. They all look interesting.

Thanks for the compliments on AngelScript. I'm very pleased to see you value exactly the features that made me start writing AngelScript almost 10 years ago, i.e. strong/static typing, and proper C++ integration.

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
Hey, something I was thinking while doing this: Are there any C++->Angelscript bindings generators out there? Something that would take in a set of .h/.cpp files and automatically generate the interop code for the symbols contained in those files?

That's something I ended up doing with this project, and I was wondering whether it is sensible to continue with that effort, or whether tools for that already exist?
Perform a forum search with "Generate" there are some binder generator scripts posted before.

i have started such project. Serious hurdles are:

- Can not determine object type. Is it a Value, NOCOUNT, Refcounted or Garbage collected
- Parameter type, &in &out &inout . Easy way out is enable unsafe refs.
- Inheritance, not enough to scan a single .h file. Allow casting or not?
- How about primitive typedefs
- Heap corruption errors, Yeah, they happen a lot. you can't spot these until functions are used in script. So, lots of test cases ?

my solution is to put preprocessor directives before some risky declarations.
I am getting tired, just too many cases to handle.
Manually registering them is way easier.
Your web page reminds me of Light Table (somewhat). Very cool!

Beginner in Game Development?  Read here. And read here.

 

Alpha_ProgDes: thanks!


Perform a forum search with "Generate" there are some binder generator scripts posted before.

i have started such project. Serious hurdles are:

- Can not determine object type. Is it a Value, NOCOUNT, Refcounted or Garbage collected
- Parameter type, &in &out &inout . Easy way out is enable unsafe refs.
- Inheritance, not enough to scan a single .h file. Allow casting or not?
- How about primitive typedefs
- Heap corruption errors, Yeah, they happen a lot. you can't spot these until functions are used in script. So, lots of test cases ?

my solution is to put preprocessor directives before some risky declarations.
I am getting tired, just too many cases to handle.
Manually registering them is way easier.


I use doxygen as the backend for my script generator. A lot of the required information is specified in the comments. For example, if a function has a comment /* @param outTriangleCount [out] Receives the number of triangles generated. */, then the presence of the string '[out]' tells the generator to use '&out' for the binding. The bindings are generated at a global project scope, not by scanning a single .h file, so the generator has knowledge of which types the script engine understands, and it automatically leaves out those signatures that contain symbols that aren't understood. Inheritance, #defines and typedefs are detectable, since doxygen knows about those, and the generator can be guided with special comments inside doxygen tags like [noscript] or [valuetype], etc. Whether the types have custom ctor/dtor/assignment/copyctor is known, and function default parameters can also be detected.

This is the third script bindings generator I have written with the same doxygen-based backend code. I have used the same approach with C++ -> QtScript bindings and C++ -> JavaScript (embind) bindings.

So far the generator is very primitive, and only used to expose MathGeoLib value types. What I'm looking for currently is whether I am duplicating my effort here and if it's sensible to write this at all, or whether someone else has solved this already.

I am still a beginner to Angelscript, so your insights on what exactly are the "not-automatically-detectable-by-introspection" kind of cases are very valuable to me. If you can give some pointers on what kind of "external" decisions a developer makes when building interop, that will be very helpful.
Advertisement
using doxygen is a great idea since it parses both comments and code.
i have used clang, unfortunately clang doesn't parse comments. boost::wave for preprocessor directives.
I dont like how mine turned out. It is a mess. Hard to use and integrate.
What is the point if i have to manually write directives for every parameter.

Maybe a GUI utility to help me fill those missing parts.
a workflow like this

1- generate xml from headers
2- open xml in gui
3- edit unwanted types, parameters, cast, constructors
4- press generate to create bindings
5- see them in gui, if dont like em go back to 3
6- save it so we dont repeat ourself later

generating binding is not worthy if process is just as hard as writing them by hand.
As you already pointed out, some things cannot be automatically generated. For example when to use autohandles, or when to use &in or &out. In these cases a manual decision has to be made. In many cases you also do not want to expose all types and functions either. Access profiles is another thing that has to be chosen manually.

My idea for an auto generator would work like this:

1. For a first time generation, the generator would parse the C++ files looking for potential types and functions that can be registered with the script engine. It should preferrably be possible to filter which C++ files to parse, so the generator doesn't try to understand the inner guts of the program.
2. The generator would store what it finds in an intermediate file where the user can select the types and functions that should and shouldn't register, as well as make the manual decisions mentioned before.
3. From this intermediate file, the generator would then generate the actual binding code that will be built with the application.
4. The generator should also have the capability of doing a new sweep over the C++ files to look for changes that have been made since the last time the binding code was generated. When this happens it should update the intermediate file, clearly marking what has been modified, yet keep the user added information where the C++ file has not been modified.

This 4th bullet is where the real benefit of an auto generator comes in. That is, the ability to automatically identify changes to keep the binding code synchronized with the C++ code.

The generator could have a couple of additional features, such as a GUI to browse and update the intermediate file, as well as to keep track of comments to be used to generate the documentation for the script writers. These features are however much less important.

All this should be done without requiring special comments in the actual C++ files. All user edited information should be kept in the intermediate 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

Thanks saejox and Andreas for the good insight! I think I've now got a good grasp of how to proceed. The tool will be available on github if you are interested in trying it out later.
It would be great to add a tool like this to the list of useful AS resources.

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