Skip to content
This repository has been archived by the owner on Dec 17, 2018. It is now read-only.

How to load my Lua from a script tag with a src attribute?

daurnimator edited this page Apr 21, 2016 · 2 revisions

Sadly <script type="text/lua" src="/static/mycode.lua"></script> cannot be supported, as browsers always interpret the content as Javascript.

Instead, use lua.vm.js' built in HTTP searcher for require. As in normal lua, . will be converted into /, and .lua will be appended. So to run the code at relative HTTP url /static/mycode.lua, insert into the page:

<script type="text/lua">
  require ".static.mycode"
</script>

You can also use an absolute URL:

<script type="text/lua">
  require "http://example.com/static/mycode"
</script>

Credit.

Clone this wiki locally