Embedding a Ruby interpreter in a C++ app

前端 未结 5 1080
半阙折子戏
半阙折子戏 2020-12-08 08:56

I\'m hoping to use Ruby as a scripting language for my game engine. I\'ve found the usual articles describing how to call Ruby classes from C++ code and vice versa (e.g. her

5条回答
  •  暖寄归人
    2020-12-08 09:08

    You could always re-design the way the scripts work to suit the script engine rather than trying to get the engine to work with the original scripting paradigms.

    So, if you had this:

    proc:
      action 1
      action 2
      sleep a bit
      action 3
    end
    

    which would require the script to be suspended on the sleep line, do this:

    proc
      action1
      action2
      set timer (time, callback_proc)
    end
    
    callback_proc
      action3
    end
    

    which lets the scripting engine finish each method neatly. It wouldn't need many changes to the hosting side - each version requires some form of event system which can restart the script engine.

提交回复
热议问题