//#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); }
public static string dolua_(string message) { if (DEBUG_) { Lua.fprintf(Lua.stdout, "%s\n", "==============>" + message); } if (L_ == null) { L_ = Lua.luaL_newstate(); Lua.luaL_openlibs(L_); } if (DEBUG_) { Lua.fprintf(Lua.stdout, "%s\n", "==============>2"); } string errorMessage = null; bool printResult = true; int status = Lua.luaL_loadbuffer(L_, message, (uint)Lua.strlen(message), "=stdin"); if (status == Lua.LUA_OK) { if (DEBUG_) { Lua.fprintf(Lua.stdout, "%s\n", "==============>3"); } status = docall_(L_, 0, printResult ? Lua.LUA_MULTRET : 0); } if ((status != Lua.LUA_OK) && !Lua.lua_isnil(L_, -1)) { if (DEBUG_) { Lua.fprintf(Lua.stdout, "%s\n", "==============>4"); } Lua.CharPtr msg = Lua.lua_tostring(L_, -1); if (msg == null) { msg = "(error object is not a string)"; } errorMessage = msg.ToString(); Lua.lua_pop(L_, 1); /* force a complete garbage collection in case of errors */ Lua.lua_gc(L_, Lua.LUA_GCCOLLECT, 0); } if (printResult) { //see Lua.LUA_MULTRET if (status == Lua.LUA_OK && Lua.lua_gettop(L_) > 0) /* any result to print? */ { Lua.luaL_checkstack(L_, Lua.LUA_MINSTACK, "too many results to print"); Lua.lua_getglobal(L_, "print"); Lua.lua_insert(L_, 1); if (Lua.lua_pcall(L_, Lua.lua_gettop(L_) - 1, 0, 0) != Lua.LUA_OK) { l_message_(progname, Lua.lua_pushfstring(L_, "error calling " + Lua.LUA_QL("print").ToString() + " (%s)", Lua.lua_tostring(L_, -1))); } } } return(errorMessage); }