#640 libguile-based scripting engine for Player server side

Release-3.0
closed-accepted
Rich Mattes
Player (393)
5
2011-05-12
2011-05-01
Paul Osmialowski
No

Scripting engine for Player Server.
Note that full description of this driver would be a book size (and maybe one
day such a book will be written). Experienced Player user who is also familiar
with C++ and Scheme programming languages (being familiar with quasiquote and
unquote helps significantly) can figure out how this scripting engine can be used
just from examining provided examples and this driver source code. Due to the
nature of libguile (embedded Scheme interpreter), this driver is not threaded
and is completely message-driven. It is good idea to keep it in separate Player
instance.
On each message arrival a function defined as follows will be executed:

(define fname (lambda (link hdr data env)
(your-code)
))

Such a function can be considered as a think-act part of sense-think-act loop.
Using 'scriptfile' or 'script' configuration file option, function body
can be provided.

Depends on libguile from guile 1.8.x (uses pkg-config infrastructure to figure out if it is present in the OS)

To build this scripting engine I had to implement one thing that is missing in Player: reflection - ability to create new objects by name given as a string.
My reflection implementation makes this scripting engine better than all python bindings that I worked with - it can handle any kind of data (arrays are always treated as lists, so even camera data can be processed easily).
To my surprise it does not create heavy load even when I start it on my old P4HT desktop PC. Also memory consumption is not heavy.
Reflection code is a C++ code generated by somewhat cruel bash script. It assumes that syntax of .def files and structure of player.h file will never change significantly, namely, these rules are important (today all *.def files and player.h conforms these rules so I didn't have to touch any of them):
- all important structures are defined as "typedef struct"
- "{" is in separate line
- only one field defined in one line
- comments (remarks) are only in separate lines or at the end of definition line (as the last thing of such a line)
If something is wrong with processed files, this bash script is capable to explain what the problem is.
This bash script is executed only when guile driver is enabled. Since it is rejected on WIN32, it will never be started on windoze.
Guile driver is disabled when pkgconfig cannot find guile-1.8.pc file in the OS.

Tested with SVN snapshots taken 2011.03.05 and 2011.04.30 and everything world in Stage.

Discussion

  • I have noticed that I pasted the same example twice in comment section, Now I uploaded updated patch with fixed comments.

     
  • Rich Mattes
    Rich Mattes
    2011-05-12

    Very cool! I've added the patch and committed it to trunk. Any chance you'd have time to add a little bit about the guile driver to the Player wiki as well?

     
  • Rich Mattes
    Rich Mattes
    2011-05-12

    • status: open --> closed-accepted
     
  • I may write something longer about new driver on Wiki, however in next few days (week or so) I'll be too busy to do that, so it will have to wait.