Example #1
0
int main (int argc, char **argv) 
{
  lua_State *L = luaL_newstate();  /* create state */

  luaL_openlibs(L);  /* open standard libraries */

  iuplua_openlibs(L);

  createargtable(L, argv, argc);  /* create table 'arg' */

  iuplua_input(L);

  lua_close(L);
  return EXIT_SUCCESS;
}
Example #2
0
static int pmain (lua_State *L) {
  int argc = (int)lua_tointeger(L, 1);
  char **argv = (char **)lua_touserdata(L, 2);
  int script;
  int args[num_has];
  args[has_i] = args[has_v] = args[has_e] = args[has_E] = 0;
  if (argv[0] && argv[0][0]) progname = argv[0];
  script = collectargs(argv, args);
  if (script < 0) {  /* invalid arg? */
    print_usage(argv[-script]);
    return 0;
  }
  if (args[has_v]) print_version();
  if (args[has_E]) {  /* option '-E'? */
    lua_pushboolean(L, 1);  /* signal for libraries to ignore env. vars. */
    lua_setfield(L, LUA_REGISTRYINDEX, "LUA_NOENV");
  }
  /* open standard libraries */
  luaL_checkversion(L);
  lua_gc(L, LUA_GCSTOP, 0);  /* stop collector during initialization */
  luaL_openlibs(L);  /* open libraries */
  lua_gc(L, LUA_GCRESTART, 0);
/******************* IUP *********************/
  iuplua_openlibs(L);
/******************* IUP *********************/
  if (!args[has_E] && handle_luainit(L) != LUA_OK)
    return 0;  /* error running LUA_INIT */
  /* execute arguments -e and -l */
  if (!runargs(L, argv, (script > 0) ? script : argc)) return 0;
  /* execute main script (if there is one) */
  if (script && handle_script(L, argv, script) != LUA_OK) return 0;
  if (args[has_i])  /* -i option? */
    dotty(L);
  else if (script == 0 && !args[has_e] && !args[has_v]) {  /* no arguments? */
    if (lua_stdin_is_tty()) {
      print_version();
/******************* IUP *********************/
/*    dotty(L);                              */
      iuplua_input(L);
/******************* IUP *********************/
    }
    else dofile(L, NULL);  /* executes stdin as a file */
  }
  lua_pushboolean(L, 1);  /* signal no errors */
  return 1;
}
Example #3
0
static int pmain (lua_State *L) {
  struct Smain *s = (struct Smain *)lua_touserdata(L, 1);
  char **argv = s->argv;
  int script;
  int has_i = 0, has_v = 0, has_e = 0;
  globalL = L;
  if (argv[0] && argv[0][0]) progname = argv[0];
  lua_gc(L, LUA_GCSTOP, 0);  /* stop collector during initialization */
  luaL_openlibs(L);  /* open libraries */
  lua_gc(L, LUA_GCRESTART, 0);
/******************* IUP *********************/
  iuplua_openlibs(L);
/******************* IUP *********************/

  s->status = handle_luainit(L);
  if (s->status != 0) return 0;
  script = collectargs(argv, &has_i, &has_v, &has_e);
  if (script < 0) {  /* invalid args? */
    print_usage();
    s->status = 1;
    return 0;
  }
  if (has_v) print_version();
  s->status = runargs(L, argv, (script > 0) ? script : s->argc);
  if (s->status != 0) return 0;
  if (script)
    s->status = handle_script(L, argv, script);
  if (s->status != 0) return 0;
  if (has_i)
    dotty(L);
  else if (script == 0 && !has_e && !has_v) {
    if (lua_stdin_is_tty()) {
      print_version();
/******************* IUP *********************/
/*    dotty(L);                              */
      iuplua_input(L);
/******************* IUP *********************/
    }
    else dofile(L, NULL);  /* executes stdin as a file */
  }
  return 0;
}
Example #4
0
static int pmain (lua_State *L) {
  int argc = lua_tointeger(L, 1);
  char **argv = (char **)lua_touserdata(L, 2);
  int script;
  int has_i = 0, has_v = 0, has_e = 0;
  if (argv[0] && argv[0][0]) progname = argv[0];
  script = collectargs(argv, &has_i, &has_v, &has_e);
  if (script < 0) {  /* invalid args? */
    print_usage();
    return 0;
  }
  if (has_v) print_version();
  /* open standard libraries */
  luaL_checkversion(L);
  lua_gc(L, LUA_GCSTOP, 0);  /* stop collector during initialization */
  luaL_openlibs(L);  /* open libraries */
  lua_gc(L, LUA_GCRESTART, 0);
/******************* IUP *********************/
  iuplua_openlibs(L);
/******************* IUP *********************/
  /* run LUA_INIT */
  if (handle_luainit(L) != LUA_OK) return 0;
  /* execute arguments -e and -l */
  if (!runargs(L, argv, (script > 0) ? script : argc)) return 0;
  /* execute main script (if there is one) */
  if (script && handle_script(L, argv, script) != LUA_OK) return 0;
  if (has_i)  /* -i option? */
    dotty(L);
  else if (script == 0 && !has_e && !has_v) {  /* no arguments? */
    if (lua_stdin_is_tty()) {
      print_version();
/******************* IUP *********************/
/*    dotty(L);                              */
      iuplua_input(L);
/******************* IUP *********************/
    }
    else dofile(L, NULL);  /* executes stdin as a file */
  }
  lua_pushboolean(L, 1);  /* signal no errors */
  return 1;
}