static void Register(ILuaEnvironment env, ILuaValue table, Delegate func, string name = null) { var funcValue = env.Runtime.CreateValue(func); var nameValue = env.Runtime.CreateValue(name ?? func.Method.Name); table.SetIndex(nameValue, funcValue); }
public static void Initialize(ILuaEnvironment E) { ILuaValue math = E.Runtime.CreateTable(); Register(E, math, (Func <double, double>)System.Math.Abs, "abs"); Register(E, math, (Func <double, double>)System.Math.Asin, "asin"); Register(E, math, (Func <double, double>)System.Math.Atan, "atan"); Register(E, math, (Func <double, double, double>)System.Math.Atan2, "atan2"); Register(E, math, (Func <double, double>)System.Math.Ceiling, "ceil"); Register(E, math, (Func <double, double>)System.Math.Cos, "cos"); Register(E, math, (Func <double, double>)System.Math.Cosh, "cosh"); Register(E, math, (Func <double, double>)deg); Register(E, math, (Func <double, double>)System.Math.Exp, "exp"); Register(E, math, (Func <double, double>)System.Math.Floor, "floor"); Register(E, math, (Func <double, double, double>)System.Math.IEEERemainder, "fmod"); Register(E, math, (Func <double, double[]>)frexp); math.SetIndex(E.Runtime.CreateValue("huge"), E.Runtime.CreateValue(double.PositiveInfinity)); Register(E, math, (Func <double, double, double>)ldexp); Register(E, math, (Func <double, double, double>)log); Register(E, math, (Func <double, double[], double>)max); Register(E, math, (Func <double, double[], double>)min); Register(E, math, (Func <double, double[]>)modf); math.SetIndex(E.Runtime.CreateValue("pi"), E.Runtime.CreateValue(System.Math.PI)); Register(E, math, (Func <double, double, double>)System.Math.Pow, "pow"); Register(E, math, (Func <double, double>)rad); Register(E, math, (Func <int?, int?, double>)random); Register(E, math, (Action <int>)randomseed); Register(E, math, (Func <double, double>)System.Math.Sin, "sin"); Register(E, math, (Func <double, double>)System.Math.Sinh, "sinh"); Register(E, math, (Func <double, double>)System.Math.Sqrt, "sqrt"); Register(E, math, (Func <double, double>)System.Math.Tan, "tan"); Register(E, math, (Func <double, double>)System.Math.Tanh, "tanh"); E.GlobalsTable.SetItemRaw(E.Runtime.CreateValue("math"), math); }
static void Register(ILuaEnvironment E, ILuaValue table, Delegate func, string name = null) { var funcValue = E.Runtime.CreateValue(func); var nameValue = E.Runtime.CreateValue(name ?? func.Method.Name); table.SetIndex(nameValue, funcValue); }