libFAUDES

Sections

Index

luafaudes.cpp

Go to the documentation of this file.
00001 /** @file luafaudes.cpp Simple Lua stand-alone interpreter for lua/faudes
00002  
00003    This lua interpreter is almost a plain copy of the original lua.c 
00004    provided with the lua 5.1.3 distribution  and under an MIT license;
00005    see original lua.h or http://www.lua.org
00006 
00007    The Advanced-Readline patch has been applied, also with lua license,
00008    copyright see below. Lua swig based bindings and minor adjustments 
00009    (wellcome string, logging) have been added (and signed "luafaudes").
00010    Thomas Moor, 2008.
00011 
00012 
00013 @ingroup Tutorials
00014 
00015 
00016 */
00017 
00018 
00019 // luafaudes: skip doxygen
00020 #ifndef FAUDES_DOXYGEN
00021 
00022 /*
00023 ** $Id: lua.c,v 1.160.1.2 2007/12/28 15:32:23 roberto Exp $
00024 ** Lua stand-alone interpreter
00025 ** See Copyright Notice in lua.h
00026 */
00027 
00028 
00029 // luafaudes: include c libs since we dont use lua.h
00030 #include <csignal>
00031 #include <cstdio>
00032 #include <cstdlib>
00033 #include <cstring>
00034 
00035 
00036 // luafaudes: use my include file
00037 #include "libluafaudes.h"
00038 
00039 // below this line: all from lua provided interpreter lua.cpp, except tagged "luafaudes"
00040 
00041 static lua_State *globalL = NULL;
00042 static const char *progname = LUA_PROGNAME;
00043 
00044 
00045 static void lstop (lua_State *L, lua_Debug *ar) {
00046   (void)ar;  /* unused arg. */
00047   lua_sethook(L, NULL, 0, 0);
00048   luaL_error(L, "interrupted!");
00049 }
00050 
00051 
00052 static void laction (int i) {
00053   signal(i, SIG_DFL); /* if another SIGINT happens before lstop,
00054                               terminate process (default action) */
00055   lua_sethook(globalL, lstop, LUA_MASKCALL | LUA_MASKRET | LUA_MASKCOUNT, 1);
00056 }
00057 
00058 
00059 static void print_usage (void) {
00060   fprintf(stderr,
00061   "usage: %s [options] [script [args]].\n"
00062   "Available options are:\n"
00063   "  -e stat  execute string " LUA_QL("stat") "\n"
00064   "  -l name  require library " LUA_QL("name") "\n"
00065   "  -i       enter interactive mode after executing " LUA_QL("script") "\n"
00066   "  -v       show version information\n"
00067   "  --       stop handling options\n"
00068   "  -        execute stdin and stop handling options\n"
00069   ,
00070   progname);
00071   fflush(stderr);
00072 }
00073 
00074 
00075 static void l_message (const char *pname, const char *msg) {
00076   if (pname) fprintf(stderr, "%s: ", pname);
00077   fprintf(stderr, "%s\n", msg);
00078   fflush(stderr);
00079 }
00080 
00081 
00082 static int report (lua_State *L, int status) {
00083   if (status && !lua_isnil(L, -1)) {
00084     const char *msg = lua_tostring(L, -1);
00085     if (msg == NULL) msg = "(error object is not a string)";
00086     l_message(progname, msg);
00087     lua_pop(L, 1);
00088   }
00089   return status;
00090 }
00091 
00092 
00093 static int traceback (lua_State *L) {
00094   if (!lua_isstring(L, 1))  /* 'message' not a string? */
00095     return 1;  /* keep it intact */
00096   lua_getfield(L, LUA_GLOBALSINDEX, "debug");
00097   if (!lua_istable(L, -1)) {
00098     lua_pop(L, 1);
00099     return 1;
00100   }
00101   lua_getfield(L, -1, "traceback");
00102   if (!lua_isfunction(L, -1)) {
00103     lua_pop(L, 2);
00104     return 1;
00105   }
00106   lua_pushvalue(L, 1);  /* pass error message */
00107   lua_pushinteger(L, 2);  /* skip this function and traceback */
00108   lua_call(L, 2, 1);  /* call debug.traceback */
00109   return 1;
00110 }
00111 
00112 
00113 static int docall (lua_State *L, int narg, int clear) {
00114   int status;
00115   int base = lua_gettop(L) - narg;  /* function index */
00116   lua_pushcfunction(L, traceback);  /* push traceback function */
00117   lua_insert(L, base);  /* put it under chunk and args */
00118   signal(SIGINT, laction);
00119   status = lua_pcall(L, narg, (clear ? 0 : LUA_MULTRET), base);
00120   signal(SIGINT, SIG_DFL);
00121   lua_remove(L, base);  /* remove traceback function */
00122   /* force a complete garbage collection in case of errors */
00123   if (status != 0) lua_gc(L, LUA_GCCOLLECT, 0);
00124   return status;
00125 }
00126 
00127 
00128 // luafaudes: my print version
00129 static void print_version (void) {
00130   std::stringstream sstr;
00131   sstr 
00132     << "Welcome to luafaudes console." << std::endl
00133     << "Versions: " << faudes::FDVersionString() << " / " << faudes::FDPluginsString() 
00134           << " / " << LUA_VERSION << std::endl
00135     << "Credits: This libFAUDES interpreter is based on the projects Lua and SWIG." << std::endl
00136     << "Type 'faudes.Help()' for a list of faudes related types and functions." << std::endl;
00137   l_message(NULL, sstr.str().c_str());
00138 }
00139 
00140 
00141 static int getargs (lua_State *L, char **argv, int n) {
00142   int narg;
00143   int i;
00144   int argc = 0;
00145   while (argv[argc]) argc++;  /* count total number of arguments */
00146   narg = argc - (n + 1);  /* number of arguments to the script */
00147   luaL_checkstack(L, narg + 3, "too many arguments to script");
00148   for (i=n+1; i < argc; i++)
00149     lua_pushstring(L, argv[i]);
00150   lua_createtable(L, narg, n + 1);
00151   for (i=0; i < argc; i++) {
00152     lua_pushstring(L, argv[i]);
00153     lua_rawseti(L, -2, i - n);
00154   }
00155   return narg;
00156 }
00157 
00158 
00159 static int dofile (lua_State *L, const char *name) {
00160   int status = luaL_loadfile(L, name) || docall(L, 0, 1);
00161   return report(L, status);
00162 }
00163 
00164 
00165 static int dostring (lua_State *L, const char *s, const char *name) {
00166   int status = luaL_loadbuffer(L, s, strlen(s), name) || docall(L, 0, 1);
00167   return report(L, status);
00168 }
00169 
00170 
00171 static int dolibrary (lua_State *L, const char *name) {
00172   lua_getglobal(L, "require");
00173   lua_pushstring(L, name);
00174   return report(L, docall(L, 1, 1));
00175 }
00176 
00177 
00178 /* ------------------------------------------------------------------------ */
00179 
00180 #ifdef LUA_USE_READLINE
00181 /*
00182 ** Advanced readline support for the GNU readline and history libraries
00183 ** or compatible replacements.
00184 **
00185 ** Copyright (C) 2004-2006 Mike Pall. Same license as Lua. See lua.h.
00186 **
00187 ** Advanced features:
00188 ** - Completion of keywords and global variable names.
00189 ** - Recursive and metatable-aware completion of variable names.
00190 ** - Context sensitive delimiter completion.
00191 ** - Save/restore of the history to/from a file (LUA_HISTORY env variable).
00192 ** - Setting a limit for the size of the history (LUA_HISTSIZE env variable).
00193 ** - Setting the app name to allow for $if lua ... $endif in ~/.inputrc.
00194 **
00195 ** Start lua and try these (replace ~ with the TAB key):
00196 **
00197 ** ~~
00198 ** fu~foo() ret~fa~end<CR>
00199 ** io~~~s~~~o~~~w~"foo\n")<CR>
00200 **
00201 ** The ~~ are just for demonstration purposes (io~s~o~w~ suffices, of course).
00202 **
00203 ** If you are used to zsh/tcsh-style completion support, try adding
00204 ** 'TAB: menu-complete' and 'C-d: possible-completions' to your ~/.inputrc.
00205 **
00206 ** The patch has been successfully tested with:
00207 **
00208 ** GNU    readline 2.2.1  (1998-07-17)
00209 ** GNU    readline 4.0    (1999-02-18) [harmless compiler warning]
00210 ** GNU    readline 4.3    (2002-07-16)
00211 ** GNU    readline 5.0    (2004-07-27)
00212 ** GNU    readline 5.1    (2005-12-07)
00213 ** NETBSD libedit  2.6.5  (2002-03-25)
00214 ** NETBSD libedit  2.6.9  (2004-05-01)
00215 */
00216 
00217 #include <ctype.h>
00218 
00219 static char *lua_rl_hist;
00220 static int lua_rl_histsize;
00221 
00222 static lua_State *lua_rl_L;  /* User data is not passed to rl callbacks. */
00223 
00224 /* Reserved keywords. */
00225 static const char *const lua_rl_keywords[] = {
00226   "and", "break", "do", "else", "elseif", "end", "false",
00227   "for", "function", "if", "in", "local", "nil", "not", "or",
00228   "repeat", "return", "then", "true", "until", "while", NULL
00229 };
00230 
00231 static int valididentifier(const char *s)
00232 {
00233   if (!(isalpha(*s) || *s == '_')) return 0;
00234   for (s++; *s; s++) if (!(isalpha(*s) || isdigit(*s) || *s == '_')) return 0;
00235   return 1;
00236 }
00237 
00238 /* Dynamically resizable match list. */
00239 typedef struct {
00240   char **list;
00241   size_t idx, allocated, matchlen;
00242 } dmlist;
00243 
00244 /* Add prefix + string + suffix to list and compute common prefix. */
00245 static int lua_rl_dmadd(dmlist *ml, const char *p, size_t pn, const char *s,
00246       int suf)
00247 {
00248   char *t = NULL;
00249 
00250   if (ml->idx+1 >= ml->allocated &&
00251       !(ml->list = (char **) realloc(ml->list, sizeof(char *) * (ml->allocated += 32)))  )
00252     return -1;
00253 
00254   if (s) {
00255     size_t n = strlen(s);
00256     if (!(t = (char *)malloc(sizeof(char)*(pn+n+(suf?2:1))))) return 1;
00257     memcpy(t, p, pn);
00258     memcpy(t+pn, s, n);
00259     n += pn;
00260     t[n] = suf;
00261     if (suf) t[++n] = '\0';
00262 
00263     if (ml->idx == 0) {
00264       ml->matchlen = n;
00265     } else {
00266       size_t i;
00267       for (i = 0; i < ml->matchlen && i < n && ml->list[1][i] == t[i]; i++) ;
00268       ml->matchlen = i;  /* Set matchlen to common prefix. */
00269     }
00270   }
00271 
00272   ml->list[++ml->idx] = t;
00273   return 0;
00274 }
00275 
00276 /* Get __index field of metatable of object on top of stack. */
00277 static int lua_rl_getmetaindex(lua_State *L)
00278 {
00279   if (!lua_getmetatable(L, -1)) { lua_pop(L, 1); return 0; }
00280   lua_pushstring(L, "__index");
00281   lua_rawget(L, -2);
00282   lua_replace(L, -2);
00283   if (lua_isnil(L, -1) || lua_rawequal(L, -1, -2)) { lua_pop(L, 2); return 0; }
00284   lua_replace(L, -2);
00285   return 1;
00286 }  /* 1: obj -- val, 0: obj -- */
00287 
00288 /* Get field from object on top of stack. Avoid calling metamethods. */
00289 static int lua_rl_getfield(lua_State *L, const char *s, size_t n)
00290 {
00291   int i = 20;  /* Avoid infinite metatable loops. */
00292   do {
00293     if (lua_istable(L, -1)) {
00294       lua_pushlstring(L, s, n);
00295       lua_rawget(L, -2);
00296       if (!lua_isnil(L, -1)) { lua_replace(L, -2); return 1; }
00297       lua_pop(L, 1);
00298     }
00299   } while (--i > 0 && lua_rl_getmetaindex(L));
00300   lua_pop(L, 1);
00301   return 0;
00302 }  /* 1: obj -- val, 0: obj -- */
00303 
00304 /* Completion callback. */
00305 static char **lua_rl_complete(const char *text, int start, int end)
00306 {
00307   lua_State *L = lua_rl_L;
00308   dmlist ml;
00309   const char *s;
00310   size_t i, n, dot, loop;
00311   int savetop;
00312 
00313   if (!(text[0] == '\0' || isalpha(text[0]) || text[0] == '_')) return NULL;
00314 
00315   ml.list = NULL;
00316   ml.idx = ml.allocated = ml.matchlen = 0;
00317 
00318   savetop = lua_gettop(L);
00319   lua_pushvalue(L, LUA_GLOBALSINDEX);
00320   for (n = (size_t)(end-start), i = dot = 0; i < n; i++)
00321     if (text[i] == '.' || text[i] == ':') {
00322       if (!lua_rl_getfield(L, text+dot, i-dot))
00323   goto error;  /* Invalid prefix. */
00324       dot = i+1;  /* Points to first char after dot/colon. */
00325     }
00326 
00327   /* Add all matches against keywords if there is no dot/colon. */
00328   if (dot == 0)
00329     for (i = 0; (s = lua_rl_keywords[i]) != NULL; i++)
00330       if (!strncmp(s, text, n) && lua_rl_dmadd(&ml, NULL, 0, s, ' '))
00331   goto error;
00332 
00333   /* Add all valid matches from all tables/metatables. */
00334   loop = 0;  /* Avoid infinite metatable loops. */
00335   do {
00336     if (lua_istable(L, -1) &&
00337   (loop == 0 || !lua_rawequal(L, -1, LUA_GLOBALSINDEX)))
00338       for (lua_pushnil(L); lua_next(L, -2); lua_pop(L, 1))
00339   if (lua_type(L, -2) == LUA_TSTRING) {
00340     s = lua_tostring(L, -2);
00341     /* Only match names starting with '_' if explicitly requested. */
00342     if (!strncmp(s, text+dot, n-dot) && valididentifier(s) &&
00343         (*s != '_' || text[dot] == '_')) {
00344       int suf = ' ';  /* Default suffix is a space. */
00345       switch (lua_type(L, -1)) {
00346       case LUA_TTABLE:  suf = '.'; break;  /* No way to guess ':'. */
00347       case LUA_TFUNCTION: suf = '('; break;
00348       case LUA_TUSERDATA:
00349         if (lua_getmetatable(L, -1)) { lua_pop(L, 1); suf = ':'; }
00350         break;
00351       }
00352       if (lua_rl_dmadd(&ml, text, dot, s, suf)) goto error;
00353     }
00354   }
00355   } while (++loop < 20 && lua_rl_getmetaindex(L));
00356 
00357   if (ml.idx > 1) {
00358     /* list[0] holds the common prefix of all matches (may be ""). */
00359     if (!(ml.list[0] = (char *)malloc(sizeof(char)*(ml.matchlen+1)))) {
00360 error:
00361       lua_settop(L, savetop);
00362       return NULL;
00363     }
00364     memcpy(ml.list[0], ml.list[1], ml.matchlen);
00365     ml.list[0][ml.matchlen] = '\0';
00366     /* Add the NULL list terminator. */
00367     if (lua_rl_dmadd(&ml, NULL, 0, NULL, 0)) goto error;
00368   } else if (ml.idx == 1) {
00369     ml.list[0] = ml.list[1];  /* Only return common prefix. */
00370     ml.list[1] = NULL;
00371   }
00372 
00373   lua_settop(L, savetop);
00374   return ml.list;
00375 }
00376 
00377 /* Initialize readline library. */
00378 static void lua_rl_init(lua_State *L)
00379 {
00380   char *s;
00381 
00382   lua_rl_L = L;
00383 
00384   /* This allows for $if lua ... $endif in ~/.inputrc. */
00385   rl_readline_name = "lua";
00386   /* Break words at every non-identifier character except '.' and ':'. */
00387   rl_completer_word_break_characters = 
00388     "\t\r\n !\"#$%&'()*+,-/;<=>?@[\\]^`{|}~";
00389   rl_completer_quote_characters = "\"'";
00390   rl_completion_append_character = '\0';
00391   rl_attempted_completion_function = lua_rl_complete;
00392   rl_initialize();
00393 
00394   /* Start using history, optionally set history size and load history file. */
00395   using_history();
00396   if ((s = getenv("LUA_HISTSIZE")) &&
00397       (lua_rl_histsize = atoi(s))) stifle_history(lua_rl_histsize);
00398   if ((lua_rl_hist = getenv("LUA_HISTORY"))) read_history(lua_rl_hist);
00399 }
00400 
00401 /* Finalize readline library. */
00402 static void lua_rl_exit(lua_State *L)
00403 {
00404   /* Optionally save history file. */
00405   if (lua_rl_hist) write_history(lua_rl_hist);
00406 }
00407 #else
00408 #define lua_rl_init(L)    ((void)L)
00409 #define lua_rl_exit(L)    ((void)L)
00410 #endif
00411 
00412 /* ------------------------------------------------------------------------ */
00413 
00414 
00415 static const char *get_prompt (lua_State *L, int firstline) {
00416   const char *p;
00417   lua_getfield(L, LUA_GLOBALSINDEX, firstline ? "_PROMPT" : "_PROMPT2");
00418   p = lua_tostring(L, -1);
00419   if (p == NULL) p = (firstline ? LUA_PROMPT : LUA_PROMPT2);
00420   lua_pop(L, 1);  /* remove global */
00421   return p;
00422 }
00423 
00424 
00425 static int incomplete (lua_State *L, int status) {
00426   if (status == LUA_ERRSYNTAX) {
00427     size_t lmsg;
00428     const char *msg = lua_tolstring(L, -1, &lmsg);
00429     const char *tp = msg + lmsg - (sizeof(LUA_QL("<eof>")) - 1);
00430     if (strstr(msg, LUA_QL("<eof>")) == tp) {
00431       lua_pop(L, 1);
00432       return 1;
00433     }
00434   }
00435   return 0;  /* else... */
00436 }
00437 
00438 
00439 static int pushline (lua_State *L, int firstline) {
00440   char buffer[LUA_MAXINPUT];
00441   char *b = buffer;
00442   size_t l;
00443   const char *prmt = get_prompt(L, firstline);
00444   if (lua_readline(L, b, prmt) == 0)
00445     return 0;  /* no input */
00446   l = strlen(b);
00447   luafaudes_lastline=b; // luafaudes: logging
00448   if (l > 0 && b[l-1] == '\n')  /* line ends with newline? */
00449     b[l-1] = '\0';  /* remove it */
00450   if (firstline && b[0] == '=')  /* first line starts with `=' ? */
00451     lua_pushfstring(L, "return %s", b+1);  /* change it to `return' */
00452   else
00453     lua_pushstring(L, b);
00454   lua_freeline(L, b);
00455   return 1;
00456 }
00457 
00458 
00459 static int loadline (lua_State *L) {
00460   int status;
00461   lua_settop(L, 0);
00462   if (!pushline(L, 1))
00463     return -1;  /* no input */
00464   for (;;) {  /* repeat until gets a complete line */
00465     status = luaL_loadbuffer(L, lua_tostring(L, 1), lua_strlen(L, 1), "=stdin");
00466     if (!incomplete(L, status)) break;  /* cannot try to add lines? */
00467     if (!pushline(L, 0))  /* no more input? */
00468       return -1;
00469     lua_pushliteral(L, "\n");  /* add a new line... */
00470     lua_insert(L, -2);  /* ...between the two lines */
00471     lua_concat(L, 3);  /* join them */
00472   }
00473   lua_saveline(L, 1);
00474   lua_remove(L, 1);  /* remove line */
00475   return status;
00476 }
00477 
00478 
00479 static void dotty (lua_State *L) {
00480   int status;
00481   const char *oldprogname = progname;
00482   progname = NULL;
00483   lua_rl_init(L);
00484   while ((status = loadline(L)) != -1) {
00485     if (status == 0) status = docall(L, 0, 0);
00486     luafaudes_logwrite(luafaudes_lastline); // luafaudes: logging 
00487     report(L, status);
00488     if (status == 0 && lua_gettop(L) > 0) {  /* any result to print? */
00489       lua_getglobal(L, "print");
00490       lua_insert(L, 1);
00491       if (lua_pcall(L, lua_gettop(L)-1, 0, 0) != 0)
00492         l_message(progname, lua_pushfstring(L,
00493                                "error calling " LUA_QL("print") " (%s)",
00494                                lua_tostring(L, -1)));
00495     }
00496   }
00497   lua_settop(L, 0);  /* clear stack */
00498   fputs("\n", stdout);
00499   fflush(stdout);
00500   lua_rl_exit(L);
00501   progname = oldprogname;
00502 }
00503 
00504 static int handle_script (lua_State *L, char **argv, int n) {
00505   int status;
00506   const char *fname;
00507   int narg = getargs(L, argv, n);  /* collect arguments */
00508   lua_setglobal(L, "arg");
00509   fname = argv[n];
00510   if (strcmp(fname, "-") == 0 && strcmp(argv[n-1], "--") != 0) 
00511     fname = NULL;  /* stdin */
00512   status = luaL_loadfile(L, fname);
00513   lua_insert(L, -(narg+1));
00514   if (status == 0)
00515     status = docall(L, narg, 0);
00516   else
00517     lua_pop(L, narg);      
00518   return report(L, status);
00519 }
00520 
00521 
00522 /* check that argument has no extra characters at the end */
00523 #define notail(x) {if ((x)[2] != '\0') return -1;}
00524 
00525 
00526 static int collectargs (char **argv, int *pi, int *pv, int *pe) {
00527   int i;
00528   for (i = 1; argv[i] != NULL; i++) {
00529     if (argv[i][0] != '-')  /* not an option? */
00530         return i;
00531     switch (argv[i][1]) {  /* option */
00532       case '-':
00533         notail(argv[i]);
00534         return (argv[i+1] != NULL ? i+1 : 0);
00535       case '\0':
00536         return i;
00537       case 'i':
00538         notail(argv[i]);
00539         *pi = 1;  /* go through */
00540       case 'v':
00541         notail(argv[i]);
00542         *pv = 1;
00543         break;
00544       case 'e':
00545         *pe = 1;  /* go through */
00546       case 'l':
00547         if (argv[i][2] == '\0') {
00548           i++;
00549           if (argv[i] == NULL) return -1;
00550         }
00551         break;
00552       default: return -1;  /* invalid option */
00553     }
00554   }
00555   return 0;
00556 }
00557 
00558 
00559 static int runargs (lua_State *L, char **argv, int n) {
00560   int i;
00561   for (i = 1; i < n; i++) {
00562     if (argv[i] == NULL) continue;
00563     lua_assert(argv[i][0] == '-');
00564     switch (argv[i][1]) {  /* option */
00565       case 'e': {
00566         const char *chunk = argv[i] + 2;
00567         if (*chunk == '\0') chunk = argv[++i];
00568         lua_assert(chunk != NULL);
00569         if (dostring(L, chunk, "=(command line)") != 0)
00570           return 1;
00571         break;
00572       }
00573       case 'l': {
00574         const char *filename = argv[i] + 2;
00575         if (*filename == '\0') filename = argv[++i];
00576         lua_assert(filename != NULL);
00577         if (dolibrary(L, filename))
00578           return 1;  /* stop if file fails */
00579         break;
00580       }
00581       default: break;
00582     }
00583   }
00584   return 0;
00585 }
00586 
00587 
00588 static int handle_luainit (lua_State *L) {
00589   const char *init = getenv(LUA_INIT);
00590   if (init == NULL) return 0;  /* status OK */
00591   else if (init[0] == '@')
00592     return dofile(L, init+1);
00593   else
00594     return dostring(L, init, "=" LUA_INIT);
00595 }
00596 
00597 
00598 struct Smain {
00599   int argc;
00600   char **argv;
00601   int status;
00602 };
00603 
00604 
00605 static int pmain (lua_State *L) {
00606   struct Smain *s = (struct Smain *)lua_touserdata(L, 1);
00607   char **argv = s->argv;
00608   int script;
00609   int has_i = 0, has_v = 0, has_e = 0;
00610   globalL = L;
00611   if (argv[0] && argv[0][0]) progname = argv[0];
00612   lua_gc(L, LUA_GCSTOP, 0);  /* stop collector during initialization */
00613   luaL_openlibs(L);  /* open libraries */
00614   luaopen_faudes_allplugins(L); // luafaudes: register
00615   luafaudes_dotready(); // luafaudes: test dot
00616   lua_gc(L, LUA_GCRESTART, 0);
00617   s->status = handle_luainit(L);
00618   if (s->status != 0) return 0;
00619   script = collectargs(argv, &has_i, &has_v, &has_e);
00620   if (script < 0) {  /* invalid args? */
00621     print_usage();
00622     s->status = 1;
00623     return 0;
00624   }
00625   if (has_v) print_version(); 
00626   s->status = runargs(L, argv, (script > 0) ? script : s->argc);
00627   if (s->status != 0) return 0;
00628   if (script)
00629     s->status = handle_script(L, argv, script);
00630   if (s->status != 0) return 0;
00631   if (has_i)
00632     dotty(L);
00633   else if (script == 0 && !has_e && !has_v) {
00634     if (lua_stdin_is_tty()) {
00635       print_version(); 
00636       dotty(L);
00637     }
00638     else dofile(L, NULL);  /* executes stdin as a file */
00639   }
00640   return 0;
00641 }
00642 
00643 
00644 int main (int argc, char **argv) {
00645   int status;
00646   struct Smain s;
00647   lua_State *L = lua_open();  /* create state */
00648   if (L == NULL) {
00649     l_message(argv[0], "cannot create state: not enough memory");
00650     return EXIT_FAILURE;
00651   }
00652   s.argc = argc;
00653   s.argv = argv;
00654   status = lua_cpcall(L, &pmain, &s);
00655   report(L, status);
00656   lua_close(L);
00657   return (status || s.status) ? EXIT_FAILURE : EXIT_SUCCESS;
00658 }
00659 
00660 
00661 // luafaudes: end skip doxygen
00662 #endif

libFAUDES 2.14g --- 2009-12-3 --- c++ source docu by doxygen 1.5.6