Example #1
0
        public override void Setup(IDictionary<string, object> table)
        {
            table.AddOrSet("config", ConfigStr);

            table.AddOrSet("cpath",
                Environment.GetEnvironmentVariable("LUA_CPATH_5_2") ??
                    Environment.GetEnvironmentVariable("LUA_CPATH") ??
                        String.Join(";", new[]
                        {
                            "!\\?.dll",
                            "!\\loadall.dll",
                            ".\\?.dll"
                        }));

            table.AddOrSet("path",
                Environment.GetEnvironmentVariable("LUA_PATH_5_2") ??
                    Environment.GetEnvironmentVariable("LUA_PATH") ??
                        String.Join(";", new[]
                        {
                            "!\\lua\\" + "?.lua",
                            "!\\lua\\" + "?\\init.lua",
                            "!\\" + "?.lua",
                            "!\\" + "?\\init.lua",
                            ".\\?.lua"
                        }));

            table.AddOrSet("loaded", new LuaTable(Context));
            table.AddOrSet("preload", new LuaTable(Context));
            table.AddOrSet("searchers", new LuaTable(Context)); // TODO: fill with searchers

            table.AddOrSet("loadlib", (Func<string, string, object>)Loadlib);
            table.AddOrSet("searchpath", (Func<string, string, string, string, object>) SearchPath);
        }
Example #2
0
        public override void Setup(IDictionary<string, object> table)
        {
            table.AddOrSet("time", (Func<LuaTable, double>)Time );
            table.AddOrSet("difftime", (Func<double, double, double>) ((t2, t1) => t2 - t1));

            //table.AddOrSet("date", (Func<object, object>)Date); // TODO

            table.AddOrSet("exit", (Action<double>)(e => Environment.Exit((int)e)));
            table.AddOrSet("getenv", (Func<string, string>) Environment.GetEnvironmentVariable);

            table.AddOrSet("remove", (Func<string, object>) Delete);
            table.AddOrSet("rename", (Func<string, string, object>) Rename);
        }
Example #3
0
 public override void Setup(IDictionary<string, object> table)
 {
     table.AddOrSet("import", (Func<string,object[], LuaTable>)ImportType);
     table.AddOrSet("method", (Func<object, string, object>)InteropGetMethod);
     table.AddOrSet("call", (Func<object, string, object[], object>)InteropCallMethod);
     table.AddOrSet("setvalue", (Func<object, string, object, object>)InteropSetValue);
     table.AddOrSet("getvalue", (Func<object, string, object>)InteropGetValue);
     table.AddOrSet("subscribe", (Action<object, string, Delegate>)InteropSubscribeEvent);
     table.AddOrSet("unsubscribe", (Action<object, string, Delegate>)InteropUnsubscribeEvent);
     table.AddOrSet("makearray", (Func<object, object, object>)MakeArray);
     table.AddOrSet("iterate", (Func<object, object[], object>)InteropEnumerate);
 }
Example #4
0
        public override void Setup(IDictionary<string, object> table)
        {
            table.AddOrSet("len", (Func<string, double>) (s => s.Length));
            table.AddOrSet("upper", (Func<string, string>) (s => s.ToUpperInvariant()));
            table.AddOrSet("lower", (Func<string, string>)(s => s.ToLowerInvariant()));
            table.AddOrSet("rep", (Func<string, double, string>) ((s, r) => s.Repeat((int)Math.Round(r, MidpointRounding.ToEven))));

            table.AddOrSet("sub", (Func<string, double, double, string>)Subst); // TODO: varargs
            table.AddOrSet("char", (Func<double[], string>) Char); // TODO: varargs
            table.AddOrSet("byte", (Func<string, double, double, double[]>) Byte); // TODO: varargs

            table.AddOrSet("find", (Func<string, string, int?, bool?, object[]>)Find);
        }
Example #5
0
 public override void Setup(IDictionary<string, object> table)
 {
     table.AddOrSet("getlocal", (Func<object, object, Varargs>)GetLocal);
     table.AddOrSet("setlocal", (Func<object, object, object, object>)SetLocal);
 }
Example #6
0
        public override void Setup(IDictionary<string,object> table)
        {
            const double Math_Tau = 2.0 * Math.PI; // http://tauday.com

            table.AddOrSet("huge", Double.MaxValue);

            // Basic operations
            table.AddOrSet("abs", (Func<double, double>)Math.Abs);
            table.AddOrSet("mod", (Func<double, double, double>)((a, b) => a % b));
            table.AddOrSet("modf", (Func<double, double, Varargs>)((a, b) =>
            {
                long r;
                long q = Math.DivRem((long) a, (long) b, out r);
                return new Varargs(q, r);
            }));
            table.AddOrSet("floor", (Func<double, double>) Math.Floor);
            table.AddOrSet("ceil", (Func<double, double>) Math.Ceiling);
            table.AddOrSet("min", (Func<double, double, double>) Math.Min);
            table.AddOrSet("max", (Func<double, double, double>) Math.Max);

            // Exponetial and logarithmic
            table.AddOrSet("sqrt", (Func<double, double>) Math.Sqrt);
            table.AddOrSet("pow", (Func<double, double, double>) Math.Pow);
            table.AddOrSet("exp", (Func<double, double>) Math.Exp);
            table.AddOrSet("log", (Func<double, double>) Math.Log);
            table.AddOrSet("log10", (Func<double, double>) Math.Log10);

            // Trigonometrical
            table.AddOrSet("pi", Math.PI);
            table.AddOrSet("tau", Math_Tau);
            table.AddOrSet("deg", (Func<double, double>)(r => r * 360.0 / Math_Tau));
            table.AddOrSet("rad", (Func<double, double>)(d => d / 360.0 * Math_Tau));
            table.AddOrSet("cos", (Func<double, double>) Math.Cos);
            table.AddOrSet("sin", (Func<double, double>) Math.Sin);
            table.AddOrSet("tan", (Func<double, double>)Math.Tan);
            table.AddOrSet("acos", (Func<double, double>)Math.Acos);
            table.AddOrSet("asin", (Func<double, double>)Math.Asin);
            table.AddOrSet("atan", (Func<double, double>)Math.Atan);
            table.AddOrSet("atan2", (Func<double, double, double>)Math.Atan2);

            // Splitting on powers of 2
            //table.AddOrSet("frexp", (Func<double, double>) Math.??);
            //table.AddOrSet("ldexp", (Func<double, double, double>) Math.??);

            // Pseudo-random numbers
            table.AddOrSet("randomseed", (Func<double, double>)(x => { rand = new Random((int)x); return rand.NextDouble(); }));
            table.AddOrSet("random", (Func<Varargs, double>)Random); // overloaded
        }