|
apriebe Newbie
Joined: 03 Dec 2011 Posts: 4
|
Posted: Sat Dec 03, 2011 12:45 am
Converting Plugin to CMUD |
Hi everyone,
I have a plugin from MUSHclient that I would really like to convert to CMUD so the rest of my order can use the functionality as well. I have read through the documentation and tried a number of tests, and am now wondering if it possible without reworking the script entirely.
The original script is in programmed in Lua, and what I am wondering is if there is some way to load the script and then create triggers and aliases that use functions in the script instead of recreating those functions inside the value portion of any given trigger/alias/variable. At the moment I am using a module and am able to load the script via an alias, is there a better way to do this? Then my only job is to replace mush specific commands with cmud equivalents, for example
Code: |
if CLIENT_TYPE == MUSH then
Execute("blah")
elseif CLIENT_TYPE == CMUD then
zs.send("blah")
else end
|
Thanks for the help! |
|
|
|
MattLofton GURU
Joined: 23 Dec 2000 Posts: 4834 Location: USA
|
Posted: Sat Dec 03, 2011 2:03 am |
Provide examples. Your explanation isn't making any sense for the following reasons:
1)scripts in CMud are already loaded as soon as the session is open. There ARE ways to load in scripts at other times, but they are less efficient.
2)the value (ie, stuff executed) portion of any given trigger/alias is the function. You can use #CALL @userfunction() if you want to centralize code, but if that one trigger is the only place it occurs then there's no reason to create a user function. |
|
_________________ EDIT: I didn't like my old signature |
|
|
|
apriebe Newbie
Joined: 03 Dec 2011 Posts: 4
|
Posted: Sat Dec 03, 2011 2:29 am |
I guess my question then would be, where do I put my script so it are loaded when the session opens? I would like it if I could include my script directly in my module's XML, but it keeps rejecting my attempts to do so.
The second part I have figured out. I was trying to create aliases in cmud that called functions inside my script (which is loaded by an alias at the moment because I am not sure how else to do it). The solution was to use zs.make* inside the script, then it is trivial to call the functions inside the script.
If you have any insights into where I should have my script so it is automatically loaded, that would be excellent. |
|
|
|
Anaristos Sorcerer
Joined: 17 Jul 2007 Posts: 821 Location: California
|
Posted: Sat Dec 03, 2011 2:48 am |
At the present there is no plugin interface for CMUD, per se. However, you can build the functionality of the MUSH plugin via internal script(s) and then activate the resulting "plugin" via the onLoad event. Plugins are, by definition, external to the client framework and need not be part of the internal script set. MUSH provides a native plugin interface which is presently lacking in CMUD. However, because CMUD exposes a server interface via COM, non-resident applications can behave as plugins by injecting data into the client and activating (i.e. running) scripts as if the requests had come from the keyboard.
EDIT: What I do in cases when I use Lua, is add code to my onLoad event to fetch (and initialize) the environment I require:
Code: |
-- Using Lua...
--
f, errors = assert(loadfile(<path_to_my_Lua_script_file)) -- The assert insures that Lua finds no parsing errors.
--
f() -- Force Lua to covert the parsed input stream (a string) into discrete scripts.
--
-- If the assert or loadfile fails errors will contain the error message...
|
Once you do this, all the scripts residing in the file will be accessible via script. |
|
_________________ Sic itur ad astra. |
|
|
|
apriebe Newbie
Joined: 03 Dec 2011 Posts: 4
|
Posted: Sat Dec 03, 2011 6:41 pm |
The onLoad event is just what I was looking forward, in fact I hadn't even looked into events so this takes care of a big problem. One annoyance I am having is with what appears to be the lack of documentation for Lua. In particular, what are all the available property names that can be set for Variables/Triggers/Aliases? I am trying to use zs.maketrigger to make a telnet trigger that is based on telnet option 69, but guess the correct property name. Does such a list exist somewhere, because it certainly isn't in the documentation.
|
|
|
|
Daern Sorcerer
Joined: 15 Apr 2011 Posts: 809
|
Posted: Sat Dec 03, 2011 6:47 pm |
I made a trigger of that type, and this is what you get when you export to xml:
Code: |
<?xml version="1.0" encoding="ISO-8859-1" ?>
<cmud>
<trigger type="Telnet" param="69" priority="33840" copy="yes">
<pattern></pattern>
<value></value>
</trigger>
</cmud> |
So, I would try type="Telnet", param=69 in your maketrigger. Just a guess. |
|
|
|
apriebe Newbie
Joined: 03 Dec 2011 Posts: 4
|
Posted: Sat Dec 03, 2011 6:55 pm |
That was how I first tried doing it and you would think that it may be backwards compatible that way, unfortunately it is not. I know alarms use the 'isalarm=true' syntax, so I tried the same with telnet... all it produces is a blank pattern trigger. Any more ideas?
|
|
|
|
|
|