BOOTLJ(1) General Commands Manual BOOTLJ(1)

bootlj - portable luajit script bootloader

bootlj [-J passopt... -J] [args...]
 

	- dir1 -+- bootlj
	        +- main.lua	( require("myutil") )
	        +- myutil.lua
	---
	dir1 $ ./bootlj -h	#>> luajit -- main.lua -h
	dir1 $ cd ..
	     $ ./dir1/bootlj	#>> run ./dir1/main.lua
	     $ cd dir1
	dir1 $ rm main.lua
	dir1 $ ./bootlj	#>> main.lua not found
	
	(make symbolic link to dir1/bootlj at /usr/bin etc)
	
	home $ bootlj	#>> run main.lua

-J passopt... -J
pass opt to luajit vm. ~$ luajit passopt...

bootlj is a wrapper of luajit runner with the followingfeatures:
 
- exec `main.lua` in the same directory - add the bootlj exist dirpath to package.path and cpath - add useful global vars   * FULL_BOOTFILE (fullpath filename, /home/abc/bootlj etc)   * BASE_BOOTFILE (filename: bootlj etc, no dirpath)   * FULL_BOOTDIR (fullpath dirname, c:\home\dir etc.)   * FULL_CWD (fullpath cwd, /home/now etc)   * DIRSEP (directory sepstr, win==\, other==/ etc)
 
this feature makes your app package portable, directory == app. lua and luajit path/cpath dont have bootfile exist dirpath so causes the path search problem. bootlj resolves it.
	- dir1 -+- src.lua ( require("myutil") )
	        +- myutil.lua
	
	dir1$ luajit src.lua	#>> work
	dir1$ cd ../
	    $ luajit ./dir1/src.lua	#>> misses myutil.lua
 
the best practice for making your luajit code portable is:
-
use require("foo") for import foo.lua. loaded from the appdir or other path
-
use package.searchpath("myutil", package.cpath) and ffi.load(rtnstr) to load libmyutil.so etc.
-
use ffi.load("directX") to load major library, libdirectX.so etc
-
use ffi.C.printf() if use standard C-lib funcs
-
place every related files(*.lua *.so *.dll) in a non-nested one directory.
dir1-+- bootlj
     +- main.lua
     +- main_impl.lua
     +- foo.lua
     +- tool.lua
     +- libmyutil.so
     +- xyz.dll
    
bootlj holds whole the orig-luajit vm. the below works almost the same.
	~$ ./bootlj -h
	~$ luajit -- main.lua -h
 
luajit vm accepts commandline options.(https://luajit.org/running.html) if you want to run luajit with its options, put between optsep str. default optsep is "-J".
 
	~$ ./bootlj -J -Ohotloop=10 -joff -J -h
	~$ luajit -Ohotloop=10 -joff -- main.lua -h
 
you can change bootfile name `main.lua` and optsep `-J` using libbootlj.a. see bootlj.h
 
//basic #include "bootlj.h" int main(int argc, char** argv){   return bootlj_main(argc, argv); } //~$ cc -Wall -pedantic -static -fPIC src.c libbootlj.a -ldl -lm //~$ ./a.out -J -Ohotloop=10 -J -h 
#include "bootlj.h" int main(int argc, char** argv){   return bootlj_main(argc, argv, "xyz.txt", "123"); } //~$ cc src.c libbootlj.a -ldl -lm //~$ ./a.out 123 -Ohotloop=10 123 -h #>> search xyz.txt and run

exit code depends on main.lua script and follows lua's method.
- rtn 1 if lj rtns nil/false/err at ag1. (lj)return nil >> $?=1
- rtn int if lj return num at ag1. (lj)return 8.2 >> $?=8
- rtn 1 if lj return other type at ag1. (lj)return "msg" >> $?=1
- emsg to stderr if err or str at ag2. (lj)return 0,"hw" >> $?=0 +"hw"
 

---concept
- make luacode/binary/library portable
- support to the powerful api, require()/ffi.load()
- files in the same directory *SHOULD* be searched/loaded

posix-2001+

Copyright 2020 momi-g, GPLv3+

2021-08-21

https://luajit.org/index.html
https://www.lua.org/manual/5.1/manual.html
 
luajit bases lua 5.1(+appropriate extented) syntax. avoid 5.2/5.3/5.4. orig-lua frequently changes syntax that ignores backwards compatibility like python2 >> 3, win7 >> 10, perl5 >> 6 etc. i recommend you to use luajit instead of orig-lua.