Is there any kind of “expression class” (C++)

前端 未结 9 1418
眼角桃花
眼角桃花 2020-12-13 14:45

I am creating a game that lets the player enter input, changes some states, then checks if a \"goal value\" is true (obviously this description is muchly simplified), and I

9条回答
  •  情歌与酒
    2020-12-13 15:14

    There's no standard way to do it in C++. One solution is to write your own parser.

    Another solution, that I'd recommend: embed a Lua interpreter in your program. Lua is a simple yet powerful programming language, that also has an extremely lightweight (<300kB) and easy-to-use interpreter. Read an introductory article here: http://www.ibm.com/developerworks/linux/library/l-embed-lua/index.html

    Having Lua embedded in your game has a number of nice side advantages:

    • you can use it as a powerful configuration language for your game
    • with Lua, you can easily create a command-line interactive environment, which is nice for testing and experiements. For example, you will be able to change the game engine parameters and see the effect immediately, without recompiling. That's especially convenient for "researchy" projects or game programming.

提交回复
热议问题