Squirrel

The programming language
Welcome to Squirrel Sign in | Join | Help
in Search

Exposing Dynamic Objects to Squirrel

Last post 01-29-2008, 11:54 PM by punkapotente. 0 replies.
Sort Posts: Previous Next
  •  01-29-2008, 11:54 PM 2363

    Exposing Dynamic Objects to Squirrel

    First of all, I'd like to say hello to everyone. I'm new to this forum - I just registered.

    I came across Squirrel because I'm currently implementing scripting support into an application. I am pretty much done with a general language-independent scripting host. Now I want to create a reference implementation for a scripting plug-in which might, depending on how well it suits the needs of the application, remain the only one for some time.

    Anyway, I was looking at a couple of languages (Lua, JewelScript, GameMonkey, etc.) but Squirrel really seems to be the nicest I've seen. I like the fact that it incorporates many of the great features of Lua (metatables, delegates) with a - IMHO, as a C/C++ guy - better syntax, explicit support for classes, and a very clean interface. Excellent work, really!

    Now to my problem/question: basically, the application already has it's own dynamic object model and management with dynamically typed properties and I'm looking for a simple way to expose these to Squirrel. This is a bit different than the usual case, where you try to make your regular C++ classes available to the script - something which SqPlus seems to be targeting mainly. Anyway, for this and other reasons (like the fact that I want to allow multiple VMs to be running) I decided not to use SqPlus.

    So here's my situation: the application's object management provides access to all objects via a string identifier. All of these objects expose dynamically typed properties (also accessible via their string identifier) which can also be added/removed at runtime. What I really want to do is make these available to the script so you can do things like "doc.object1.myproperty1 = 0.5*doc.object2.myproperty2;" or "doc.object1.newintproperty <- 5;" and so on in the script. The objects should still be managed by the application (although I will probably implement creation/deletion of objects from the script at some later point).

    Now, I don't really want to use Squirrel's tables for looking up objects & properties, since the application already has hashtables to do all this pretty efficiently. This means that I don't want to generate a slot for every property, but rather have one generic mechanism. Since objects/properties are created/removed all the time, I don't want to track all these modifications and reproduce them in Squirrel. I rather want an "overloaded" implementation which uses the application's tables for this. I understand that something like this should be possible using userpointers & delegates, right? (Also, is it possible to make things like foreach work in such a setup?)

    However, I'm not really sure how to approach this - the documentation is a bit brief in that respect. I would greatly appreciate some feedback on this and how to get it working in Squirrel (without Sq Plus). Particularly, some example code would be fantastic.

    Thanks, and keep up the good work!

     

     

View as RSS news feed in XML
Powered by Community Server, by Telligent Systems