I want to create web pages with dynamic content. I have an HTML page, and I want to call a lua script from it
How do I invoke the lua script?
<script type="text/application" >
?<script type="text/lua" >
?
Retrieve data from it? Can I do something like:
int xx = 0;
<script type=text/lua>
xx = 123;
</script>
and have any hope that xx
will be 123
when the script exits?
Replace the current web page with the content generated by the lua script.
To run a Lua scriptOpen the Lua Script Library through Prepare > Run Lua Script. Use the appearing dialog to load, save, and execute Lua scripts as well as to create new ones. Select the script to be run. Click Execute Script.
if your source to be executed is src/main. lua . Then hit F5 or "Run"->"Start Debugging", select the lauch configuration and happy debugging. Please do not try to build it, simply load it in VS Code and debug it!
lua file and automatically runs it on Notepad++ startup. You can easily edit this file via Plugins > LuaScript > Edit Startup Script . You can include any commands you want to immediately execute on program startup, as well as register any additional shortcuts or callbacks.
On the client-side, you can use:
Fengari and Moonshine execute compiled Lua bytecode. They are more compatible than lua.js, and have a lower code-size footprint than e.g. an Emscripten-compiled Lua interpreter. They may be the slowest method of all because they aren't using WASM/asm.js like the stock Lua interpreter compiled with Emscripten would, and they aren't generating JavaScript which could be subsequently JIT'ed.
I'd try using Fengari first as it seems to be most active. It has easier JS interop than something using WASM would have.
On the WWW scripts can run in two places.
If you want it to run in the browser, then you need support for the language built into the browser (or provided by an extension). For all practical purposes, if you are writing webpages for the WWW, then the only language you can use in an HTML <script>
is JavaScript.
If you want to run it on the web server, then you need to get your HTTPD to run the script in response to a URL being requested from it. The simplest way to achieve this is via CGI.
With CGI, the HTTPD will run a program (as a separate process) in response to the request being made. It will pass in various information about the request via STDIN and environment variables (as described in the CGI specification). The script then prints an HTTP response (header (at least a Content-Type) and body (e.g. an HTML document)) and sends it to STDOUT where the HTTPD picks it up and sends it back to the browser.
How you configure your server to run programs using CGI depends on the server. Apache has a guide for their server.
There are probably CGI libraries for Lua, but I don't know the language so cannot make any recommendations.
CGI is a slow and inefficient protocol (as it requires a new processes to be spawned for each request). There are alternatives, such as FastCGI and various language specific options. Again, I don't know what is considered optimal in Lua land.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With