DarkWiiPlayer
DarkWiiPlayer

Reputation: 7064

Can I somehow set the script interpreter in Apache, as opposed to the start of the file?

I am having the following problem: When I want to run an uncompiled Lua script in Apache, I just add #!/usr/share/lua at the beginning of the file, so far everything works fine.

But if I want to compile it with luac to have it run a bit faster I cannot add any text to the file, as it is compiled binary data (which still needs to be interpreted by the Lua interpreter, and cannot be executed on its own).

Is there a way to tell Apache to always have /usr/share/lua interpret files with the .lua (or .luac to mark them as compiled) extension?

Upvotes: 0

Views: 102

Answers (1)

Adam B
Adam B

Reputation: 3833

I'm not aware of a way to do this as a CGI script, as the CGI spec basically requires that the shell can figure out how to run a file based on the hashbang at the beginning.

However, you could write a simple CGI handler in Lua that does a loadfile() on the .luac file and then executes it. You can set .luac files to be handled by this script with the following directives in a .htaccess or httpd.conf file:

# Files of a particular file extension
AddHandler my-file-type .xyz
Action my-file-type /cgi-bin/program.cgi

In this example from the docs, program.cgi would be passed the filename requested by the URL so you could parse it and run that file.

Upvotes: 1

Related Questions