Small alias to execute lua code from the input line - import in, and do lua echo ("hi") for example. Can also display things with lua display(mytable) or lua mytable.
Note: this script is included by default with Mudlet now, you can use it as-is without installing!
Run Lua code from the command line
Run Lua code from the command line
- Attachments
-
- run-lua-code-v4.xml
- (548 Bytes) Downloaded 3762 times
Re: Execute Lua code from the input line
Nice...
Thank you for this great piece of code!
Thank you for this great piece of code!
Re: Run Lua code from the command line
Alias improved, now auto-displays if the function returned any results.
Re: Run Lua code from the command line
Fixed v2.
Re: Run Lua code from the command line
Updated to v4 - if a function returns 'false' as a result, it'll be displayed properly.
Re: Run Lua code from the command line
I use the following code - it's basically the same, except it allows multiple returns. IE, if you did lua getMainWindowSize(), this would return both the first and second values.
The reason for the exotic use of display is to tell it that it's already started... it's not at '0'. This allows it to display the first line on the same line as the A: or B: etc.
lua getMainWindowSize()
A: 1280
B: 633
Re: Run Lua code from the command line
Don't know if this will be of any use, but a more universal solution would be something like this:
Re: Run Lua code from the command line
Interesting - what is the pack() function doing with f()? Would not r = {f()} be more simple? I've long since modified my lua code alias to do that, just never updated this post...
Re: Run Lua code from the command line
Truth be told, it probably is. pack() was just a mental exercise in creating an inverse function to the unpack() function. ![Smile :-)](./images/smilies/icon_e_smile.gif)
![Smile :-)](./images/smilies/icon_e_smile.gif)
Re: Run Lua code from the command line
... I see. pack() is interesting, looks like it basically just wraps {} around the arguments, and throws in a key of 'n' equal to the number of arguments. I wonder how it compares speedwise to r = {f()}...