Newb Lua Question

Posted by JoeScripter on Sun 05 Nov 2006 07:06 AM — 5 posts, 21,117 views.

#0
I'm brand new to Lua, and have written a simple function to load information from a file. It works when I run it from Crimson Editor but seems to fail if I try using the script file in MUSHclient.

The lines in question are:

[snip]
function loaddirs (file)
dirs = {}
io.input (file)
[/snip]

It fails on the io.input line with:
[string "Script file"]:3: attempt to index global `io' (a nil value)
stack traceback:
[string "Script file"]:3: in function `loaddirs'
[string "Script file"]:21: in main chunk

Can anyone help me as to why io isn't recognizable within my function in mushclient?
USA #1
File IO is disabled via the "Sandbox" in MUSHclient, look in the Global Options Dialog, from file menu, and it gives instructions on disabling it, or if it is a plugin, you can add it to the trusted list, or just that particular world file. There are many options to allow that to not be set to nil.

Hope that helps :)

Laterzzz,
Onoitsu2
#2
ah hah! That makes perfect sense now.. thank you!
Australia Forum Administrator #3
This seems to trap someone about once a week. How would this be? If instead of simply setting things like io to nil, the sandbox replaced them with a function to warn about the sandbox? Something like this:


/f = io.open ("foo", "r")

-->

Run-time error
World: SMAUG
Immediate execution
[string "Command line"]:1: Function 'io.open' disabled in Lua sandbox - see MUSHclient global preferences


This makes it clearer that the function is intentionally disabled, and how to go about fixing it.
#4
I think this would be an excellent change Nick! It stumped me until I found the Lua sandboxing section, then it all made sense.. giving someone a nudge in that direction may help for all those users who think they know everything and don't need to look at docs - like me! :)

p.s. It's long overdue, but I've just registered my copy of mushclient! After playing around and seeing how powerful Lua will allow my scripting to be, it seems like I've got a new (old?) project in automating my favorite mud :) Thanks again for such great software!