Example #1
0
        public LuaContext(LuaContext parent)
        {
            this.Parent = parent;

            if (Parent.variables != null)
                this.variables = new LinkedDictionary<string, LuaObject> (parent.variables);
        }
Example #2
0
        public static void Main(string [] args)
        {
            LuaParser parser;

            var context = new LuaContext ();
            context.AddBasicLibrary ();
            context.AddIoLibrary ();

            if (args.Any ()) { // take first arg as file name
                parser = new LuaParser (context, args [0]);
                parser.Parse ();

                return;
            }

            // otherwise, run repl
            Console.WriteLine ("AluminumLua 0.1 (c) 2011 Alex Corrado");
            parser = new LuaParser (context);

                try {

                    parser.Parse (true);
                }
                catch (LuaException e) {
                    Console.WriteLine (e.Message);
                }
        }
		private static void SetRefletionTable(ContainerBuilder builder, LuaContext context)
		{
			var b = new AutofacLuaReflection();
			var builderTable =
				LuaObject.FromTable(
					new Dictionary<LuaObject, LuaObject>()
						{
							{ "Activate", LuaObject.FromFunction(b.Activate) },
							{ "Resolve", LuaObject.FromDelegate((Func<IComponentContext, object, object>)b.Resolve) },
							{ "Invoke", LuaObject.FromFunction(b.Invoke) },
							{ "GetValue", LuaObject.FromFunction(b.GetValue) },
							{ "SetValue", LuaObject.FromFunction(b.SetValue) },
							{ "Type", LuaObject.FromDelegate((Func<object, object>)b.Type) },
							{ "TypeOf", LuaObject.FromDelegate((Func<object, object>)b.TypeOf) },
						});
			context.SetGlobal("reflection", builderTable);
		}
		private static void SetBuilderTable(ContainerBuilder builder, LuaContext context)
		{
			var b = new AutofacLuaBuilder(builder);
			var builderTable =
				LuaObject.FromTable(
					new Dictionary<LuaObject, LuaObject>()
						{
							{ "As", LuaObject.FromDelegate((Func<object, object, object>)(b.As)) },
							{ "RegisterGeneric", LuaObject.FromDelegate((Func<object, object>)(b.RegisterGeneric)) },
							{ "RegisterType", LuaObject.FromDelegate((Func<object, object>)(b.RegisterType)) },
							{ "RegisterModule", LuaObject.FromDelegate((Action<object>)(b.RegisterModule)) },
							{ "RegisterInstance", LuaObject.FromDelegate((Func<object, object>)(b.RegisterInstance)) },
							{ "Register", LuaObject.FromDelegate((Func<LuaFunction, object>)(b.Register)) },
							{ "InstancePerDependency", LuaObject.FromDelegate((Func<object, object>)(b.InstancePerDependency)) },
							{ "SingleInstance", LuaObject.FromDelegate((Func<object, object>)(b.SingleInstance)) },
						});
			context.SetGlobal("builder", builderTable);
		}
		/// <summary>
		/// The load.
		/// </summary>
		/// <param name="builder">
		/// The builder.
		/// </param>
		protected override void Load(ContainerBuilder builder)
		{
			if (string.IsNullOrEmpty(this.fileName)) this.fileName = "autofac.lua";

			LuaParser parser;

			var context = new LuaContext();
			context.AddBasicLibrary();
			parser = new LuaParser(context, this.fileName);

			SetBuilderTable(builder, context);
			SetRefletionTable(builder, context);

			parser.Parse();

			//lua = new Lua();
			//{
			//    lua["builder"] = new AutofacLuaBuilder(builder);
			//    lua.DoString(File.ReadAllText(fileName));
			//}
		}
Example #6
0
        public static string ValidateArtemisScript(string script)
        {
            try
            {
                script = "if false then " + Environment.NewLine + Regex.Replace(script, @"^\s*([A-Z]\w+):\s(.+)$", new MatchEvaluator(artemisScriptValidator), RegexOptions.Multiline) + Environment.NewLine + " end";
            }
            catch
            {
                return "Failed to parse script. Dunno why. This shouldn't happen.";
            }

            LuaContext lua = new LuaContext();
            lua.AddBasicLibrary();
            LuaParser p = new LuaParser(lua, new StringReader(script));
            try
            {
                p.Parse();
            }
            catch (LuaException ex)
            {
                return ex.Message;
            }
            return null;
        }
Example #7
0
 public LuaParser(LuaContext ctx)
     : this(LuaSettings.Executor(ctx))
 {
 }
Example #8
0
 public LuaParser(LuaContext ctx, TextReader stream)
     : this(LuaSettings.Executor(ctx), stream)
 {
 }
Example #9
0
 public LuaParser(LuaContext ctx, string file)
     : this(LuaSettings.Executor(ctx), file)
 {
 }
Example #10
0
 public LuaParser(LuaContext ctx, string file)
     : this(LuaSettings.Executor(ctx), file)
 {
 }
Example #11
0
 public LuaParser(LuaContext ctx)
     : this(LuaSettings.Executor(ctx))
 {
 }
Example #12
0
 public LuaParser(LuaContext ctx, TextReader stream)
     : this(LuaSettings.Executor(ctx), stream)
 {
 }