Moonscript uses \ to call methods so can someone explain to me why the code below does not work:
> file = io\open("mix.exs", "rb")
[string "tmp"]:1: calling 'open' on bad self (string expected, got table)
but when you call it to read the file it does ?
> file\read!
"Code.ensure_loaded?(Hex) and Hex.start
The
io.openfunction expects to get a string as the first argument butio\open(likeio:openin lua itself) is actually passing theiotable as the first argument. That is it is a method call.io\open("file", "mode")/io:open("file", "mode")are syntactic sugar forio.open(io, "file", "mode").This is why
file\read!works without an explicit argument becausefilegets passed as the first argument to theread("file", "format")function.