Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are
spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the
password reset link.
Due to spam on this forum, all posts now need moderator approval.
Entire forum
➜ MUSHclient
➜ Lua
➜ io.open error
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Rhien
(13 posts) Bio
|
Date
| Wed 20 Dec 2017 03:31 AM (UTC) Amended on Wed 20 Dec 2017 03:43 AM (UTC) by Rhien
|
Message
| I'm digging MushClient after a week.
I'm writing some Lua to log data out to a flat file and I'm running into an issue. I tried this code in a Lua IDE locally and it worked, in MushClient I get an error. In the IDE I set trigger text to something random.
The trigger returns %0 correctly as I want, the io.open tosses an error though which is also below.
local triggerText = "%0"
file = assert(io.open("C:\\Temp\\test.txt", "a"))
io.output(file)
io.write(os.date("%m/%d/%Y "))
io.write(triggerText)
io.close(file)
Run-time error
World: Mud
Immediate execution
[string "Trigger: "]:2: C:Temp est.txt: Invalid argument
stack traceback:
[C]: in function 'assert'
[string "Trigger: "]:2: in main chunk
Although not mentioned in the error, I have trusted all world in the global settings I have permissions to the folder in question. I've also tried the other append/write modes.
Any thoughts on what I'm missing?
Edit, but will leave for posterity -->
Got it working with this... The odd formatting of the file in the error seemed like it wasn't reading the escapes right.. went from 2 per slash to 4.. and it worked. I'm not sure why it needs 4, but it worked after.
file = assert(io.open("C:\\\\Temp\\\\test.txt", "a"))
| Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #1 on Wed 20 Dec 2017 05:31 AM (UTC) |
Message
| I was about to reply, but you worked it out. There are two levels of escaping of backslashes at work here. First the "send" box in a trigger lets you use backslashes so you have to escape them. Second, in Lua, you need to escape backslashes in a string literal. The upshot is that you need 4 backslashes to get one inside a string literal.
If you had used a script file (not "send to script") then the Lua code would have worked in the expected way (you only need 2 backslashes). |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #2 on Wed 20 Dec 2017 05:31 AM (UTC) |
Message
| I think you can get away with forward slashes in pathnames, which makes this particular problem go away. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Rhien
(13 posts) Bio
|
Date
| Reply #3 on Wed 20 Dec 2017 02:24 PM (UTC) |
Message
| Thank you for the explanation Nick, that makes perfect sense. | Top |
|
The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).
To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.
12,498 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top