Logging via Script

User avatar
Oneymus
Posts: 321
Joined: Thu Sep 17, 2009 5:24 am

Logging via Script

Post by Oneymus »

I've been searching for some time, but haven't been able to find a solution.

I'd like to be able to start logging from a script, be it through Triggers or Aliases what-have-you. Perhaps I've missed the function somewhere? My research did turn up an old thread stating that "automatic logging" would definitely be a feature; has it yet to be implemented?

User avatar
Heiko
Site Admin
Posts: 1548
Joined: Wed Mar 11, 2009 6:26 pm

Re: Logging via Script

Post by Heiko »

Such a function has been requested before. It's on my todo list.

User avatar
Oneymus
Posts: 321
Joined: Thu Sep 17, 2009 5:24 am

Re: Logging via Script

Post by Oneymus »

With the release of 1.0, I thought this might be an appropriate time to ask about progress on exposing logging to scripting.

User avatar
Heiko
Site Admin
Posts: 1548
Joined: Wed Mar 11, 2009 6:26 pm

Re: Logging via Script

Post by Heiko »

It will be in 1.0.3.

User avatar
Oneymus
Posts: 321
Joined: Thu Sep 17, 2009 5:24 am

Re: Logging via Script

Post by Oneymus »

Awesome.

Thank you.

hempa
Posts: 48
Joined: Sat Jan 02, 2010 1:07 pm

Re: Logging via Script

Post by hempa »

Was this not added in 1.0.3 or am I just not finding it in the documentation?

Oh, and is there a way to list all global functions in mudlet somehow?

Iocun
Posts: 174
Joined: Wed Dec 02, 2009 1:45 am

Re: Logging via Script

Post by Iocun »

It was added, but you may be right that it isn't listed in the manual yet.
startLogging(true) starts the logging startLogging(false) stops it. It will always log to a file in the Mudlet home directory, and as far as I know there's currently no way to change that. If you want to log to somewhere else, you'll have to write your own function for it.
(E.g:
logfile = assert(io.open ("Your Desired Path and File Name","a"))
enableTrigger("log")

And a trigger named "log" that matches on every single line (^.*$) and does: logfile:write(line.."\n")

And finally a function to close the log:
logfile:close()
disableTrigger("log")
)

As for displaying all functions: Well, I don't know about restricting it to the predefined Mudlet functions, but since the global table _G holds all functions of Mudlet (predefined and the ones you defined) you can do it with something like:

Code: Select all

for k,v in pairs(_G) do
	if type(v) =="function" and not 
	(string.match(k,"^Trigger%d+$") or string.match(k,"^Alias%d+$") or string.match(k,"^Key%d+$") or string.match(k,"^Timer%d+$")) then
		echo(k.."\n")
	end
end
(That's just some really quick and dirty code, to go through _G, check whether something is a function, filter out your Aliases, Triggers, etc. and display the remaining ones.)


P.S. Quite an interesting thing to do, as I just noticed. I found some functions there that I had no clue existed.
Of course, it would also be nice to know what arguments those functions take and what they do...

User avatar
Vadi
Posts: 5035
Joined: Sat Mar 14, 2009 3:13 pm

Re: Logging via Script

Post by Vadi »

*cough* well check TLuaInterpreter.cpp for that. Let me know which ones are missing besides this one, I'll work on this in the weekend ;)

hempa
Posts: 48
Joined: Sat Jan 02, 2010 1:07 pm

Re: Logging via Script

Post by hempa »

Vadi,

Have you considered using Doxygen for documentation of the lua functions? As far as I know, as long as the doxygen comments are updated, you can have a function reference updated automatically with a short description for how it works. There are some examples for it here.

:)

User avatar
Vadi
Posts: 5035
Joined: Sat Mar 14, 2009 3:13 pm

Re: Logging via Script

Post by Vadi »

I know about it, but it looks too ugly. The source code isn't commented much anyway, and it wouldn't be integrated with the main part... so doesn't really help the resource problem in any way.

Post Reply