当前位置: 首页>>代码示例>>C#>>正文


C# LuaValue类代码示例

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


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

示例1: Wrap

 public static LuaValue Wrap(LuaValue[] args)
 {
     LuaFunction f = args[0] as LuaFunction;
     LuaCoroutine c = new LuaCoroutine(f);
     LuaFunction f2 = new LuaFunction(new LuaFunc(delegate(LuaValue[] args2) { return LuaBoolean.From(c.Resume(args2)); }));
     return f2;
 }
开发者ID:Majiir,项目名称:MuMechLib,代码行数:7,代码来源:CoroutineLib.cs

示例2: IsClass

 public static LuaValue IsClass(LuaValue[] args)
 {
     if ((args[0] as LuaClass) != null)
         return LuaBoolean.True;
     else
         return LuaBoolean.False;
 }
开发者ID:chenzuo,项目名称:SharpLua,代码行数:7,代码来源:ClassLib.cs

示例3: open

        public static LuaValue open(LuaValue[] values)
        {
            //[PixelCrushers]LuaString file = values[0] as LuaString;
            LuaString modeStr = values.Length > 1 ? values[1] as LuaString : null;
            string mode = modeStr == null ? "r" : modeStr.Text;

            switch (mode)
            {
                case "r":
                case "r+":
                //[PixelCrushers]StreamReader reader = File.OpenText(file.Text);
                //[PixelCrushers]return new LuaUserdata(reader, FileLib.CreateMetaTable());
                return null;
                case "w":
                case "w+":
                //[PixelCrushers]StreamWriter writer = File.CreateText(file.Text);
                //[PixelCrushers]return new LuaUserdata(writer, FileLib.CreateMetaTable());
                return null;
                case "a":
                case "a+":
                //[PixelCrushers]writer = File.AppendText(file.Text);
                //[PixelCrushers]return new LuaUserdata(writer, FileLib.CreateMetaTable());
                return null;
                default:
                    throw new ArgumentException("Invalid file open mode " + mode);
            }
        }
开发者ID:farreltr,项目名称:OneLastSunset,代码行数:27,代码来源:IOLib.cs

示例4: Yield

 public static LuaValue Yield(LuaValue[] args)
 {
     LuaCoroutine c = args[0] as LuaCoroutine;
     c.Pause();
     // TODO: set restart args
     return LuaNil.Nil;
 }
开发者ID:chenzuo,项目名称:SharpLua,代码行数:7,代码来源:CoroutineLib.cs

示例5: Evaluate

        public override LuaValue Evaluate(LuaValue baseValue, LuaTable enviroment)
        {
            LuaValue value = LuaValue.GetKeyValue(baseValue, new LuaString(this.Method));
            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
                {
                    //[PixelCrushers]List<LuaValue> args = this.Args.ArgList.ConvertAll(arg => arg.Evaluate(enviroment));
                    List<LuaValue> args = LuaInterpreterExtensions.EvaluateAll(this.Args.ArgList, enviroment);
                    args.Insert(0, baseValue);
                    return function.Function.Invoke(args.ToArray());
                }
            }
            else
            {
                throw new Exception("Invoke method call on non function value.");
            }
        }
开发者ID:farreltr,项目名称:OneLastSunset,代码行数:28,代码来源:MethodCall.cs

示例6: Lines

        public static LuaValue Lines(LuaValue[] values)
        {
            LuaUserdata data = values[0] as LuaUserdata;
            TextReader reader = data.Value as TextReader;

            LuaFunction func = new LuaFunction((LuaValue[] args) =>
                {
                    LuaUserdata _data = values[0] as LuaUserdata;
                    TextReader _reader = data.Value as TextReader;

                    string line = _reader.ReadLine();

                    if (line != null)
                    {
                        return new LuaString(line);
                    }
                    else
                    {
                        return LuaNil.Nil;
                    }
                }
            );

            return new LuaMultiValue(new LuaValue[] { func, data, LuaNil.Nil });
        }
开发者ID:Majiir,项目名称:MuMechLib,代码行数:25,代码来源:FileLib.cs

示例7: Flush

 public static LuaValue Flush(LuaValue[] values)
 {
     LuaUserdata data = values[0] as LuaUserdata;
     TextWriter writer = data.Value as TextWriter;
     writer.Flush();
     return null;
 }
开发者ID:Majiir,项目名称:MuMechLib,代码行数:7,代码来源:FileLib.cs

示例8: 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

示例9: DiffTime

 public static LuaValue DiffTime(LuaValue[] args)
 {
     // FIXM
     DateTime t2 = DateTime.Parse(args[0].Value.ToString());
     DateTime t1 = DateTime.Parse(args[1].Value.ToString());
     return new LuaUserdata(t2 - t1);
 }
开发者ID:Majiir,项目名称:MuMechLib,代码行数:7,代码来源:OSLib.cs

示例10: Copy

        public static LuaValue Copy(LuaValue[] args)
        {
            LuaTable _new = (LuaTable) args[0];
            LuaTable old = (LuaTable) args[1];
            if (_new == null)
                throw new ArgumentNullException("Table to copy to cannot be nil!");
            if (old == null)
                throw new ArgumentNullException("Table to copy from cannot be nil!");
            if (old.Count == 0)
                return _new; // nothing to copy
            Dictionary<LuaValue, LuaValue> oldFields = (Dictionary<LuaValue, LuaValue>)old.KeyValuePairs;
            List<LuaValue> keys = new List<LuaValue>();
            List<LuaValue> values = new List<LuaValue>();

            foreach (LuaValue key in oldFields.Keys)
                keys.Add(key);
            foreach (LuaValue val in oldFields.Values)
                values.Add(val);

            // add to new table
            for (int i = 0; i < keys.Count; i++)
            {
                try {
                    _new.SetKeyValue(keys[i], values[i]);
                } catch (Exception ex) {
                    throw new Exception("Error copying at index " + i + ": " + ex.Message);
                }
            }
            return _new;
        }
开发者ID:Majiir,项目名称:MuMechLib,代码行数:30,代码来源:TableLib.cs

示例11: GetMetaFunction

        private static LuaFunction GetMetaFunction(string name, LuaValue leftValue, LuaValue rightValue)
        {
            LuaTable left = leftValue as LuaTable;

            if (left != null)
            {
                LuaFunction func = left.GetValue(name) as LuaFunction;

                if (func != null)
                {
                    return func;
                }
            }
            LuaFunction f = leftValue.MetaTable.GetValue(name) as LuaFunction;
            if (f != null)
                return f;

            LuaTable right = rightValue as LuaTable;

            if (right != null)
            {
                return right.GetValue(name) as LuaFunction;
            }
            f = rightValue.MetaTable.GetValue(name) as LuaFunction;
            if (f != null)
                return f;

            return null;
        }
开发者ID:Majiir,项目名称:MuMechLib,代码行数:29,代码来源:Operation.cs

示例12: VariableUpdateEventArgs

		public VariableUpdateEventArgs(VariableUpdateType type, LuaValue thread, VariableDetails[] vars, bool cacheFlush)
		{
			mType = type;
			mThread = thread;
			mVariables = vars;
			mCacheFlush = cacheFlush;
		}
开发者ID:zcnet4,项目名称:lua-tilde,代码行数:7,代码来源:VariableUpdateEvent.cs

示例13: 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

示例14: 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

示例15: Concat

        public static LuaValue Concat(LuaValue[] values)
        {
            LuaTable table = values[0] as LuaTable;
            LuaString separator = values.Length > 1 ? values[1] as LuaString : LuaString.Empty;
            LuaNumber startNumber = values.Length > 2 ? values[2] as LuaNumber : null;
            LuaNumber endNumber = values.Length > 3 ? values[3] as LuaNumber : null;

            int start = startNumber == null ? 1 : (int)startNumber.Number;
            int end = endNumber == null ? table.Count : (int)endNumber.Number;

            if (start > end)
            {
                return LuaString.Empty;
            }
            else
            {
                StringBuilder text = new StringBuilder();

                for (int index = start; index < end; index++)
                {
                    text.Append(table.GetValue(index).ToString());
                    text.Append(separator.Text);
                }
                text.Append(table.GetValue(end).ToString());

                return new LuaString(text.ToString());
            }
        }
开发者ID:Majiir,项目名称:MuMechLib,代码行数:28,代码来源:TableLib.cs


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