I'm having issues modularizing my lua scripts. I have a main script file, which calls my other script files (it calls system.lua, which has requires for all my other scripts). When the system is installed, it uses dofile() on various lua files which define triggers, aliases, timers, etc. Most of the time it works correctly. However, on triggers that have a script function reference (instead of using sendto.script) due to my wanting to have access to the styles, it tells me: Script name is not in the script file when I try to set the script function reference to a function in one of the other script files (a.k.a. calling prompt_capture in prompt.lua). I can use /prompt_capture and have it run the function, but it says it can't find it for the trigger. Any way around this?
Modularization Issues
Posted by Tichi on Thu 07 May 2009 06:04 AM — 6 posts, 24,965 views.
You can always use the XML <include> tag and save triggers and their needed scripts as an xml file instead of just as a lua file.
When setting up a file to be included just follow a slightly typical plugin format:
This will load it all into the main XML file using it as if it were hard coded in the file main one to begin with.
Since you're keeping the triggers with their necessary script functions, those errors will disappear.
I'm sure somebody will be able to elaborate a bit on my suggestion, this is just what I've made work for my own uses.
When setting up a file to be included just follow a slightly typical plugin format:
<muclient>
<triggers>
<trigger
blah blah blah>
</trigger>
</triggers>
<script>
</script>
</muclient>This will load it all into the main XML file using it as if it were hard coded in the file main one to begin with.
Since you're keeping the triggers with their necessary script functions, those errors will disappear.
I'm sure somebody will be able to elaborate a bit on my suggestion, this is just what I've made work for my own uses.
Well, my main issue is that I want to keep the scripts separate in their own files. Basically, my entire system is based off of the main system.lua. You have prompt.lua, stats.lua, etc. And each of these has a settings file (with triggers and what not) such as prompt_settings.lua. A trigger in prompt_settings has reference to prompt:capture, which is defined in prompt.lua as prompt:capture(name, line, wildcards, styles). Normally, I would just set the trigger to send-to script, and put the function in the send text - this works. However, I can't find any way to get a hold of the styles of the match if I do it that way. I tend to reuse quite a few of my scripts and functions, so defining them in the triggers file results in a lot of redundant code, which I'd prefer to avoid. Anyone have any ideas as to how to get around this issue efficiently?
Are you using prompt_capture or prompt:capture? I don't think the latter syntax works in the script field of a trigger or alias. You'd have to use the former and then call the latter inside, as a sort of redirection.
My system for Lusternia (http://larkin.dischai.googlepages.com/treant) is highly modularized and has no troubles with calling functions from other functions. I use the script field in only two or three places, though.
My system for Lusternia (http://larkin.dischai.googlepages.com/treant) is highly modularized and has no troubles with calling functions from other functions. I use the script field in only two or three places, though.
Yeah, I ended up making a trigger-redirecting function, since I don't plan to use many of the direct-function call triggers. Was just hoping there was a better way to do it, heh. Thanks guys.
Have you looked at the "require" function call? This loads a file once only, which sounds like what you are trying to do.