io operations using lua.vm.js in nodewebkit


I am using the npm package lua.vm.js to execute some pre-existing lua code in my node webkit based app (nw).

The file newtest.lua contains:

local myFile, err ='/tmp/file.txt')
theContent ='*all')

In my javascript code I am doing:

var fs = require('fs');
theFileContent = fs.readFileSync("./newtest.lua", "utf8");
var LuaVM = require('lua.vm.js');
var l = new LuaVM.Lua.State();

If I simply execute:

lua newtest.lua

as expected, I get the content of '/tmp/file.txt' printed on the console.

But If I run the same code from the nw-based app, I don't get anything: nothing on the output console and not even the global variable theContent set to the right value

myFile is nil and err is /tmp/file.txt: No such file or directory

But the file is right there.

I am starting to think that the lua code executed by lua.vm.js does not allow io operations. Any idea?

UPDATE I tried to run a simple node app (removing nodewebkit from the picture). This is the example.js I am running

By : magopieri


As I answered over at :

lua.vm.js virtualises IO into an in memory virtual file system (using emscripten) This is because it's primarily targeted at the browser, where real IO doesn't exist.

If you're running in node, you can use the node file functions:

local file ="fs":open("/tmp/file.txt")

This video can help you solving your question :)
By: admin