tech

[English] [Japanese]

01. Introduction

This time, it is an introduction about how to introduce LuneScript.

LuneScript on Web Browser

A LuneScript environment that runs on a web browser is provided for checking LuneScript operations.

../onweb

Also, the following sample sources have a case with a Run button. By pressing that button, you can run that sample source. And you can modify the source and run it.

It takes several seconds to 10 seconds for the first time after pressing the Run button until the sample is executed (the time depends on the network environment and terminal specifications). This is to load the Lua VM and the LuneScript compiler on your browser.

When re-executing after loading once, it can be executed instantly because this loading process is not performed.

How to install LuneScript

LuneScript provides two delivery methods:

  • A single-binary go version that can run on its own
  • Lua version that works as a Lua script

go version

We have prepared a Dockerfile for building LuneScript from sources registered in git.

https://github.com/ifritJP/LuneScript/tree/master/src/test/docker/compose

  • linux/build/Dockerfile
  • alpine/build/Dockerfile

Run the following to generate lnsc for Linux in LuneScript/src:

$ git clone --depth 1 https://github.com/ifritJP/LuneScript
$ cd LuneScript/src
$ sudo docker build -t linux_lns test/docker/compose/linux/build
$ sudo docker run --rm -v $PWD:/local linux_lns cp /usr/bin/lnsc /local/lnsc

Put lnsc in your PATH.

In the proxy environment, please specify the proxy as follows when docker build.

$ sudo docker build -t linux_lns test/docker/compose/linux/build --build-arg PROXY=http://proxy.hoge/

That's all for the go version of LuneScript.

Lua version

The Lun version of LuneScript has a much longer transcompile time than the go version. We recommend using the go version.

LuneScript is a Lua transcompiler. Also, LuneScript itself works as a Lua script.

Therefore, the Lua version of LuneScript requires a Lua execution environment.

The Lua versions supported by LuneScript are 5.1, 5.2, 5.3, and 5.4.

However, there are some restrictions when using with Lua 5.1. The details of the specific limits are described in a separate article.

Postscript: 12/10 (Lua 5.1 support)

The version of Lua installed by default on your system is often 5.1.

Check the installed Lua version with the following command:

$ lua -v

Introducing Lua

Lua can be downloaded from the following URL.

http://www.lua.org/download.html

If it is Linux, it can be easily installed with package management, but be careful about the version of Lua.

For example, in apt package management such as ubuntu, it can be installed with the following command.

$ sudo apt install lua5.3
For Windows

On Windows, the cygwin version of Lua is required.

Transcompiled Lua code works without cygwin version.

However, LuneScript itself assumes the linux environment, so cygwin is required.

Be sure to prepare the cygwin version of Lua.

I'll check later if it works with the Windows Subsystem for Linux.

Since it works with WSL2, it is possible with WSL2 instead of the cygwin version.

Introducing LuneScript

As mentioned above, LuneScript works as a Lua script.

Lua's module management is very simple, just put files in the Lua-managed module directory.

LuneScript modules are published on github.

https://github.com/ifritJP/LuneScript

You can set it up by copying the files manually, but hereafter we will explain how to set it up using LuneScript's setup.lua.

Copying files manually is difficult unless you are familiar with Lua's module management.

How to install LuneScript

Run the LuneScript setup.lua.

Here are the steps:

$ git clone https://github.com/ifritJP/LuneScript.git
$ cd LuneScript/src
$ lua5.3 setup.lua -d
$ sudo make install

This will install LuneScript into the modules directory.

If you want to specify the module directory of Lua to install LuneScript, remove -d from lua5.3 setup.lua -d and execute.

module directory managed by Lua

You can check the module directory managed by Lua with the following command.

$ lua5.3 -e 'print( package.path )'

The result of the above command will be: (depending on the environment)

/usr/local/share/lua/5.3/?.lua;/usr/local/share/lua/5.3/?/init.lua;/usr/local/lib/lua/5.3/?.lua;/usr/local/lib/lua/5.3/?/init.lua;/usr/share/lua/5.3/?.lua;/usr/share/lua/5.3/?/init.lua;./?.lua;./?/init.lua

Delimiting this with ; gives:

  • /usr/local/share/lua/5.3/?.lua
  • /usr/local/share/lua/5.3/?/init.lua
  • /usr/local/lib/lua/5.3/?.lua
  • /usr/local/lib/lua/5.3/?/init.lua
  • /usr/share/lua/5.3/?.lua
  • /usr/share/lua/5.3/?/init.lua
  • ./?.lua
  • ./?/init.lua

I won't go into details, but the following directory is the module directory managed by Lua.

  • /usr/local/share/lua/5.3
  • /usr/local/lib/lua/5.3
  • /usr/share/lua/5.3
  • ./

The directory will vary depending on your environment.

The module directory can also be specified by environment variables, but we will omit the explanation here.

emacs settings

LuneScript provides an emacs lisp for developing with emacs.

Make the following settings.

  (add-to-list 'load-path "my-lune-path")  ;;; clone した LuneScript のパスを指定
  (setq lns-lua-command "/usr/local/bin/lua")  ;;; lua のパス
  (require 'lns-conf)
  (require 'lns-flymake)
  (require 'lns-company-mode)
  (require 'lns-helm)

This gives you:

  • Indentation and coloring of .lns files
  • Syntax checking with flymake
  • Completion with company-mode

Syntax checking supports flymake and flycheck. If you want to use flycheck, require lns-flycheck instead of lns-flymake.

Please do M-x package-install separately for helm, company-mode, flycheck, flymake.

project file

LuneScript utilizes a directory hierarchy for module management. Therefore, the current directory is important when transcompiling with LuneScript.

By placing a file with the following name in the current directory for transcompiling, it will be treated as a project file.

lune.js

Especially when you edit the LuneScript source with an editor, this file is searched to recognize where the project directory of the LuneScript source is, so be sure to generate the above file.

Project file format

The project file is in JSON format.

At a minimum, create a lune.js file with the following content:

{}

The directory in which this file is placed will be the starting directory of the module.

For example, if the directory structure is as follows,

foo/
foo/lune.js
foo/bar/
foo/bar/mod1.lns

bar.mod1 is the module path for mod1.lns.

Add command line option

By setting LuneScript command line options in the project file, the command line options set in the project file will be used when transcompiling.

To set the command line option, set the string list with the cmd_option key as follows.

{
    "cmd_option": [ "--valid-luaval" ]
}

summary

Lua's module management is very simple, making it easy to adopt.

Next time, I will introduce Hello World by LuneScript.