Get back the output of os.execute in Lua

If you have io.popen, then this is what I use: function os.capture(cmd, raw) local f = assert(io.popen(cmd, ‘r’)) local s = assert(f:read(‘*a’)) f:close() if raw then return s end s = string.gsub(s, ‘^%s+’, ”) s = string.gsub(s, ‘%s+$’, ”) s = string.gsub(s, ‘[\n\r]+’, ‘ ‘) return s end If you don’t have io.popen, then presumably … Read more

How can I embed Lua in Java?

LuaJ is easy to embed in Java. I did have to change a few lines of their source to get it to work how I expected (it didn’t require the IO library automatically). http://sourceforge.net/projects/luaj/

What does # mean in Lua?

That is the length operator: The length operator is denoted by the unary operator #. The length of a string is its number of bytes (that is, the usual meaning of string length when each character is one byte). The length of a table t is defined to be any integer index n such that … Read more

Load Lua-files by relative path

There is a way of deducing the “local path” of a file (more concretely, the string that was used to load the file). If you are requiring a file inside lib.foo.bar, you might be doing something like this: require ‘lib.foo.bar’ Then you can get the path to the file as the first element (and only) … Read more