2013-10-28 19:13:01 +00:00
|
|
|
|
using System;
|
|
|
|
|
using LuaInterface;
|
|
|
|
|
|
|
|
|
|
namespace BizHawk.Client.Common
|
|
|
|
|
{
|
|
|
|
|
public class NamedLuaFunction
|
|
|
|
|
{
|
2013-10-28 20:57:25 +00:00
|
|
|
|
private readonly LuaFunction _function;
|
|
|
|
|
private readonly string _name;
|
|
|
|
|
private readonly string _event;
|
2013-11-10 19:19:58 +00:00
|
|
|
|
private readonly Action _action;
|
2013-12-30 01:58:44 +00:00
|
|
|
|
|
2013-11-26 01:21:24 +00:00
|
|
|
|
public NamedLuaFunction(LuaFunction function, string theevent, Action<string> logCallback, Lua lua, string name = null)
|
2013-10-28 19:13:01 +00:00
|
|
|
|
{
|
|
|
|
|
_function = function;
|
2013-10-31 16:58:56 +00:00
|
|
|
|
_name = name ?? "Anonymous";
|
2013-10-28 19:13:01 +00:00
|
|
|
|
_event = theevent;
|
2013-11-26 01:21:24 +00:00
|
|
|
|
Lua = lua;
|
|
|
|
|
Guid = Guid.NewGuid();
|
2013-11-10 19:19:58 +00:00
|
|
|
|
|
2013-11-26 01:21:24 +00:00
|
|
|
|
_action = delegate
|
2013-11-10 19:19:58 +00:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_function.Call();
|
|
|
|
|
}
|
|
|
|
|
catch (SystemException ex)
|
|
|
|
|
{
|
|
|
|
|
logCallback(
|
|
|
|
|
"error running function attached by the event " +
|
|
|
|
|
_event +
|
|
|
|
|
"\nError message: " +
|
|
|
|
|
ex.Message
|
|
|
|
|
);
|
|
|
|
|
}
|
2013-11-26 01:21:24 +00:00
|
|
|
|
};
|
2013-10-28 19:13:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-11-26 01:21:24 +00:00
|
|
|
|
public Guid Guid { get; private set; }
|
2013-10-28 19:13:01 +00:00
|
|
|
|
|
|
|
|
|
public void Call(string name = null)
|
|
|
|
|
{
|
|
|
|
|
_function.Call(name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string Name
|
|
|
|
|
{
|
|
|
|
|
get { return _name; }
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-26 01:21:24 +00:00
|
|
|
|
public Lua Lua { get; private set; }
|
|
|
|
|
|
2013-10-28 19:13:01 +00:00
|
|
|
|
public string Event
|
|
|
|
|
{
|
|
|
|
|
get { return _event; }
|
|
|
|
|
}
|
2013-11-10 19:19:58 +00:00
|
|
|
|
|
|
|
|
|
public Action Callback
|
|
|
|
|
{
|
|
|
|
|
get { return _action; }
|
|
|
|
|
}
|
2013-10-28 19:13:01 +00:00
|
|
|
|
}
|
|
|
|
|
}
|