Jump to content
  • Advertisement
Sign in to follow this  
Angelic Ice

Simplifying Lua-Scripting for Users

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

Hello forum!


Currently all my logic is done within Lua (rest is in C++). However, I'm looking for user-friendly implementations.


For every enemy and other object, there is one Lua-file.

They provide functions which will be triggered on a mouse click or collision.


Additionally, there is a main file per level, which owns all the tables. It owns the event-triggers as well. If the player clicked something and the clicked target is an actual grid element of the level, C++ will call this function and provide the coordinates that has been clicked.


Now, I thought about moving all these into an more C++ entity driven approach in order to ease scripting for the modder.


At the moment, the user or modder would have to copy a Lua class template and then customise it.

Which is pretty terrible for people who have barely any knowledge. Yes, of course, there will always be people who lose their interest on all kinds of possible difficulties. Nonetheless, I would like to ease the pain and lower the chance of causing crashes.


Therefore, I thought about creating C++ entities instead Lua objects and just add needed components to it. Nonetheless, this leaves me open on saving the game.

It will cost some time to move the current implementation to a component system that just suits my needs (and the modder's).


Sadly, saving my C++ entities seems to be quite a possible neck breaker. As saving complex functions to a savegame  Lua table from C++ entities seems.. a bit difficult. Maybe using raw strings?

The C++ entities would be instantiated from a Lua table and shall be saved with all their changes during runtime back into a Lua table.

These entities will have different collide-functions (defined in the savegame Lua table) that shall be written back into the table.


An example for (in my opinion) clearer and easier approach.

monster = {

Collision = {

coordinates = {0, 0}

clicked = function(this)


Graphics = {

-- ...



In the end, I'm really curious on what kind of popular approaches are being done for Lua/C++ modding-friendly approaches.


Share this post

Link to post
Share on other sites
You might want to take a look at how Urho3D does it. They implement Lua scripts as a component that you can add to an object. You can register to receive particular events in script, and the events are handed off to the proper event handlers in the script object.
Urho3D serialization serializes to XML rather than a Lua table, however, but you still might be able to get some ideas by seeing how they do things. In my own code that uses Urho3D, I have written routines that can save/load objects to/from Lua tables. It's not too difficult. Edited by JTippetts

Share this post

Link to post
Share on other sites

Yeah, I read about Urho3D having a solution to this already.


However, are there any common design patterns for this? While I'm aware that implementations often differ, there still should be commonly used approaches for this

Is Urho3D doing such? If yes, how is this pattern called and where could I read more about it?

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!