Many games support script languages to be able to change their logic with having to re-compile: Blizzard allows customizing your World of Warcraft user interface with Lua, for instance, and CCP built EVE Online around Stackless Python.
I’ve been messing around with C++ Windows Store Apps recently, more specifically with DirectX games for Windows Store. It required quite a bit of an effort to get Lua to run (and validate) with Windows Store apps, and I’d like to share my learnings.
- Download and install Microsoft Visual Studio Express 2013 for Windows, and create a new Visual C++ Windows Store DirectX App.
- Download and extract the Lua 5.2.3 source code.
- Copy and include the contents of the Lua src folder in your project.
- VC++ does not support C++/CX extensions in files compiled as C. Select all Lua C source code files, and open the properties dialog. In Configuration Properties > C/C++ > General, change Consume Windows Runtime Extension to No.
- The precompiled header file (pch.h) for the Windows Store App is C++ and can’t be used from C. With all Lua C source code files still selected, open the properties dialog. In Configuration Properties > C/C++ > Precompiled Headers, change Precompiled Header to Not Using Precompiled Headers.
- Some of the functions in Lua call system and IO functions that are not supported by Windows Store Apps – but we’re not going use them anyway:
- First, we need to disable deprecation warnings for these functions treated as errors. In the properties of your C++ project, in Configuration Properties > C/C++ > Preprocessor, add _CRT_SECURE_NO_WARNINGS to your Proprocessor Definitions.
- Next, in luaconf.h, remove the LUA_DL_DLL define in the #if defined(LUA_WIN) section.
- In lualib.c, remove the io_popen and io_pclose functions, and remove the popen entry from the iolib array in the same code file.
- In lua.c, loadlib.c and loslib.c, replace all calls to the getenv function by NULL. These functions are designed to handle NULL as a failed call to getenv.
- Finally, in loslib.c, remove the os_execute function and its entry in the syslib array in the same file.
- In the source file luac.c, remove the main function.
- Build and deploy the solution, and observe that validating it using the Windows App Certification Kit succeeds, except for the Branding validation test that requires you to replace the app icon images.
Congratulations, you’re good to go! Go ahead, and take your first steps with the overview of the Lua C API!
1. Justin M. Chase. Embedding Lua into a Windows Store app. January 13, 2014.