Sign in to follow this  

Questions About Managing Embedded Scripts in C++

This topic is 1903 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

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

Share this post


Link to post
Share on other sites
[quote name='Shaquil' timestamp='1351608227' post='4995433']
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?
[/quote]

It's not quite that complicated. What you want is [url="http://pgl.yoyo.org/luai/i/luaL_dofile"]luaL_dofile[/url]. No need to manage the file streams yourself.

Share this post


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

Share this post


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

Share this post


Link to post
Share on other sites

This topic is 1903 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this