problem opening relative path files while the "Add Plugin" dialog is open

Posted by Fiendish on Sun 12 Dec 2010 04:52 AM — 2 posts, 7,856 views.

USA Global Moderator #0
Here's an interesting scenario...

I just recently added the ability to log chats to a file in my channel capture plugin, and I noticed something weird that happened today. If a chat comes through, and the plugin subsequently tries to log the chat to a file, while I have the Add Plugin dialog open, the file open operation fails if you use GetInfo(58) (the logs directory path) if it is defined as a relative path.

Here's the error:
Run-time error
Plugin: Aardwolf_Chat_Capture_Miniwindow (called from world: Aardwolf)
Function/Sub: OnPluginBroadcast called by Plugin Aardwolf_Chat_Capture_Miniwindow
Reason: Executing plugin Aardwolf_Chat_Capture_Miniwindow sub OnPluginBroadcast
[string "Plugin"]:490: .\logs\AardwolfChatLog.txt: No such file or directory
stack traceback:
        [C]: in function 'assert'
        [string "Plugin"]:490: in function 'stampAndStore'
        [string "Plugin"]:556: in function <[string "Plugin"]:546>
Error context in script:
 486 :     if (log_to_file == 1) then
 487 :         if (log_colour_codes == 0) then
 488 :             log_text = strip_colours(log_text)
 489 :         end
 490*:         local f = assert(io.open (GetInfo(58)..GetInfo(2).."ChatLog.txt", "a+")) -- handle to chat log file
 491 :         f:write (log_text.."\n") -- write to it
 492 :         f:close ()  -- close that file now
 493 :     end
 494 : 


I seem to have fixed it by replacing GetInfo(58) with
GetInfo(58):gsub("^\.\",GetInfo(56)) to construct an absolute path.
Australia Forum Administrator #1
I hate relative paths with a bit of a passion, as far as MUSHclient goes, because the question is "relative to what"?

It's one thing to be in a shell (eg. in Linux or DOS) and then say "cd foo" because you know it is "foo" relative to where you currently are, which hopefully you know.

But in MUSHclient, the current directory can be a bit fluid. Is it the starting directory? The executable directory? It can change if you script in a ChangeDir function call (as it is designed to do). And it can change if you use the file picker, and change directories.

So, you are basically better off using absolute paths.