public static LuaTable CreateGlobalEnviroment() { LuaTable global = new LuaTable(); BaseLib.RegisterFunctions(global); StringLib.RegisterModule(global); TableLib.RegisterModule(global); IOLib.RegisterModule(global); FileLib.RegisterModule(global); MathLib.RegisterModule(global); OSLib.RegisterModule(global); global.SetNameValue("_G", global); return(global); }
/// <summary> /// Creates a global environment with all the base modules registered and /// some default values set. /// </summary> /// <returns></returns> public static LuaTable CreateGlobalEnviroment(bool createBaseLib = true, bool createStringLib = true, bool createTableLib = true, bool createOSLib = true, bool createIOLib = true, bool createFileLib = true, bool createMathLib = true, bool createScriptLib = true, bool createWinFormsLib = true, bool createConsoleLib = true, bool createCoroutineLib = true, bool createPackageLib = true, bool createClassLib = true, bool createFileSystemLib = true) { LuaTable global = new LuaTable(); // Register Lua Modules if (createBaseLib) { BaseLib.RegisterFunctions(global); } if (createStringLib) { StringLib.RegisterModule(global); } if (createTableLib) { TableLib.RegisterModule(global); } if (createIOLib) { IOLib.RegisterModule(global); } if (createFileLib) { FileLib.RegisterModule(global); } if (createMathLib) { MathLib.RegisterModule(global); } if (createOSLib) { OSLib.RegisterModule(global); } if (createScriptLib) { ScriptLib.RegisterModule(global); } //if (createWinFormsLib) // WinFormLib.RegisterModule(global); if (createConsoleLib) { ConsoleLib.RegisterModule(global); } if (createCoroutineLib) { CoroutineLib.RegisterModule(global); } if (createPackageLib) { PackageLib.RegisterModule(global); } if (createClassLib) { ClassLib.RegisterModule(global); } if (createFileSystemLib) { FileSystemLib.RegisterModule(global); } //global.SetNameValue("_WORKDIR", new LuaString(Application.StartupPath + "\\")); global.SetNameValue("_VERSION", new LuaString("Sharp Lua 1.1")); global.SetNameValue("_G", global); if (createPackageLib) { // set package.preload table LuaTable preload = (LuaTable)(global.GetValue("package") as LuaTable).GetValue("preload"); if (createStringLib) { preload.SetNameValue("string", (LuaTable)global.GetValue("string")); } if (createTableLib) { preload.SetNameValue("table", (LuaTable)global.GetValue("table")); } if (createIOLib) { preload.SetNameValue("io", (LuaTable)global.GetValue("io")); } if (createFileLib) { preload.SetNameValue("file", (LuaTable)global.GetValue("file")); } if (createMathLib) { preload.SetNameValue("math", (LuaTable)global.GetValue("math")); } if (createOSLib) { preload.SetNameValue("os", (LuaTable)global.GetValue("os")); } if (createScriptLib) { preload.SetNameValue("script", (LuaTable)global.GetValue("script")); } //if (createWinFormsLib) // preload.SetNameValue("WinForms", (LuaTable) global.GetValue("WinForms")); if (createConsoleLib) { preload.SetNameValue("console", (LuaTable)global.GetValue("console")); } if (createCoroutineLib) { preload.SetNameValue("coroutine", (LuaTable)global.GetValue("coroutine")); } if (createPackageLib) // wait a second... { preload.SetNameValue("package", (LuaTable)global.GetValue("package")); } if (createClassLib) { preload.SetNameValue("class", (LuaTable)global.GetValue("class")); } if (createFileSystemLib) { preload.SetNameValue("filesystem", (LuaTable)global.GetValue("filesystem")); } } if (createFileSystemLib) { FileSystemLib.currentDir = global.GetValue("_WORKDIR").ToString(); } GlobalEnvironment = global; return(global); }