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
Questions About Managing Embedded Scripts in C++
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.
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.
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.
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement