Closed adrian-castravete closed 10 years ago
I believe you'd have to write it into a file first using the IO API.
Hello @SpiritedDusty ,
Thanks for the answer! Can you give me an example as to what is happening and how I should make it work?
Is it because the files aren't loaded as normal "text/lua" scripts are?
First you'd have to load the file from the server using XHR or something. Then you'd pass the file contents to Lua, where it will write it to a file. The file is stored in a temporary filesystem that gets erased after the page closes.
var xhr = new XMLHttpRequest();
// Send a GET request to get the file contents
xhr.open('GET', '/test.lua', true);
xhr.onreadystatechange = function() {
data = this.responseText;
// We now get the file contents and write it to a file
Lua.execute('h = io.open("/test.lua", "w") h:write(js.global.data) h:close');
// Now we can require it
Lua.execute('require("test")')
};
xhr.send();
Thank you very much, @SpiritedDusty ! :) Had a hunch there would be eval-like stuff.
Things are probably now as expected in c35388ef068e7d5acdfcd462bd58dbe20d7be095
Issue with lua modules and require.
First of all I'd like to say that this is an awesome project. The problem is I may be doing something wrong here, so please correct me if this is not the right way.
I have index.html the page from which I want to load (require) the test.lua module.
The problem is that I'm getting this output in chromium's Console. Which leads me to believe that requiring doesn't work exactly as it should. I have also tried to append to the
packages.path
variable with no luck. :(Am I doing something wrong?
For ease of access: