SQREWD - dynamic squirrel binding library

BlitzMax Forums/BlitzMax Programming/SQREWD - dynamic squirrel binding library

grable(Posted 2013) [#1]
been playing with squirrel for the past few days, and got tired of manually wrapping types.
so i made this binding lib using runtime code generation called sqrewd.

yeah thats how i felt when doing it manually ;)

it uses a modified BRL.Reflection and an x86 runtime assembler to expose a type and its constants, fields, methods and functions to squirrel.

it can also wrap objects so instances can be passed between squirrel and blitzmax.

im just dumping it here in case anyone needs it, or want to know more about how to embed squirrel.

an example using a Vector3 as a sample type:

sample.nut
local x = Vector3( 1, 2, 3);
local y = Vector3(3, 2, 1);
local z = x + y;
print( "x == " + x + "\n");
print( "y == " + y + "\n");
print( "x + y == " + z + "\n");


UPDATED: March 8 2013
v 0.9:
added typetag meta, which saves having to pass it manually. and it gives the generated stubs ability to verify typetags as well.
otherwise tightened error handling and optimized some of the generated code and fixed a few bugs in arguments and properties.
allso made types nullable, for properties and arguments.

sqrewd_v0.9.7z
sqrewd_v0.8.7z

happy coding :)


Derron(Posted 2013) [#2]
Is there a reason why you have to "extend" TSquirrelObject?
Maybe this should be automagically done when registering an object to the squirrel-vm (like an container).

This would make auto-exposing possible without changing too much code (done that similar for lua).
Especially when using reflection you should be able to avoid the "extend".


bye
Ron


grable(Posted 2013) [#3]
You dont have to extend TSquirrelObject, its for convenience really.

Just define the fields in your custom type and add the wrapped meta and some manual linking in constructors etc and your good to go.
Of course this is if you require full wrapping, just exposing a type without wrapping requires only metadata.

If you check the source for TSquirrelObject you can se its pretty basic.


Derron(Posted 2013) [#4]
Thanks for clarification. Nice to have alternatives but for my current project I will stay with Lua.

PS: your first post sounded like "i did it during the last days" - but the posts concerning some bugs and reflection-extensions state you are playing with squirrel for over 3 years now.

What advantages does it have compared to Lua (especially supported platforms and language bindings) ? Smaller Footprint, more versatile language construction? ...


bye
Ron


GW(Posted 2013) [#5]
Nice!


grable(Posted 2013) [#6]
haha didnt think of that, maybe i should have added a date or something to that post ;)

Well it was inspired by Lua, so they are very similar. At least from en embedding standpoint since their apis are similar.

Personally i like builtin support for classes and compile-time constants, and the syntax :p

How fast and whatnot i cant say, havent studied squirrel or lua source enough.


grable(Posted 2013) [#7]
Found some glaring bugs in argument handling and properties, so if anyone is using the old version please update.

this one is much more resilient to faulty inputs.

check top post.

Oh, and thanks GW. this is the kind if thing i like making too :D


GW(Posted 2013) [#8]
cool. have you make modifications to the reflection module?
if so, what version of bmax are you using?


grable(Posted 2013) [#9]
Yes, there are changes to BRL.Reflection. but only thing recently new is type constants.
its the same version as i put here BRL.Reflection: Pointer support

dunno which version they got included in or if they have been there all along though ;)

in any case im using blitzmax 1.48 win32.