After a few days of code crunching, I can finally say that my LuaScript subsystem is operational enough that a portion of the game can be run with it.
The LuaScript subsystem allows us to load a Lua script and execute its default code in a new Lua environment. It also register the custom Lua extensions that were created for HDB.
The process consisted of implementing a simple interpreter, hooking it up to the file-manager and executing the bundled Lua scripts through
Common::SeekableReadStreams. Alongside with the interpreter, Lua error reporting facilities were added to the engines. In case Lua faces a problem, a stack traceback is printed to the screen.
Along with a standard interpreter, the Lua subsystem in the original had a series of Lua extensions, Global Strings, Global Values, Sound and Entity Spawn names attached with them. As of right now, I have created stubbed-out versions of the extensions and registered them with each Lua environment. I’ll be adding the Globals as and when I need them. The Sound and Entity Spawn names will be added once those subsystems have been implemented.
The coming weeks would involve filling out these stubbed functions by building the subsystems they rely upon.
Changes from Lua 4.0 to 5.1.3
During the proposal period, I had performed a high-level overview of the differences between Lua 4.0 and Lua 5.1.3 in order to gauge how difficult it would be to run Lua 4.0 code through a Lua 5.1.3 interpreter. While the HDB codebase was largely compatible with the changes, it seems that there were a number of smaller changes that were not. Here is the list of the ones I have found so far.
- Upvalue Syntax: Upvalues are the closet thing to static function variables in Lua. The syntax for accessing them inside a function was changed from
xfor an upvalue-referenced variable
- setglobal: Lua 4.0 had a predefined function for assignment. In certain cases, such as dynamically determining the name of a variable, it led to cleaner code and has been used in certain places.
- for Loop Syntax: From Lua 5.0 to 5.1, there was a subtle change in the scope of the implicit variables of the for and for the repeat statement. Now
for i, v in tablehas to be replaced by
for i, v in pairs(table).
Another thing I found, which is not a difference in the Lua syntax, is the usage of C++ style comments in the Lua codebase. Apparently, these were put there for a reason since there is code to preprocess it in the original sources. For my implementation, I have replicated their method entirely.
In the beginning, the plan was to write a preprocessor function to transform the code into valid Lua 5.1.3 code. However, the syntax changes proved to be both unique and countably few that makes more sense to just patch the differences wherever they occur. Now, we have a ScriptPatch system in place that keeps a track of known differences, and updates them before executing a file.
- The current objective to build the map-loader, and draw an entire map to the screen.
- Add the map animations once a complete single frame of the map has been drawn.
- Add the main hero to the map, at which time we can work on input and AI.