ILua scripting

by Unknown

Back to Project L.

Theomar2007-05-23 00:50:45
Ooooh, that helped a bunch. Thanks much. smile.gif
Theomar2007-05-23 01:37:17
Actually, I just realized that I don't understand how to properly use the regex library.

So far, I have:
CODE
rex = require("rex_pcre")


And I put the 4 .dlls in the LMTS file where I have the file that uses it (triggers.lua).

I am getting this:
QUOTE

: error loading module 'rex_pcre' from file '.\\rex_pcre.dll':
One of the library files needed to run this application cannot be found.

Traceback:
:-1: in a C function
:-1: in function 'require'
triggers.lua:2: in main chunk
: triggers.lua: error loading module 'rex_pcre' from file '.\\rex_pcre.dll':
One of the library files needed to run this application cannot be found.


I honestly have no idea what I'm doing wrong.
Unknown2007-05-23 10:54:07
Make a copy of lua51.dll and name it lua5.1.dll. MudBot needs the former and rex_pcre.dll needs the latter.
Theomar2007-05-23 13:53:06
That worked, but also it seems that I am using a later version, as "newPCRE" and "newPOSIX" were replaced by "new".

Yay for figuring things out on my own.

Edit: Hrm, I can't seem how to figure out how to do simple substitutions, because mb.line is read only, and the only way I can think of doing a sub would be changing mb.line. Also, if you're going to do normal pattern matching in the new version, it's:
CODE
rex = require "rex_pcre"
if (rex.find(mb.line, "(.*)world(.*)")) then
    echo("Hello World!")
    return true
end
Unknown2007-05-23 15:27:44
Thanks for the heads up on that new version. As for substitution, use the replace() function.
Theomar2007-05-23 16:21:38
Hrm. Is there a list of all the functions ILua has? I checked the Wiki Zarquan posted, but I can't seem to find any list.

Thanks for the replace().
Unknown2007-05-23 17:10:46
Taken from a comment in the C code:

CODE
/*
* mb =
* {
*    version = "M.m"
*    
*    -- Callbacks
*    unload = nil,
*    server_line = nil,
*    server_prompt = nil,
*    client_aliases = nil,
*    
*    -- Communication
*    echo
*    send
*    debug
*    prefix
*    suffix
*    insert
*    replace
*    show_prompt
*    
*    -- Utility
*    cmp
*    
*    -- MXP / not implemented
*    
*    -- Timers
*    add_timer
*    del_timer
*    
*    -- Networking / not implemented
*    
*    -- LINE structure
*    line
*    raw_line
*    ending
*    len
*    raw_len
*    
*    gag_line
*    gag_ending
* }
*
*/


I don't use all of these callbacks and functions myself, but I have used gag_line, gag_ending, line, echo, echop, send, add_timer, server_line, server_prompt, and client_aliases. If you have a question about the syntax (some are straightforward enough), ask and I'll look it up for you, maybe even give an example Lua snippet.
Theomar2007-05-23 17:19:14
That's exactly what I was looking for.

Thanks CroX and Zarquan.
Theomar2007-05-24 22:23:32
Actually, I was wondering if there was any way to do echos/prefixs/suffixs/etc in different colors?
Unknown2007-05-25 01:07:59
Yes. You might have noticed the "C.x" and such in my prompt script. The "C" table is the ANSI color codes table. The C.x is a special one that resets the colors back to ANSI default, and then there's ones like C.r (dark red) or C.R (bright red) and so on. I don't have the color codes here offhand, and I've added background color codes to my own LMTS, which I haven't committed to SourceForge yet. When I get the codes, I'll post them, unless CroX does it first.
Theomar2007-05-25 02:16:36
Oooo, I wondered what the C was. I didn't read the prompt script as carefully as I thought I did.

Thanks.

Edit: Actually, I've noticed something. Once in a while, the colors seem to bleed over. Just now, I used the code:
CODE
if (input == "test123") then
    echo(C.R.."Test Complete... Hello World!")
    return true
end


And it worked, but the next line of text Lusternia sent, "Your sense of smell is assaulted by a pile of steaming dung," was in the same red as the "Test Complete... Hello World!" message.

Also, if anyone every plans to create a system, I offer my services in any way I can. I'm actually planning on making my own, but I seem to lack all the trigger messages. So, if anyone wants to contribute (preferably in a zMud format), I'd be very grateful.
Unknown2007-05-25 11:28:04
The bleeding is what the C.x is there to prevent. Put a ..C.x at the end of your echo and that'll clear it right up!
Theomar2007-05-25 14:53:09
Now I feel stupid.

Gracias.
Theomar2007-05-25 17:46:22
Bleh. I hate double posting like this, but has anyone else noticed that once in a while, the "return true" line in aliases that make it not send the input to Lusternia stop working?

I have no idea why it does that; it seems random to me. Anyone else have this problem?
Unknown2007-05-25 20:06:30
I do not have this problem. Perhaps you've got some small typo in the code?
Theomar2007-05-26 02:37:35
I thought so too, but it does that for every single alias that I don't want the text I typed sent, such as "gc" for "get target." I'll just do my best to see when it changes over.
Xinael2007-05-26 06:25:55
Is there any documentation for the rex_pcre library? I remember reading about it somewhere but can't find it now, and it's going to be pretty important if I want to actually do anything with this.

Edit: I found some documentation in the MUSHClient help files, for the interested.

Another Edit: Pondering other ways to handle trigger matches, especially with pcre. How about something like this?

CODE
-- rex table, key = id, val = compiled rex.
trig_rex={}

-- trigger command table, key = id, val = func
trig_func={}

-- trigger event handler
mb.server_line  =   function ()
                        for id in pairs(trig_rex) do
                            local match
                            _, _, match = id:match(mb.line)
                            if match then
                                trig_func(match)
                            end
                        end
                    end

Might have to be trig_rex:match(mb.line) rather than id:match(mb.line), I haven't checked.
Unknown2007-05-26 11:25:19
The original source for the documentation, which is really just a listing of the functions and parameters, can be found on the LuaForge site for lrexlib... http://lrexlib.luaforge.net/

That's a nice little script idea, Xinael. I've been meaning to find a way to do something like that myself, but just haven't had the time, so thanks for posting it!

Theomar, if you e-mail me your script/config, I can see if maybe I can find the problem for you.
Xinael2007-05-26 15:15:08
Here's a simple alias one too. It'd probably be better to have the alias table work like my trigger table (which is now a single table where keys = ids and vals = another table. The val table has three keys, "rex", "func" and "disabled", which I think are pretty self-explanatory) and have a list of compiled rexes with associated functions. But since most aliases are in the format command-word param1 param2 ... this method works just as well. You'll need to write a separate (additional?) rex handler if you want to do funky things like echoing something on any line containing the word "nipple".

CODE
-- alias table. Keys are command words (first word of input), values are functions that take an array of parameters.
-- The array of parameters has two special elements. -1 is entire input line that matched the alias. 0 is the alias' command word.
alias = {}

function mb.client_aliases (input)
    local i, params = 0, {}
    for match in string.gmatch(input,"%S+")
        params=match
        i=i+1
    end
    if alias] then
        params = input
        alias](params)
        return true
    else
        return false
    end
end


Also, how do add_ and del_timer work? And what on earth is cmp?
Xinael2007-05-26 19:09:44
I'm feeling really thick now. No matter what I do, ILua doesn't actually affect any input/output. I've tried using the prompt example from the first page and one of the examples from the wiki page. `il mods shows the "cool" module as loaded, but the xp never appears on my prompt. Any ideas?