mirror of
https://github.com/tym1116/BH3.git
synced 2025-12-18 17:34:45 +01:00
74 lines
1.3 KiB
C#
74 lines
1.3 KiB
C#
using System;
|
|
|
|
namespace LuaInterface
|
|
{
|
|
public class LuaFunction : LuaBase
|
|
{
|
|
internal LuaCSFunction function;
|
|
|
|
public LuaFunction(int reference, LuaState interpreter)
|
|
{
|
|
_Reference = reference;
|
|
function = null;
|
|
_Interpreter = interpreter;
|
|
}
|
|
|
|
public LuaFunction(LuaCSFunction function, LuaState interpreter)
|
|
{
|
|
_Reference = 0;
|
|
this.function = function;
|
|
_Interpreter = interpreter;
|
|
}
|
|
|
|
internal object[] call(object[] args, Type[] returnTypes)
|
|
{
|
|
return _Interpreter.callFunction(this, args, returnTypes);
|
|
}
|
|
|
|
public object[] Call(params object[] args)
|
|
{
|
|
return _Interpreter.callFunction(this, args);
|
|
}
|
|
|
|
internal void push(IntPtr luaState)
|
|
{
|
|
if (_Reference != 0)
|
|
{
|
|
LuaDLL.lua_getref(luaState, _Reference);
|
|
}
|
|
else
|
|
{
|
|
_Interpreter.pushCSFunction(function);
|
|
}
|
|
}
|
|
|
|
public override string ToString()
|
|
{
|
|
return "function";
|
|
}
|
|
|
|
public override bool Equals(object o)
|
|
{
|
|
if (o is LuaFunction)
|
|
{
|
|
LuaFunction luaFunction = (LuaFunction)o;
|
|
if (_Reference != 0 && luaFunction._Reference != 0)
|
|
{
|
|
return _Interpreter.compareRef(luaFunction._Reference, _Reference);
|
|
}
|
|
return function == luaFunction.function;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public override int GetHashCode()
|
|
{
|
|
if (_Reference != 0)
|
|
{
|
|
return _Reference;
|
|
}
|
|
return function.GetHashCode();
|
|
}
|
|
}
|
|
}
|