4 ms·
Technically yes, but it would likely only be possible with a restricted subset of the language. Python and Ruby have a large standard library and set of built-
by nilved 13y ago
Technically yes, but it would likely only be possible with a restricted subset of the language. Python and Ruby have a large standard library and set of built-in functions, because they're "batteries included" languages. Lua is quite the opposite: it doesn't even have access to the file system unless you implement that or use a module. So you'd either end up using a limited Python without features absent in Lua, or you'd need to bridge the gap in functionality with a very large runtime library.
If you're looking for a more expressive syntax, check out MoonScript. It's an awesome language that you could consider Lua's CoffeeScript analogue.
- tzs 13y agoAren't a large part of the Python and Ruby standard libraries written IN Python and Ruby, respectively? That should greatly reduce the amount of work.
- deleted 13y ago[deleted]
- kodablah 13y agoLua does have file system access: http://www.lua.org/manual/5.2/manual.html#6.8 http://www.lua.org/manual/5.2/manual.html#6.8
- spc476 13y agoIn that it can open files. It does not, however, have a way to enumerate files in a given directory---that requires a module to handle.
- kodablah 13y agoAh, true. Penlight helps, but you are correct it is a separate module. I think for being the target of a higher-level language it might help that you aren't married to a standard library.
- jekub 13y agoI fully agree with you but just want to add that you can do it in "pure" Lua : for file in io.popen("ls "..dir):lines() do ... end This should never be used in real applications and a proper filesystem module should be used instead. But, I find it very useful for quick one-shot scripts I write for batch processing some files.
- silentbicycle 13y agoLua has access to the filesystem, but you probably want the luafilesystem module for general scripting, it provides more POSIX and Windows-specific functionality. As a general rule, the Lua standard library only includes what can be portably built on the C standard library. Instead of "batteries included", Lua is small and portable everywhere ("travel light"), and makes it easy to wrap other functionality via the C API. Sometimes that's a problem, but sometimes it's exactly what you want - say, when Python would be too big a dependency, Lua is an excellent option. (No experience with MoonScript. I'm content with Lua's syntax. I much prefer it to Ruby's, for example.)