Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Keem

Script/Native Interaction

This topic is 5146 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
That''s what I''m trying to do. Any pointers to languages that have this kind of information available?

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!