Skip to content
Li, Xizhi edited this page Jul 27, 2017 · 10 revisions

Hello World in NPL

This tutorial demonstrates

  • how to setup a simple development environment
  • write a program that output hello world
  • explains the basic concept behind the scene

This article is an aggregates of information you will find in this wiki guide. Skip this tutorial, if you have already read all related pages.

Setup Development Environment

For more information, see Install Guide.

Windows Install

git clone https://github.com/LiXizhi/ParaCraftSDK.git
  • Make sure you have updated to the latest version, by running ./redist/paracraft.exe at least once
  • Run ./NPLRuntime/install.bat
    • The NPL Runtime will be copied from ./redist folder to ./NPLRuntime/win/bin
    • The above path will be added to your %path% variable, so that you can run npl script from any folder.

To write NPL code, we recommend using either or both of following editors (and plugins):

Linux Install

Under linux you need to compile from source code.

git clone https://github.com/LiXizhi/NPLRuntime.git
./build_linux.sh

One can also use ./npl_install.sh to install, which automatically download prerequisites.

Hello World Program

Run in command line npl helloworld.lua. The content of helloworld.lua is like this:

print("hello world")

You should see a file ./log.txt in your current working directory, which contains the "hello world" text.

Linux Command line

In linux, npl is installed to /usr/local/bin/npl if you installed it from source code. Therefore, one can invoke standalone npl application like below. Write helloworld.npl like below

#!/usr/local/bin/npl
print("hello world")
ParaGlobal.Exit(0)

And then one can run the application with the command

./helloworld.npl

Please note only *.npl and *.lua file extension are supported.

Windows Command line

Under Windows, the npl executable folder need to be added to search path. If npl command is not found, make sure ./NPLRuntime/win/bin is added to your search %path%; or you can simply use the full path to run your script (see below).

__YourSDKPath__/NPLRuntime/win/bin/npl helloworld.lua

Behind the Scenes

ParacraftSDK's redist folder contains an installer of Paracraft. Running Paracraft.exe from redist directory will install the latest version of Paracraft, which ships with NPLRuntime. ./NPLRuntime/install.bat copies only NPL runtime related files from redist folder to ./NPLRuntime/win/bin and ./NPLRuntime/win/packages

./NPLRuntime/win/packages contains pre-compiled source code of NPL libraries.

To deploy your application, you need to deploy both bin and packages folders together with your own script and resource files, such as

./bin/       :npl runtime 32bits 
./bin64/     :npl runtime 64bits
./packages/  :npl precompiled source code
./script/    :your own script
./           :the working (root) directory of your application

In NPL script, you can reference any file using path relative to the working directory. So you need to make sure you start your app from the root directory.

Further Readings

ParacraftSDK contains many example projects written in NPL.

Clone this wiki locally