So, I know that these functions can be given either strings to compile and execute, or a premade function (or a function created dynamically). In terms of performance and memory usage, is one preferable to another?
Specifically, if I want to call a function and pass it information from the calling function after the timer or trigger has fired, what would be the best method to use?
An example would be appreciated.
Temp Timer and Temp Trigger Question
Re: Temp Timer and Temp Trigger Question
I would go with the closures. They are much cleaner and simpler to use, and going with strings you'll be losing out time on string concatenation and globals lookup after.
That said, I haven't benchmarked it, but I believe the differences are not that big to go with the inconvenient way.
That said, I haven't benchmarked it, but I believe the differences are not that big to go with the inconvenient way.
Re: Temp Timer and Temp Trigger Question
Thanks Vadi. Obviously when using functions that don't need arguments, using predefined functions seems ideal. Is there any way to pass arguments to functions when using these?
Re: Temp Timer and Temp Trigger Question
Not by giving the function to tempTimer directly, but you can with the usual string method -
Re: Temp Timer and Temp Trigger Question
Right, well I knew about that one. Thanks Vadi.
Re: Temp Timer and Temp Trigger Question
or perhaps wrap it in an anonymous function
Re: Temp Timer and Temp Trigger Question
That would certainly work better for passing table variables. Thanks.
Re: Temp Timer and Temp Trigger Question
Mudlet does *NOT* support function parameters neither in tempTimers nor tempTriggers. A long time ago I added code to test support for function parameters for tempTimers but no code to clean up the memory when the timer gets killed. Consequently, using a function parameter causes a memory leak. The reason why I opted against adding a function parameters feature for this type of functions is because it imho slows down the client unnecessarily because we have to call into Lua again and clean up the timer info before the timer object gets destroyed. As I've added other "slow-but-useful" stuff since then I'm open for a feature discussion.Jor'Mox wrote:So, I know that these functions can be given either strings to compile and execute, or a premade function (or a function created dynamically). In terms of performance and memory usage, is one preferable to another?
Re: Temp Timer and Temp Trigger Question
Honestly, I was hoping to be able to pass arguments directly, rather than using some of the other methods suggested, so as to avoid the current memory leak associated with using tempTriggers and tempTimers, in that the functions that they generate are never removed from memory, remaining stored in the global variables associated with them, even once the timer or trigger is destroyed. I.E. if I make a tempTimer, and it has ID# 5, then Timer5 becomes a new variable in the global name space, and stores the resulting function, and it isn't cleared after the timer fires and is removed.
Note: More thorough testing reveals this only happens when timers and/or triggers are passed code to execute as a string. Passing a function, even an anonymous function, does not result in persistent storage problems. Though, even with nothing referencing them, the ID number remains "taken" and will not be reused, which seems less than ideal, but not hugely problematic.
As an aside, it would also be nice if other function invoking functions, like setLabelClickCallback allowed for similar syntax.
Note: More thorough testing reveals this only happens when timers and/or triggers are passed code to execute as a string. Passing a function, even an anonymous function, does not result in persistent storage problems. Though, even with nothing referencing them, the ID number remains "taken" and will not be reused, which seems less than ideal, but not hugely problematic.
As an aside, it would also be nice if other function invoking functions, like setLabelClickCallback allowed for similar syntax.