public static int system(CharPtr str) { ProcessStartInfo processStartInfo = new ProcessStartInfo(); processStartInfo.WindowStyle = ProcessWindowStyle.Hidden; processStartInfo.CreateNoWindow = true; processStartInfo.UseShellExecute = false; processStartInfo.RedirectStandardOutput = true; processStartInfo.RedirectStandardError = true; processStartInfo.FileName = "cmd"; processStartInfo.Arguments = "/c "; processStartInfo.Arguments += str.ToString(); Process process = Process.Start(processStartInfo); process.WaitForExit(); return(process.ExitCode); }
public static FILE fopen(CharPtr filename, CharPtr mode) { FileStream stream = null; string str = filename.ToString(); FileMode filemode = FileMode.Open; FileAccess fileaccess = (FileAccess)0; for (int i = 0; mode[i] != '\0'; i++) { switch (mode[i]) { case 'r': fileaccess = fileaccess | FileAccess.Read; if (!File.Exists(str)) { return(null); } break; case 'w': filemode = FileMode.Create; fileaccess = fileaccess | FileAccess.Write; break; } } try { stream = new FileStream(str, filemode, fileaccess); } catch { stream = null; } FILE ret = new FILE(); ret.stream = stream; return(ret); }
private static int os_execute(lua_State L) { #if XBOX || SILVERLIGHT luaL_error(L, "os_execute not supported on XBox360"); #else CharPtr param = luaL_optstring(L, 1, null); if (param == null) { lua_pushinteger(L, 1); return(1); } CharPtr strCmdLine = "/C regenresx " + luaL_optstring(L, 1, null); System.Diagnostics.Process proc = new System.Diagnostics.Process(); proc.EnableRaisingEvents = false; proc.StartInfo.FileName = "CMD.exe"; proc.StartInfo.Arguments = strCmdLine.ToString(); proc.Start(); proc.WaitForExit(); lua_pushinteger(L, proc.ExitCode); #endif return(1); }
private static int OSExecute(LuaState L) { #if XBOX || SILVERLIGHT LuaLError(L, "os_execute not supported on XBox360"); #else CharPtr param = LuaLOptString(L, 1, null); if (param == null) { LuaPushInteger(L, 1); return(1); } CharPtr strCmdLine = "/C " + LuaLOptString(L, 1, null); System.Diagnostics.Process proc = new System.Diagnostics.Process(); proc.EnableRaisingEvents = false; proc.StartInfo.FileName = "CMD.exe"; proc.StartInfo.Arguments = strCmdLine.ToString(); proc.StartInfo.CreateNoWindow = true; proc.Start(); proc.WaitForExit(); LuaPushInteger(L, proc.ExitCode); #endif return(1); }
public CharPtr str; //FIXME:added = new CharPtr()???; public override string ToString() { return(str.ToString()); } // for debugging
public static void sprintf(CharPtr buffer, CharPtr str, params object[] argv) { string temp = Tools.sprintf(str.ToString(), argv); strcpy(buffer, new CharPtr(temp)); }
public static double atof(CharPtr nptr) { return(Convert.ToDouble(nptr.ToString())); }
public static int puts(CharPtr str) { Console.WriteLine(str.ToString()); return(0); }
//#define IS(s) (strcmp(argv[i],s)==0) static int doargs(int argc, string[] argv) { int i; int version = 0; if ((argv.Length > 0) && (argv[0] != "")) { progname = argv[0]; } for (i = 1; i < argc; i++) { if (argv[i][0] != '-') /* end of options; keep it */ { break; } else if (Lua.strcmp(argv[i], "--") == 0) /* end of options; skip it */ { ++i; if (version != 0) { ++version; } break; } else if (Lua.strcmp(argv[i], "-") == 0) /* end of options; use stdin */ { break; } else if (Lua.strcmp(argv[i], "-l") == 0) /* list */ { ++listing; } else if (Lua.strcmp(argv[i], "-o") == 0) /* output file */ { output = argv[++i]; if (output == null || (output[0] == 0)) { usage(Lua.LUA_QL("-o") + " needs argument"); } if (Lua.strcmp(argv[i], "-") == 0) { output = null; } } else if (Lua.strcmp(argv[i], "-p") == 0) /* parse only */ { dumping = 0; } else if (Lua.strcmp(argv[i], "-s") == 0) /* strip debug information */ { stripping = 1; } else if (Lua.strcmp(argv[i], "-v") == 0) /* show version */ { ++version; } else /* unknown option */ { usage(argv[i]); } } if (i == argc && ((listing != 0) || (dumping == 0))) { dumping = 0; argv[--i] = Output.ToString(); } if (version != 0) { Lua.printf("%s %s\n", Lua.LUA_RELEASE, Lua.LUA_COPYRIGHT); if (version == argc - 1) { Environment.Exit(Lua.EXIT_SUCCESS); } } return(i); }