Creating a Launch Script with Haxe/Lime

[ development  haxe  ]
Written on February 22, 2023
Reading time: 1 min

During the development of the library hxCodec, I found that I needed to add a launch script to be used on Linux, because if the executable was simply run directly, several dynamically linked libraries would not be found. This is because Linux does not search the current directory for libraries by default. This is a problem because these library files are necessary for the video player code that hxCodec uses.

I eventually discovered that you can use Lime’s template feature to do this for you. Including files with template is similar to including files with assets, but additional application context flags are replaced with the appropriate values. For example, the ::APP_FILE:: flag is replaced with the name of the executable file.

Here’s the snippet I used to add a launch script to hxCodec:


    <template path="templates/Linux/" rename="" if="linux" />

And here’s the launch script. Note that



# Start the game
env LD_LIBRARY_PATH=./lib/ ./::APP_FILE::

Note the use of ::APP_FILE:: in the launch script. The value will get replaced based on the target user’s project.xml file, which may look like this:


	<app main="Main" path="export" file="Sample" />

The resulting export will be this:



# Start the game
env LD_LIBRARY_PATH=./lib/ ./Sample

This is useful in the case where you need to include launch arguments or environment variables for the application to work.