Exemple #1
0
int
main ()
{
  object *env = init_env ();
  print_version ();
  doREPL (&env);
  free_object (env);
  return 0;
}
/*
** Main body of stand-alone interpreter (to be called in protected mode).
** Reads the options and handles them all.
*/
static int pmain (lua_State *L) {
  int argc = (int)lua_tointeger(L, 1);
  char **argv = (char **)lua_touserdata(L, 2);
  int script;
  int args = collectargs(argv, &script);
  luaL_checkversion(L);  /* check that interpreter has correct version */
  if (argv[0] && argv[0][0]) progname = argv[0];
#if 0
  if (args == has_error) {  /* bad arg? */
    print_usage(argv[script]);  /* 'script' has index of bad arg. */
    return 0;
  }
#endif
  if (args & has_v)  /* option '-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");
  }
  luaL_openlibs(L);  /* open standard libraries */
  createargtable(L, argv, argc, script);  /* create table 'arg' */
  if (!(args & has_E)) {  /* no option '-E'? */
    if (handle_luainit(L) != LUA_OK)  /* run LUA_INIT */
      return 0;  /* error running LUA_INIT */
  }
  if (!runargs(L, argv, script))  /* execute arguments -e and -l */
    return 0;  /* something failed */
  if (script < argc &&  /* execute main script (if there is one) */
      handle_script(L, argv + script) != LUA_OK)
    return 0;
#if 0
  if (args & has_i)  /* -i option? */
    doREPL(L);  /* do read-eval-print loop */
  else if (script == argc && !(args & (has_e | has_v))) {  /* no arguments? */
    if (lua_stdin_is_tty()) {  /* running in interactive mode? */
      print_version();
      doREPL(L);  /* do read-eval-print loop */
    }
    else dofile(L, NULL);  /* executes stdin as a file */
  }
#endif
  lua_pushboolean(L, 1);  /* signal no errors */
  return 1;
}
Exemple #3
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 = collectargs(argv, &script);
  luaL_checkversion(L);  /* 检查解释器的版本*/
  if (argv[0] && argv[0][0]) progname = argv[0];
  if (args == has_error) {  /* 坏变量? */
    print_usage(argv[script]);  /* '脚本'存在坏的变量 */
    return 0;
  }
  if (args & has_v)  /* 带有选项参数 '-v'? */
    print_version();
  if (args & has_E) {  /* 带有选项参数 '-E'? */
    lua_pushboolean(L, 1);  /* signal for libraries to ignore env. vars. */
    lua_setfield(L, LUA_REGISTRYINDEX, "LUA_NOENV");
  }
  luaL_openlibs(L);  /* 打开标准库 */
  createargtable(L, argv, argc, script);  /* 创建表 'arg' */
  if (!(args & has_E)) {  /* 没有选项'-E'? */
    if (handle_luainit(L) != LUA_OK)  /* 执行LUA_INIT */
      return 0;  /* error running LUA_INIT */
  }
  if (!runargs(L, argv, script))  /* 执行选项参数 -e and -l */
    return 0;  /* something failed */
  if (script < argc &&  /**************************************** 执行主脚本 (如果有一个),这里是重点 *************************************/
      handle_script(L, argv + script) != LUA_OK)
    return 0;
  if (args & has_i)  /* -i 选项参数? */
    doREPL(L);  /* do read-eval-print loop 交互模式,即读取->运算->输出循环 */
  else if (script == argc && !(args & (has_e | has_v))) {  /* 没有参数? */
    if (lua_stdin_is_tty()) {  /* 交互模式运行? */
      print_version();
      doREPL(L);  /* do read-eval-print loop   交互模式,即读取->运算->输出循环*/
    }
    else dofile(L, NULL);  /* 执行stdin as a file */
  }
  lua_pushboolean(L, 1);  /* signal no errors */
  return 1;
}
Exemple #4
0
/*
** Main body of stand-alone interpreter (to be called in protected mode).
** Reads the options and handles them all.
*/
static int pmain (lua_State *L) {
  luaL_checkversion(L);  /* check that interpreter has correct version */

  lua_pushboolean(L, 1);  /* signal for libraries to ignore env. vars. */
  lua_setfield(L, LUA_REGISTRYINDEX, "LUA_NOENV");

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

  print_version();
  doREPL(L);  /* do read-eval-print loop */

  lua_pushboolean(L, 1);  /* signal no errors */
  return 1;
}
Exemple #5
0
void lua_main(void)
{
	//l_message("lua", "welcome !!!\n");
	
  lua_State *L = luaL_newstate();  /* create state */
  if (L == NULL) {
    l_message("lua", "cannot create state: not enough memory\n");
    return ;
  }
	luaL_openlibs(L);
	print_version();
	//dostring(L,"print('hello')","Test_lua");
	//dofile(L, NULL);  /* executes stdin as a file */
	doREPL(L);
	
  lua_close(L);
}