lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

Hi all.

Do you know the filesystem binfmt_misc on Linux?

>From here:
we got a definition

"Binfmt_misc provides the ability to register additional binary formats to the Kernel without compiling an additional module/kernel. Therefore binfmt_misc needs to know magic numbers at the beginning or the filename extension of the binary."

With it, is possible to make this(suppose that you have a simple hello world in Lua..):

MCid299a:~$ luac -o hello hello.lua
MCid299a:~$ chmod +x hello
Hello world!

This is what I make just now :)

And now, the little HOWTO.

I'm assuming Debian, I don't know how another distros implements the configuration on binfmt (althoug I guess that is similar...)
I'm on Debian Unstable.

1- Create a file in /usr/share/binfmts called 'lua', with the contens below:

package lua
interpreter /usr/bin/lua
magic LuaP
offset 1

This assumes that you're using Lua5, cause in Lua 5, the magic word 'LuaP' is showed after the the 1st byte (the offset) in the bytecoded Lua file (just for the sake of curiosity, try to edit a lua bytecode in a editor!). is that magic word that binfmt uses to determine if a file is a lua bytecod or not.

2 - Run the commands:
update-binfmts -- import lua
update-binfmts -- enable lua

The first command install the lua script on /var/lib/binfmts
The second enables the binfmt to Lua

3- That's all!

You can do that to see if worked:

MCid299a:/proc/sys/fs/binfmt_misc# cat lua
interpreter /usr/bin/lua
offset 1
magic 4c756150

And now, you can create a Lua script (or compile one that you have), chmod it (+x) and run it.


I hope you like.

- Walter