Advertisement

Script/Native Interaction

Started by June 11, 2004 07:55 AM
2 comments, last by Keem 20 years, 5 months ago
Hi there, I am in the middle of desiging and implementing scripting support for my engine. I am having no ( or little ) difficulty with most of the concepts involed but I am having difficulty visualising how some of the more complicated script to native interactions will work. I can handle self contained scripts ( messing around with strings, or arithmetic or manipulating scripted classes ) but the following two cases give me problems. (scripted function taking native parameters) function HitEnemy( Enemy enemy ) { ... } // where enemy is a native class Now I do have some ideas but I''m not sure if they are quite sensible. When a game is run ( maybe on a mode switch ) it could output a ''library'' of the native classes that can be read by the script compiler ( so that the first example above doesn;t throw a "Enemy: No such type" error. When a class gets instantiated by the Factory a simple class containing it''s address and exposed methods ( as typesafe function pointers , functors ). Get put into some kind of symbol table for the VM the when enemy.TakeDamage() is called the VM can lookup enemy in the sybol table and call the function. Like i say, it''s this part i''m having difficulty visualising ( after all i''ll use lexx & yacc to do most of my compilation work ) or (calling native code from native objects from a script) enemy.TakeDamage(); // where enemy is again a native type and TakeDamage() a natively defined function. If anyone has any pointers on this kind of thing it would be most appreciated, it seems that all the tuts that i have found ( fantastic though they are ) don''t go this far.
The best thing to do is study 2 or three scripting languages to see how they do it. Then pick the method that you feel most comfortable with.
Advertisement
That''s what I''m trying to do. Any pointers to languages that have this kind of information available?
I did it by studying the implementations of the languages. I'm very comfortable with embedding objects with Spidermonkey. Generally, you push parameters onto the script's stack in some way. And then call the scripted function. Or The script pushes parameters into a stack (public or private) and calls a specifically typed native function.

In Javascript it's something like:-

jsbool functionname(JSContext *cxt, JSObject *obj, jsint argc, jsval *argv, rsval ret)

Game Scripting Mastery (Alex Varanese) may be helpful in your cause.

[edited by - downgraded on June 14, 2004 9:34:19 AM]

This topic is closed to new replies.

Advertisement