Since my game is already going to be scripted with Lua, I've decided to make all my configuration and localization data defined using Lua tables. For example, this could be a basic locale file:
-- en-us.lua
text = {
error = {
sdl = "Error initializing SDL",
opengl = "Error initializing OpenGL",
resource = "Error loading resource $",
-- ...
},
menu = {
offline = "Play solo",
online = "Play co-op",
quit = "Quit",
-- ...
},
-- ...
}
Different locales and profiles can be loaded simply by choosing the right file, for example between en-us.lua
and fr.lua
.
Because the table is in global scope, it's easy for other Lua code to reference. If a script needed to access a configuration variable or throw an error, it would just have to look up the value using something like text.error.opengl
or config.graphics.fullscreen
.
The difficulties come when native code (C) has to work with these values. There are basically two options that I can think of:
The tables are loaded into client code as a tree. It's easy to get and set values on the client side, but changes on either side need to be synchronized.
The native code does no caching and instead directly reads from/writes to the Lua state each time. Possible performance issues?
What's the best way to handle this from the native side?