public LuaEngine(IServiceProvider sp, string name) : base(sp, name) { // create the state this.propertyScriptCount = new SimpleConfigItemProperty <int>(this, "tw_luaengine_scripts", "Skripte", "Lua-Engine", "Anzahl der aktiven Scripte.", "{0:N0}", 0); // create the lists this.scripts = new DEList <LuaScript>(this, "tw_scripts", "Scriptlist"); this.globals = new DEList <LuaAttachedGlobal>(this, "tw_globals", "Attached scripts"); // Register the service var sc = sp.GetService <IServiceContainer>(true); sc.AddService(typeof(IDELuaEngine), this); // register context extensions LuaType.RegisterTypeExtension(typeof(HttpResponseHelper)); // create the debug options debugHook = new LuaEngineTraceLineDebugger(this); debugOptions = new LuaCompileOptions(); debugOptions.DebugEngine = debugHook; // update lua runtime sp.GetService <DEServer>(true).UpdateLuaRuntime(lua); } // ctor
public void ExtensionTest01() { LuaType.RegisterTypeExtension(typeof(TypeExt)); TestCode("return 'Hallo0':LetterCount();", 5); TestCode("t = 'Hallo0'; return t:LetterCount();", 5); }
private void ExtendLuaEnvironment(LuaGlobal g) { g.RegisterPackage("os", typeof(OperationSystemPackage)); g.RegisterPackage("log", typeof(ConsolePackage)); foreach (var package in _userProvidedPackages) { g.RegisterPackage(package.Key, package.Value); } // extension methods need to be registered separately through RegisterTypeExtension call) foreach (var extensionClass in _userProvidedExtensionMethodClasses) { LuaType.RegisterTypeExtension(extensionClass); } // tables can be registered directly dynamic dg = g; foreach (var pair in _userProvidedTables) { dg[pair.Key] = pair.Value; } // delegates need to be registered with the LuaGlobal foreach (var pair in _userProvidedDelegate) { g.DefineFunction(pair.Key, pair.Value); } }
private static void LinqTest2() { LuaType.RegisterTypeExtension(typeof(Enumerable)); // generic geht nicht List <int> lst = new List <int>(); lst.Add(1); lst.Add(2); lst.Add(3); using (Lua l = new Lua()) { var g = l.CreateEnvironment(); LuaResult r = g.DoChunk(String.Join(Environment.NewLine, "return a.Select(function (c) return c; end).ToArray();" ), new KeyValuePair <string, object>("a", lst)); Console.WriteLine(r[0].ToString()); } }
public void NamespaceTest01() { LuaType.RegisterTypeExtension(typeof(TypeExt)); TestCode("return '{0} {1}':Format(clr.System.Windows:FullName(), clr.Microsoft.Windows:FullName());", "System.Windows Microsoft.Windows"); }
public static void Initialize() { LuaType.RegisterTypeExtension(typeof(Extensions)); }