private static int DoRepl() { var l = CSLua.CreateLuaState(); BaseLib.OpenLib(l); while (true) { Console.Write("> "); var line = Console.ReadLine(); if (string.IsNullOrEmpty(line)) { continue; } try { l.Load(line.GetBytes(), "repl", "bt"); l.Call(0, 0); } catch (Exception e) { Console.WriteLine(e.ToString()); } } }
public IDatabase CreateClient(DatabaseLib.Entity.DatabaseEntity dbEntity, BaseLib.SystemType tmpSystemType) { IDatabase dDatabase = null; try { //��ȡ��Ӧ�����ݿ����� Type ClientType = Type.GetType(_sClassPath + ((DataType)(Int32.Parse(dbEntity.Data_Type))).ToString(), true); //������Ӧ�����ݿ����ʵ�������ظ��ӿ�ʹ������ͨ���ӿ����ҵ����ݿ����ʵ�ִ��� dDatabase = (IDatabase)Activator.CreateInstance(ClientType); dDatabase.SystemType = tmpSystemType; dDatabase.Server = dbEntity.Server; dDatabase.Uid = dbEntity.Uid; dDatabase.Password = dbEntity.Pwd; dDatabase.DatabaseName = dbEntity.Name; dDatabase.Port = dbEntity.Port; } catch (Exception ex) { //��ȡ�����쳣�Ĵ�����Ϣ this.Message = ex.Message; this.Result = false; } //���ز���ʵ������ return dDatabase; }
/*!----------------------------------�쳣δ����-------------------------------------------*/ public IDatabase CreateClient(BaseLib.SystemType tmpSystemType) { IDatabase dDatabase = null; try { //��ȡ��Ӧ�����ݿ����� Type ClientType = Type.GetType(_sClassPath + ((DataType)(Int32.Parse(CommonLib.Common.ConfigReader.Read("DataType", tmpSystemType)))).ToString(), true); //������Ӧ�����ݿ����ʵ�������ظ��ӿ�ʹ������ͨ���ӿ����ҵ����ݿ����ʵ�ִ��� dDatabase = (IDatabase)Activator.CreateInstance(ClientType); dDatabase.SystemType = tmpSystemType; dDatabase.Server = CommonLib.Common.ConfigReader.Read("Server", tmpSystemType); dDatabase.Uid = CommonLib.Common.ConfigReader.Read("UID", tmpSystemType); dDatabase.Password = CommonLib.Common.ConfigReader.Read("PWD", tmpSystemType); dDatabase.DatabaseName = CommonLib.Common.ConfigReader.Read("Database", tmpSystemType); dDatabase.Port = CommonLib.Common.ConfigReader.Read("Port", tmpSystemType); } catch (Exception ex) { //��ȡ�����쳣�Ĵ�����Ϣ this.Message = ex.Message; this.Result = false; } //���ز���ʵ������ return dDatabase; }
public Test001() { const string test001 = "n = 99 + (1 * 10) / 2 - 0.5;\n" + "if n > 10 then return 'Oh, 真的比10还大哦:'..n end\n" + "return n\n"; const string test002 = "return _VERSION"; const string test003 = "return nil"; const bool isLoadLib = true; try { Console.WriteLine("Start test..."); Lua L = new Lua(); if (isLoadLib) { BaseLib.open(L); PackageLib.open(L); MathLib.open(L); OSLib.open(L); StringLib.open(L); TableLib.open(L); } int status = L.doString(test001); if (status != 0) { object errObj = L.value(1); object tostring = L.getGlobal("tostring"); L.push(tostring); L.push(errObj); L.call(1, 1); string errObjStr = L.toString(L.value(-1)); throw new Exception("Error compiling : " + L.value(1)); } else { object result = L.value(1); object tostring_ = L.getGlobal("tostring"); L.push(tostring_); L.push(result); L.call(1, 1); string resultStr = L.toString(L.value(-1)); Console.WriteLine("Result >>> " + resultStr); } } catch (Exception e) { Console.WriteLine(e); } }
public static LuaTable CreateGlobalEnviroment() { LuaTable global = new LuaTable(); BaseLib.RegisterFunctions(global); StringLib.RegisterModule(global); TableLib.RegisterModule(global); IOLib.RegisterModule(global); MathLib.RegisterModule(global); global.SetNameValue("_G", global); return(global); }
private static int DoFile(string filePath) { try { var data = File.ReadAllBytes(filePath); var l = CSLua.CreateLuaState(); BaseLib.OpenLib(l); l.Load(data, filePath, "bt"); l.Call(0, 0); return((int)EErrorCode.Ok); } catch (IOException e) { Console.WriteLine(e.ToString()); return((int)EErrorCode.ErrFile); } catch (Exception e) { Console.WriteLine(e.ToString()); return((int)EErrorCode.ErrRun); } }
public List<string> ExtractFriendIDs(ref BaseLib.ChilkatHttpHelpr HttpHelper, ref Chilkat.Http http, ref string userID) { try { string pgSrc_HomePage = HttpHelper.GetHtml("http://www.facebook.com/", ref http); string ProFileURL = string.Empty; string UserId = string.Empty; #region Get User or Account ID if (pgSrc_HomePage.Contains("http://www.facebook.com/profile.php?id=")) { ///Modified Sumit [10-12-2011] #region int startIndx = pgSrc_HomePage.IndexOf("http://www.facebook.com/profile.php?id="); int endIndx = pgSrc_HomePage.IndexOf("\"", startIndx + 1); ProFileURL = pgSrc_HomePage.Substring(startIndx, endIndx - startIndx); if (ProFileURL.Contains("&")) { string[] Arr = ProFileURL.Split('&'); ProFileURL = Arr[0]; } #endregion } if (ProFileURL.Contains("http://www.facebook.com/profile.php?id=")) { UserId = ProFileURL.Replace("http://www.facebook.com/profile.php?id=", ""); if (UserId.Contains("&")) { UserId = UserId.Remove(UserId.IndexOf("&")); } userID = UserId; } #endregion List<string> lstFriend = new List<string>(); string pgSrc_FriendsPage = HttpHelper.GetHtml("http://www.facebook.com/profile.php?id=" + UserId + "&sk=friends&v=friends", ref http); if (pgSrc_FriendsPage.Contains("http://www.facebook.com/profile.php?id=")) { string[] arr = Regex.Split(pgSrc_FriendsPage, "href"); foreach (string strhref in arr) { if (!strhref.Contains("<!DOCTYPE")) { if (strhref.Contains("profile.php?id")) { int startIndx = strhref.IndexOf("profile.php?id") + "profile.php?id".Length + 1; int endIndx = strhref.IndexOf("\"", startIndx); string profileID = strhref.Substring(startIndx, endIndx - startIndx); if (profileID.Contains("&")) { profileID = profileID.Remove(profileID.IndexOf("&")); } if (profileID.Contains("\\")) { profileID = profileID.Replace("\\", ""); } lstFriend.Add(profileID); } } } } List<string> itemId = lstFriend.Distinct().ToList(); return itemId; } catch (Exception) { return null; } }
/// <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); }
private void RaiseSchedulerEvent(BaseLib.Module module) { EventsArgs eArgs = new EventsArgs(module); Event_StartScheduler.RaiseScheduler(eArgs); }
public string strModule(BaseLib.Module module) { switch (module) { case BaseLib.Module.SearchkeywordInvites: return threadNaming_SearchkeywordInvites_; //case BaseLib.Module.Tweet: // return threadNaming_Tweet_; //case BaseLib.Module.Retweet: // return threadNaming_Retweet_; //case BaseLib.Module.Reply: // return threadNaming_Reply_; //case BaseLib.Module.Follow: // return threadNaming_Follow_; //case BaseLib.Module.Unfollow: // return threadNaming_Unfollow_; //case BaseLib.Module.ProfileManager: // return threadNaming_ProfileManager_; default: return ""; } }
/// <summary> /// ��ʼ������֤���ݿ����� /// </summary> /// <returns></returns> public void GetDataType(BaseLib.SystemType type, string strDataType) { int nDataType = 0; if (strDataType == null || strDataType == "") strDataType = CommonLib.Common.ConfigReader.Read("DataType", type); if (!CommonLib.Common.Validate.IsNumber(strDataType)) { this.Message = "���ݿ��������ô���!"; this.Result = false; } nDataType = Int32.Parse(strDataType); _sClassName = ((DataType)nDataType).ToString(); if (CommonLib.Common.Validate.IsNumber(_sClassName)) { _sClassName = ""; this.Message = "���ݿ��������ô���!"; this.Result = false; } }
public Runner(string[] args, string filename) { if (args.Length > 0) { string path = args[0]; StreamReader sr = new StreamReader(path, Encoding.Default); String line; string content = ""; while ((line = sr.ReadLine()) != null) { content += line.ToString() + "\n"; } const bool isLoadLib = true; const bool useArg = true; // try { Lua L = new Lua(); if (isLoadLib) { BaseLib.open(L); PackageLib.open(L); MathLib.open(L); OSLib.open(L); StringLib.open(L); TableLib.open(L); } if (useArg) { //FIXME: index may be minus (for example, arg[-1], before script file name) //@see http://www.ttlsa.com/lua/lua-install-and-lua-variable-ttlsa/ int narg = args.Length; LuaTable tbl = L.createTable(narg, narg); for (int i = 0; i < narg; i++) { L.rawSetI(tbl, i, args[i]); } L.setGlobal("arg", tbl); } int status = L.doString(content); if (status != 0) { object errObj = L.value(1); object tostring = L.getGlobal("tostring"); L.push(tostring); L.push(errObj); L.call(1, 1); string errObjStr = L.toString(L.value(-1)); throw new Exception("Error compiling : " + L.value(1)); } else { object result = L.value(1); object tostring_ = L.getGlobal("tostring"); L.push(tostring_); L.push(result); L.call(1, 1); string resultStr = L.toString(L.value(-1)); Console.WriteLine("Result >>> " + resultStr); } } // catch (Exception e) // { // Console.WriteLine(e); // } } else { Console.WriteLine("usage: {0} <filename>", filename); } }