[Plugin] C# API to Lua wrapper

Added by Per Amundsen 19 days ago

This is just a test to allow using Lua to listen/respond to AdiIRC API events.

Uses NLua to provide .NET Lua support.


Download and unpack the attached to the $adiircdir\Plugins folder.
Open Plugins Dialog and load LuaWrapper.dll.


Put the lua files in the $adiircdir\Plugins\lua folder, file extension must end with .lua, the plugin monitors and updates the folder in real time.

The plugin will call all lua files with the function name matching the API call e.g OnJoin() (Use plugin docs as reference)

To eat the text or eat the entire event, use EatData.EatNone, EatData.EatText, EatData.EatAll as the return value in the function.

Properties for all objects needs more testing.

Feel free to use/edit/distribute the wrapper, it's public domain.

Global Variables

These variables is always available to the script.

plugin - The c# plugin.
myHost - The plugin host API.
myTools - The plugin tools API.
scriptFile - Full path to the Lua file.

Event Variables

Available variables will be in camelCase version from the docs e.g Server is server, QuitMessage is quitMessage, if unsure just check the LuaWrapper source code.

These variables will have a value or NULL depending on the event called.

server - IServer
channel - IChannel
user - IUser
window - object, can be either IServer, IChannel, IUser or ICustomWindow.
quitMessage - string.
partMessage - string.
newNick - string.
mode - string.
message - string.
kickReason - string.
newTopic - string.
notice - string.
data - string.
byUser - string
editbox - IEditbox
bytes - byte[]. (Not tested)
menuItems ToolstripMenuItems[] array. (Not tested)
keyPressEventArgs - KeyPressEventArgs.


For some reason functions calls for IPluginHost/IServer/IChannel etc doesn't work, and using them as parameters doesn't seem to work either, so some global functions with object as parameter is provided to replace them.

Properties seems to work well though.

bool NotifyUser(object window, string text);
string Evaluate(object window, string script, string args);
bool HookCommand(string command, string syntax, string description)
bool UnHookCommand(string command)
bool SendCommand(object window, string command, string args)
bool SendFakeRaw(object window, string data)
bool SendRaw(object window, string data)
bool SendRawData(object window, byte[] data)
IChannel FindChannel(IServer server, string name)
IUser FindUser(IServer server, string nick)


-- set a global variable
joined = 0;

function OnJoin()
  -- print a message to the server window.
  NotifyUser(server, user.Nick .. " just joined " .. channel.Name);

  -- don't do anything to the original message.
  return EatData.EatNone;

function OnPart() 
  -- eat/hide the part message..
  return EatData.EatText;

function OnUserJoin()
  -- update the global variable.
  joined = joined + 1;

  -- print number of times joined a channel while the script was running.
  NotifyUser(server, "I have joined a channel " .. joined .. " times");

function OnLoad()
  -- print a message when the script is loaded.
  NotifyUser(myHost.ActiveWindow, "Loaded script " .. scriptFile);

  -- add a hook for the command /testlua
  HookCommand("/testlua", "/testlua", "Command for testing HookCommand from Lua");

  -- add a hook for the command /testeval
  HookCommand("/testeval", "/testeval", "Command for testing msl evaluation from Lua");

  -- add a hook for the command /listnicks
  HookCommand("/listnicks", "/listnicks", "Command for testing list enumeration");

  -- add a hook for the command /testcmd
  HookCommand("/testcmd", "/testcmd", "Command for testing sending commands");

function OnUnLoad() {
  -- unhook the commands

  -- print a message when the script is unloaded.
  NotifyUser(myHost.ActiveWindow, "Unloaded script " .. scriptFile);  

function OnCommand()
  if command == "/testlua" then

    -- if the typed command was /testlua, print a message.
    myHost.NotifyUser(window, "You typed /testlua " .. args);

  elseif command == "/testeval" then

    -- if the typed command was /testeval, try to evaluate "$me" 
    NotifyUser(window, "$me evaluates to " .. Evaluate(myHost.ActiveWindow, "$me", ""));

  elseif command == "/listnicks" then

    -- if the typed command was /listnicks, print all nicks in the channel
    local it = window.GetUsers:GetEnumerator()
    while it:MoveNext() do
      NotifyUser(myHost.ActiveWindow, it.Current.Nick);

  elseif command == "/testcmd" then

    -- send a "/echo -ag Hello world" command to the active window.
    SendCommand(myHost.ActiveWindow, "/echo", "-ag Hello World");



  • v1.0
    Initial release