Deploy Your Application

You can deploy your application to windows, linux, ios, android, etc. Both 32bits/64bits versions are supported.

  • NPL scripts can be deployed in plain *.lua or *.npl text files or in precompiled *.o binary file.
  • You can also buddle all or part of your scripts or any other read-only resource files into one or more zipped archive files.
  • You can deploy NPL runtime globally or side-by-side with your application files.

For automatic deployment, please install and use ParacraftSDK. This articles explains how to do it manually.

Pre-compiling NPL script

Precompiled NPL script is called bytecode in lua. The bytecode generated by Luajit is incompatible with bytecode generated by lua, but is cross-platform for any (32bits/64bits) architecture. If you choose to deploy your app with bytecode, you must also choose to use luajit or lua when deploying NPL runtime.

Please read the documentation in NPLCompiler.lua for more information. Examples:

NPL.load("(gl)script/ide/Debugger/NPLCompiler.lua");
NPL.CompileFiles("script/*.lua", nil, 100);

Buddle Scripts in Zip files

You can buddle your script and assets in zip files. There are two kinds of zip files: one is the standard *.zip file, the other is called *.pkg file. You can create *.pkg file from a standard zip file with the NPL runtime like below. *.pkg use a simple encription algorithm over the zip file.

ParaAsset.GeneratePkgFile("main.zip", "main.pkg");

When application starts, NPL runtime will automatically load all main*.pkg and main*.zip files in the application’s start directory into memory. The load order is based on file name, so that the a file in “main_patch2.pkg” will overwrite the same file in “main_patch1.pkg”.

Please note that loading pkg file is very fast, it only copys the file into memory, individual script file or assets are only unzipped and parsed on first use.

A programmer can also programmatically load or unload any archive file using the NPL API like below.

NPL.load("pluginABC.pkg");
-- or using explicit calls
ParaAsset.OpenArchive("pluginABC.pkg", true);

The second parameter is whether to use relative path in archive files. (i.e. file path in archive file are relative to the containing directory). Search paths, such as from npl_packages are honored when loading archives.

Deploy NPLRuntime Side-By-Side

Deploying NPL Runtime side-by-side is as easy as copying all executable files to the application directory. The recommended deployment folder structures is below

bin/: npl exe, dll, lua,luajit, etc
packages/: common *.pkg *.zip package files
script/: your own script files
config.txt
any other files

Another way is to deploy everything to the application root directory.

script/: your own script files
npl exe, dll, lua,luajit, etc
common *.pkg *.zip package files
config.txt
any other files
if config.txt file is on the root application directory. Its cmdline content will be appended to NPL command line when running NPL runtime from this directory.

An example config.txt, see below:

cmdline=noupdate="true" debug="main" bootstrapper="script/apps/HelloWorld/main.lua"

Luajit vs Lua

Luajit and Lua are ABI-compatible, meaning that you can deploy NPL runtime with them simply by replacing lua.dll(so) with either implementation. Luajit is the recommended way for release deployment on all platforms. However, currently on iOS, Luajit is used but disabled, since it is not allowed. Even a disabled luajit runs faster than lua and its bytecode is the same for both 32bits and 64bits OS. So you would only want to deploy lua dll for debugging purposes on development machines.