示例#1
0
文件: bench.c 项目: nrnrnr/noweb3
int main (int argc, char *argv[])
{
  int i;
  int result = 0;
  iolib_open ();
  strlib_open ();
  mathlib_open ();
  if (argc < 2) {
    fprintf(stderr, "Usage: %s <filename> <arguments>\n", argv[0]);
    exit(1);
  } else {
    lua_Object lua_arg;
    lua_arg = lua_createtable();
    for (i=2; i<argc; i++) {
      lua_pushobject(lua_arg);
      lua_pushnumber((double)(i-1));
      lua_pushstring(argv[i]);
      lua_storesubscript();
    }
    lua_pushobject(lua_arg);
    lua_storeglobal("arg");
    result = lua_dofile (argv[1]);
    if (result) {
      if (result == 2) {
        fprintf(stderr, "lua: cannot execute file `%s' - ", argv[i]);
        perror(NULL);
      }
      return 1;
    }
  }
  return result;
}
示例#2
0
int main (int argc, char *argv[])
{
    int i;
    int result = 0;
    iolib_open ();
    strlib_open ();
    mathlib_open ();

    lua_register("argv", lua_getargv);

    if (argc < 2)
        manual_input();
    else
    {
        for (i=1; i<argc; i++)
            if (strcmp(argv[i], "--") == 0)
            {
                lua_argc = argc-i-1;
                lua_argv = argv+i;
                break;
            }
        for (i=1; i<argc; i++)
        {
            if (strcmp(argv[i], "--") == 0)
                break;
            else if (strcmp(argv[i], "-") == 0)
                manual_input();
            else if (strcmp(argv[i], "-v") == 0)
                printf("%s  %s\n(written by %s)\n\n",
                       LUA_VERSION, LUA_COPYRIGHT, LUA_AUTHORS);
            else
            {
                result = lua_dofile (argv[i]);
                if (result)
                    fprintf(stderr, "lua: error trying to run file %s\n", argv[i]);
            }
        }
    }
    return result;
}
示例#3
0
int main (int argc, char *argv[])
{
 int i;
 int result = 0;
 iolib_open ();
 strlib_open ();
 mathlib_open ();

 lua_register("argv", lua_getargv);

 if (argc < 2)
 {
   char buffer[250];
   while (gets(buffer) != 0)
     result = lua_dostring(buffer);
 }
 else
 {
  for (i=1; i<argc; i++)
  {
   if (strcmp(argv[i], "--") == 0)
   {
    lua_argc = argc-i-1;
    lua_argv = argv+i;
    break;
   }
  }
  for (i=1; i<argc; i++)
  {
   if (strcmp(argv[i], "--") == 0)
    break;
   else
    result = lua_dofile (argv[i]);
  }
 }
 return result;
}