Jump to content

  • Log In with Google      Sign In   
  • Create Account


Questions About Managing Embedded Scripts in C++


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 Shaquil   Members   -  Reputation: 815

Like
0Likes
Like

Posted 30 October 2012 - 08:43 AM

I've coded a few 2D games now, and for my next project, I'd like to include simple cutscenes and some more complicated AI. I know that these are two things which, arguably, are best tackled by scripting languages, and so I've started researching them. Lua seems easy to embed with LuaBind, and I've gotten a small demo up and running; however, the actual Lua code must be written into a string which is passed to a function that parses the code, which is not at all what I expected.

If the Lua code is literally in the C++ code, then I immediately lose the huge benefit of being able to make changes to the script without having to recompile. I know one solution is to load the code as a string of characters from some outside file and pass that to the function. Or, if I just have the wrong attitude about this, what might be some wise options for loading up the script from some outside source? Right now my only plan is to write it up in a text editor with highlighting (like gedit), save it as a text file and load it up manually from there using the filestream. Plan B is to use pugixml (an xml parser) in a hacky way to read the script in.

Also, feel free to let me know if I'm just confronting this problem completely wrongly. Maybe dealing with a scripting language isn't the right move at all?

Thanks

Sponsor:

#2 ColinDuquesnoy   Members   -  Reputation: 1103

Like
0Likes
Like

Posted 30 October 2012 - 10:05 AM

What's wrong with loading script from file? I guess that is how we all do

#3 nox_pp   Members   -  Reputation: 490

Like
0Likes
Like

Posted 30 October 2012 - 06:53 PM

I know one solution is to load the code as a string of characters from some outside file and pass that to the function. Or, if I just have the wrong attitude about this, what might be some wise options for loading up the script from some outside source?


It's not quite that complicated. What you want is luaL_dofile. No need to manage the file streams yourself.

Between Scylla and Charybdis: First Look <-- The game I'm working on

 

Object-Oriented Programming Sucks <-- The kind of thing I say


#4 wqking   Members   -  Reputation: 756

Like
0Likes
Like

Posted 30 October 2012 - 08:39 PM

How to load and execute the script doesn't relate to the binding engine, which you are using Luabind.
Also, the test/example in Luabind is using C++ string for script doesn't mean you must do it.

You can always load the script from anywhere you want, an external file, an XML, what ever, and call Lua API to execute, no matter which script binding engine you are using.

http://www.cpgf.org/
cpgf library -- free C++ open source library for reflection, serialization, script binding, callbacks, and meta data for OpenGL Box2D, SFML and Irrlicht.
v1.5.5 was released. Now supports tween and timeline for ease animation.


#5 Lauris Kaplinski   Members   -  Reputation: 841

Like
0Likes
Like

Posted 31 October 2012 - 02:35 AM

The correct way of managing scripts depends on how you manage other assets (models, sprites, textures, images, shaders...). There is nothing very special about scripts - they are just another kind of datablocks that are used to put together a game.
Lauris Kaplinski

First technology demo of my game Shinya is out: http://lauris.kaplinski.com/shinya
Khayyam 3D - a freeware poser and scene builder application: http://khayyam.kaplinski.com/




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS