Skip to content

Lua Embedding #13

@Twinklebear

Description

@Twinklebear

Implement Lua for scripting objects behavior

  • Need to determine what is necessary to be exposed and what should be handled internally and how the API should work and such
  • Should entities be drawn automatically? Or should it be required to make the call yourself in draw?
    • I think an image file should be described in the entity's json file and used. Rendering should be toggle-able to enable/disable drawing of the image

Need a better way for Lua scripts to load the modules they need through something like require or such

  • Need a system to prevent scripts from being able to try and register the same module twice as it causes a crash. This issue is easy to encounter if perhaps you call "dofile" from a script with a module loaded and then the script that's just been loaded via "dofile" also attempts to load the same module, it causes a crash. Need to track which modules are registered by the state and quietly ignore re-registration attempts.

How should the State class be handled?

  • If I create the ability to call state functions like SetExit from Lua, will ObjectButton no longer be needed? since Button's OnClick script would then simply call the function? I'll try this and then decide what to do with ObjectButton.
    • I think I've got a method for this setup, see the static StateManager function ChangeScene
      • This isn't quite right. The button needs to set exit on the actively running scene so that it can exit cleanly
  • Will need some way to grab the active state, perhaps from StateManager? It's a pure-static class so yes, I think that will work
  • Also brought up by this is GameState vs. MenuState, ie. will such a distinction be needed or even a good idea once so much of the behavior is defined in Lua? I think they should be merged together when Lua entities fully take over, leaving us with a base State class that's used for the game and the EditorState which will only be used internally for creating the editor itself.

Should states be run via script? Hmm. What to do with states..

  • States will execute their basic C++ functionality, such as making the calls to the manager, and other background stuff, but will also call a function on a state script if one is attached

How to save data from script?

  • Have decided to leave this up to the user, so editor created data will be handled by JsonCPP and script data will be handled by whatever is desired for Lua, and will have no interoperation between the C++ saved data and custom script data.

Helpful Reading Material

Programming in Lua: The C API
Luabind Documentation

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions