• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# LuaTypes.LuaTable类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中SharpLua.LuaTypes.LuaTable的典型用法代码示例。如果您正苦于以下问题:C# LuaTable类的具体用法?C# LuaTable怎么用?C# LuaTable使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



LuaTable类属于SharpLua.LuaTypes命名空间,在下文中一共展示了LuaTable类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: CreateClass

 public static LuaValue CreateClass(LuaValue[] args)
 {
     LuaTable from = new LuaTable();
     if (args.Length > 0)
         if (args[0].GetTypeCode() == "table" && ((IsClass(new LuaValue[] {args[0]}) as LuaBoolean).BoolValue == false))
             from = args[0] as LuaTable;
     LuaClass nClass = new LuaClass("CLASS_" + classCount++, false, false);
     List<LuaClass> Parents = new List<LuaClass>();
     for (int i = 0; i < args.Length; i++)
     {
         LuaClass c = args[i] as LuaClass;
         if (c == null)
             continue;
         if (c.Final)
             throw new Exception("Cannot inherit from a final class");
         else
         {
             Parents.Add(c);
             c.ChildClasses.Add(nClass);
         }
     }
     nClass.ParentClasses = Parents;
     TableLib.Copy(new LuaValue[] {nClass.Self, from});
     return nClass;
 }
开发者ID:Majiir,项目名称:MuMechLib,代码行数:25,代码来源:ClassLib.cs


示例2: Date

        public static LuaValue Date(LuaValue[] values)
        {
            LuaString format = null;
            if (values.Length > 0)
                format = values[0] as LuaString;
            if (format != null)
            {
                if (format.Text == "*t")
                {
                    LuaTable table = new LuaTable();
                    DateTime now = DateTime.Now;
                    table.SetNameValue("year", new LuaNumber (now.Year));
                    table.SetNameValue("month", new LuaNumber (now.Month ));
                    table.SetNameValue("day", new LuaNumber (now.Day));
                    table.SetNameValue("hour", new LuaNumber (now.Hour));
                    table.SetNameValue("min", new LuaNumber (now.Minute));
                    table.SetNameValue("sec", new LuaNumber (now.Second));
                    table.SetNameValue("wday", new LuaNumber ((int)now.DayOfWeek));
                    table.SetNameValue("yday", new LuaNumber (now.DayOfYear));
                    table.SetNameValue("isdst", LuaBoolean.From(now.IsDaylightSavingTime()));
                }
                else
                {
                    return new LuaString(DateTime.Now.ToString(format.Text));
                }
            }

            return new LuaString(DateTime.Now.ToShortDateString());
        }
开发者ID:chenzuo,项目名称:SharpLua,代码行数:29,代码来源:OSLib.cs


示例3: RegisterFunctions

 public static void RegisterFunctions(LuaTable module)
 {
     module.Register("print", Print);
     module.Register("type", Type);
     module.Register("getmetatable", GetMetaTable);
     module.Register("setmetatable", SetMetaTable);
     module.Register("tostring", Tostring);
     module.Register("tonumber", Tonumber);
     module.Register("ipairs", IPairs);
     module.Register("pairs", Pairs);
     module.Register("next", Next);
     module.Register("assert", Assert);
     module.Register("error", Error);
     module.Register("rawget", RawGet);
     module.Register("rawset", RawSet);
     module.Register("select", Select);
     module.Register("dofile", DoFile);
     module.Register("loadstring", LoadString);
     module.Register("unpack", UnPack);
     module.Register("pcall", Pcall);
     module.Register("openfile", OpenFile);
     module.Register("require", Require);
     module.Register("set", Set);
     module.Register("loadfile", LoadFile);
     module.Register("xpcall", XPcall);
     module.Register("wait", Wait);
     module.Register("loadbin", LoadBin);
     module.Register("ssave", SSave);
     module.Register("sload", SLoad);
     module.Register("createauserdata", (LuaValue[] args) => { return new LuaUserdata(null); });
     module.Register("iarray", IterateDotNetList);
 }
开发者ID:chenzuo,项目名称:SharpLua,代码行数:32,代码来源:BaseLib.cs


示例4: Execute

        /// <summary>
        /// Executes the chunk
        /// </summary>
        /// <param name="enviroment">Runs in the given environment</param>
        /// <param name="isBreak">whether to break execution</param>
        /// <returns></returns>
        public override LuaValue Execute(LuaTable enviroment, out bool isBreak)
        {
            LuaNumber start = this.Start.Evaluate(enviroment) as LuaNumber;
            LuaNumber end = this.End.Evaluate(enviroment) as LuaNumber;

            double step = 1;
            if (this.Step != null)
            {
                step = (this.Step.Evaluate(enviroment) as LuaNumber).Number;
            }

            var table = new LuaTable(enviroment);
            table.SetNameValue(this.VarName, start);
            this.Body.Enviroment = table;

            while (step > 0 && start.Number <= end.Number ||
                   step <= 0 && start.Number >= end.Number)
            {
                var returnValue = this.Body.Execute(out isBreak);
                if (returnValue != null || isBreak == true)
                {
                    isBreak = false;
                    return returnValue;
                }
                start.Number += step;
            }

            isBreak = false;
            return null;
        }
开发者ID:Majiir,项目名称:MuMechLib,代码行数:36,代码来源:ForStmt.cs


示例5: Execute

        /// <summary>
        /// Executes the chunk
        /// </summary>
        /// <param name="enviroment">The environment to run in</param>
        /// <param name="isBreak">whether to break execution</param>
        /// <returns></returns>
        public override LuaValue Execute(LuaTable enviroment, out bool isBreak)
        {
            LuaValue condition = this.Condition.Evaluate(enviroment);

            if (condition.GetBooleanValue() == true)
            {
                return this.ThenBlock.Execute(enviroment, out isBreak);
            }
            else
            {
                foreach (ElseifBlock elseifBlock in this.ElseifBlocks)
                {
                    condition = elseifBlock.Condition.Evaluate(enviroment);

                    if (condition.GetBooleanValue() == true)
                    {
                        return elseifBlock.ThenBlock.Execute(enviroment, out isBreak);
                    }
                }

                if (this.ElseBlock != null)
                {
                    return this.ElseBlock.Execute(enviroment, out isBreak);
                }
            }

            isBreak = false;
            return null;
        }
开发者ID:chenzuo,项目名称:SharpLua,代码行数:35,代码来源:IfStmt.cs


示例6: Evaluate

        public override LuaValue Evaluate(LuaTable enviroment)
        {
            LuaTable table = new LuaTable();

            foreach (Field field in this.FieldList)
            {
                NameValue nameValue = field as NameValue;
                if (nameValue != null)
                {
                    table.SetNameValue(nameValue.Name, nameValue.Value.Evaluate(enviroment));
                    continue;
                }

                KeyValue keyValue = field as KeyValue;
                if (keyValue != null)
                {
                    table.SetKeyValue(
                        keyValue.Key.Evaluate(enviroment),
                        keyValue.Value.Evaluate(enviroment));
                    continue;
                }

                ItemValue itemValue = field as ItemValue;
                if (itemValue != null)
                {
                    table.AddValue(itemValue.Value.Evaluate(enviroment));
                    continue;
                }
            }

            return table;
        }
开发者ID:Majiir,项目名称:MuMechLib,代码行数:32,代码来源:TableConstructor.cs


示例7: RegisterModule

 public void RegisterModule(SharpLua.LuaTypes.LuaTable environment)
 {
     LuaTable mod = new LuaTable();
     RegisterFunctions(mod);
     
     LuaTable mt = new LuaTable();
     mt.Register("__newindex", (LuaValue[] args) =>
                 {
                     string key = args[1].ToString();
                     if (key.ToLower() == "key")
                     {
                         CryptoLib.key = IExtendFramework.Encryption.SampleObjects.CreateRijndaelKeyWithSHA512(args[2].ToString());
                         Console.WriteLine("Encryption Key is now " + ByteToString(CryptoLib.key));
                     }
                     else if (key.ToLower() == "iv")
                     {
                         iv = IExtendFramework.Encryption.SampleObjects.CreateRijndaelIVWithSHA512(args[2].ToString());
                         Console.WriteLine("Encryption IV is now " + ByteToString(CryptoLib.iv));
                     }
                     
                     return LuaNil.Nil;
                 });
     mod.MetaTable = mt;
     environment.SetNameValue(ModuleName, mod);
 }
开发者ID:chenzuo,项目名称:SharpLua,代码行数:25,代码来源:MyClass.cs


示例8: CreateMetaTable

 public static LuaTable CreateMetaTable()
 {
     LuaTable metatable = new LuaTable();
     RegisterFunctions(metatable);
     metatable.SetNameValue("__index", metatable);
     return metatable;
 }
开发者ID:Majiir,项目名称:MuMechLib,代码行数:7,代码来源:FileLib.cs


示例9: Evaluate

        public override LuaValue Evaluate(LuaValue baseValue, LuaTable enviroment)
        {
            LuaValue value = null;
		try {LuaValue.GetKeyValue(baseValue, new LuaString(this.Method)); } catch (Exception) { }
            LuaFunction function = value as LuaFunction;

            if (function != null)
            {
                if (this.Args.Table != null)
                {
                    return function.Function.Invoke(new LuaValue[] { baseValue, this.Args.Table.Evaluate(enviroment) });
                }
                else if (this.Args.String != null)
                {
                    return function.Function.Invoke(new LuaValue[] { baseValue, this.Args.String.Evaluate(enviroment) });
                }
                else
                {
                    List<LuaValue> args = this.Args.ArgList.ConvertAll(arg => arg.Evaluate(enviroment));
                    args.Insert(0, baseValue);
                    return function.Function.Invoke(args.ToArray());
                }
            } // method call on table would be like _G:script()
            else if ((baseValue as LuaTable) != null)
            {
                List<LuaValue> args = this.Args.ArgList.ConvertAll(arg => arg.Evaluate(enviroment));
                return ((baseValue as LuaTable).MetaTable.GetValue("__call") as LuaFunction).Invoke(args.ToArray());
            }
            else if ((baseValue as LuaClass) != null)
            {
                LuaClass c = baseValue as LuaClass;
                List<LuaValue> args = this.Args.ArgList.ConvertAll(arg => arg.Evaluate(enviroment));
                args.Insert(0, new LuaString(this.Method));
                if (c.Self.MetaTable == null)
                    c.GenerateMetaTable();
                return (c.Self.MetaTable.GetValue("__call") as LuaFunction).Invoke(args.ToArray());
            }
            else if ((baseValue as LuaUserdata) != null)
            {
                List<LuaValue> args = this.Args.ArgList.ConvertAll(arg => arg.Evaluate(enviroment));
                LuaUserdata obj = baseValue as LuaUserdata;
                object o = obj.Value;
                if (obj.MetaTable != null)
                {
                    if (obj.MetaTable.GetValue(this.Method) != null)
                    {
                        LuaValue o2 = obj.MetaTable.GetValue(this.Method);
                        if ((o2 as LuaFunction) != null)
                            return (o2 as LuaFunction).Invoke(args.ToArray());
                        else if ((o2 as LuaTable) != null)
                            throw new NotImplementedException(); // TODO
                    }
                }
                return ObjectToLua.ToLuaValue(o.GetType().GetMethod(this.Method, BindingFlags.IgnoreCase | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).Invoke(o, BindingFlags.IgnoreCase | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, args.ToArray(), CultureInfo.CurrentCulture));
            }
            else
            {
                throw new Exception("Invoke method call on non function value.");
            }
        }
开发者ID:chenzuo,项目名称:SharpLua,代码行数:60,代码来源:MethodCall.cs


示例10: RegisterFunctions

 public static void RegisterFunctions(LuaTable mod)
 {
     mod.Register("attributes", Attributes);
     mod.Register("chdir", ChDir);
     mod.Register("lock", Lock);
     mod.Register("currentdir", CurrentDir);
     mod.Register("mkdir", Mkdir);
     mod.Register("delete", Delete);
     mod.Register("unlock", Unlock);
     mod.Register("copy", (LuaValue[] args) =>
                  {
                      File.Copy(args[0].ToString(), args[1].ToString());
                      return LuaBoolean.True;
                  });
     mod.Register("write", (LuaValue[] args) =>
                  {
                      using (StreamWriter sw = new StreamWriter(args[0].ToString()))
                      {
                          for (int i = 1; i < args.Length; i++)
                              sw.WriteLine(args[i].ToString());
                          sw.Close();
                      }
                      return LuaNil.Nil;
                  });
 }
开发者ID:chenzuo,项目名称:SharpLua,代码行数:25,代码来源:FileSystemLib.cs


示例11: RegisterFunctions

 public static void RegisterFunctions(LuaTable module)
 {
     module.SetNameValue("huge", new LuaNumber(double.MaxValue));
     module.SetNameValue("pi", new LuaNumber(Math.PI));
     module.Register("abs", Abs);
     module.Register("acos", Acos);
     module.Register("asin", Asin);
     module.Register("atan", Atan);
     module.Register("atan2", Atan2);
     module.Register("ceil", Ceil);
     module.Register("cos", Cos);
     module.Register("cosh", Cosh);
     module.Register("deg", Deg);
     module.Register("exp", Exp);
     module.Register("floor", Floor);
     module.Register("fmod", Fmod);
     module.Register("log", Log);
     module.Register("log10", Log10);
     module.Register("max", Max);
     module.Register("min", Min);
     module.Register("modf", ModF);
     module.Register("pow", Pow);
     module.Register("rad", Rad);
     module.Register("random", Random);
     module.Register("randomseed", RandomSeed);
     module.Register("sin", Sin);
     module.Register("sinh", SinH);
     module.Register("sqrt", Sqrt);
     module.Register("tan", Tan);
     module.Register("tanh", TanH);
 }
开发者ID:chenzuo,项目名称:SharpLua,代码行数:31,代码来源:MathLib.cs


示例12: RegisterModule

 public static void RegisterModule(LuaTable enviroment)
 {
     LuaTable module = new LuaTable();
     RegisterFunctions(module);
     enviroment.SetNameValue("WinForms", module);
     module.SetNameValue("_G", enviroment);
     currentModule = module;
 }
开发者ID:chenzuo,项目名称:SharpLua,代码行数:8,代码来源:WinFormLib.cs


示例13: RegisterFunctions

 public static void RegisterFunctions(LuaTable module)
 {
     module.Register("create", Create);
     module.Register("resume", Resume);
     module.Register("running", Running);
     module.Register("status", Status);
     module.Register("wrap", Wrap);
     module.Register("yield", Yield);
 }
开发者ID:Majiir,项目名称:MuMechLib,代码行数:9,代码来源:CoroutineLib.cs


示例14: RegisterFunctions

 public static void RegisterFunctions(LuaTable module)
 {
     module.Register("close", Close);
     module.Register("read", Read);
     module.Register("write", Write);
     module.Register("lines", Lines);
     module.Register("flush", Flush);
     module.Register("seek", Seek);
 }
开发者ID:chenzuo,项目名称:SharpLua,代码行数:9,代码来源:FileLib.cs


示例15: RegisterFunctions

 public static void RegisterFunctions(LuaTable module)
 {
     module.Register("write", Write);
     module.Register("writeline", WriteLine);
     module.Register("clear", new LuaFunc(delegate (LuaValue[] args) {
                                              A8Console.Clear();
                                              return LuaNil.Nil;
                                          }));
 }
开发者ID:Majiir,项目名称:MuMechLib,代码行数:9,代码来源:ConsoleLib.cs


示例16: RegisterFunctions

 public static void RegisterFunctions(LuaTable module)
 {
     module.Register("Run", RunApp);
     module.Register("ShowMessage", ShowMessage);
     module.Register("MessageBox", ShowMessage);
     module.Register("msgbox", ShowMessage);
     LuaTable metaTable = new LuaTable();
     metaTable.Register("__index", GetControlCreator);
     module.MetaTable = metaTable;
 }
开发者ID:chenzuo,项目名称:SharpLua,代码行数:10,代码来源:WinFormLib.cs


示例17: Evaluate

        public override LuaValue Evaluate(LuaTable enviroment)
        {
            LuaValue baseValue = this.Base.Evaluate(enviroment);

            foreach (Access access in this.Accesses)
            {
                baseValue = access.Evaluate(baseValue, enviroment);
            }

            return baseValue;
        }
开发者ID:chenzuo,项目名称:SharpLua,代码行数:11,代码来源:PrimaryExpr.cs


示例18: Execute

        /// <summary>
        /// Executes the chunk
        /// </summary>
        /// <param name="enviroment">Runs in the given environment</param>
        /// <param name="isBreak">whether to break execution</param>
        /// <returns></returns>
        public override LuaValue Execute(LuaTable enviroment, out bool isBreak)
        {
            LuaValue[] values = this.ExprList.ConvertAll(expr => expr.Evaluate(enviroment)).ToArray();
            LuaValue[] neatValues = LuaMultiValue.UnWrapLuaValues(values);

            if (neatValues.Length < 3) //probably LuaUserdata. Literal will also fail...
            {
                return ExecuteAlternative(enviroment, out isBreak);
            }

            LuaFunction func = neatValues[0] as LuaFunction;
            LuaValue state = neatValues[1];
            LuaValue loopVar = neatValues[2];

            var table = new LuaTable(enviroment);
            this.Body.Enviroment = table;

            while (true)
            {
                LuaValue result = func.Invoke(new LuaValue[] { state, loopVar });
                LuaMultiValue multiValue = result as LuaMultiValue;

                if (multiValue != null)
                {
                    neatValues = LuaMultiValue.UnWrapLuaValues(multiValue.Values);
                    loopVar = neatValues[0];

                    for (int i = 0; i < Math.Min(this.NameList.Count, neatValues.Length); i++)
                    {
                        table.SetNameValue(this.NameList[i], neatValues[i]);
                    }
                }
                else
                {
                    loopVar = result;
                    table.SetNameValue(this.NameList[0], result);
                }

                if (loopVar == LuaNil.Nil)
                {
                    break;
                }

                var returnValue = this.Body.Execute(out isBreak);
                if (returnValue != null || isBreak == true)
                {
                    isBreak = false;
                    return returnValue;
                }
            }

            isBreak = false;
            return null;
        }
开发者ID:Majiir,项目名称:MuMechLib,代码行数:60,代码来源:ForInStmt.cs


示例19: RegisterFunctions

 public static void RegisterFunctions(LuaTable module)
 {
     module.Register("input", Input);
     module.Register("output", Output);
     module.Register("open", Open);
     module.Register("read", Read);
     module.Register("write", Write);
     module.Register("flush", Flush);
     module.Register("tmpfile", TmpFile);
     module.Register("close", Close);
     module.Register("lines", Lines);
 }
开发者ID:chenzuo,项目名称:SharpLua,代码行数:12,代码来源:IOLib.cs


示例20: RegisterFunctions

 public static void RegisterFunctions(LuaTable module)
 {
     module.Register("clock", Clock);
     module.Register("date", Date);
     module.Register("time", Time);
     module.Register("exit", Exit);
     module.Register("getenv", GetEnv);
     module.Register("remove", Remove);
     module.Register("rename", Rename);
     module.Register("tmpname", TmpName);
     module.Register("difftime", DiffTime);
 }
开发者ID:Majiir,项目名称:MuMechLib,代码行数:12,代码来源:OSLib.cs



注:本文中的SharpLua.LuaTypes.LuaTable类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# SharpMap.Map类代码示例发布时间:2022-05-26
下一篇:
C# Html.Node类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap