Beispiel #1
0
int main (int argc, char **argv) {
  int status, result;
  lua_State *L = luaL_newstate();  /* create state */
  if (L == NULL) {
    l_message(argv[0], "cannot create state: not enough memory");
    return EXIT_FAILURE;
  }
  /* call 'pmain' in protected mode */
  lua_pushcfunction(L, &pmain);
  lua_pushinteger(L, argc);  /* 1st argument */
  lua_pushlightuserdata(L, argv); /* 2nd argument */
  status = lua_pcall(L, 2, 1, 0);
  result = lua_toboolean(L, -1);  /* get result */
  finalreport(L, status);
  lua_close(L);
  return (result && status == LUA_OK) ? EXIT_SUCCESS : EXIT_FAILURE;
}
Beispiel #2
0
int main (int argc, char **argv) {
  static lua_CFunction ppmain = &pmain;
  int status, result;
  lua_State *L = luaL_newstate();  /* create state */
  if (L == NULL) {
    l_message(argv[0], "cannot create state: not enough memory");
    return EXIT_FAILURE;
  }
  /* call 'pmain' in protected mode */
  lua_rawgeti(L, LUA_REGISTRYINDEX, LUA_RIDX_CPCALL);  /* calling function */
  lua_pushlightuserdata(L, &ppmain);
  lua_pushinteger(L, argc); 
  lua_pushlightuserdata(L, argv);
  status = lua_pcall(L, 3, 1, 0);
  result = lua_toboolean(L, -1);  /* get result */
  finalreport(L, status);
  lua_close(L);
  return (result && status == LUA_OK) ? EXIT_SUCCESS : EXIT_FAILURE;
}
Beispiel #3
0
int lua_shell(void * pServer) {
	int status, result;
	lua_State *L;

	L = luaL_newstate(); /* create state */
	if (L == NULL ) {
		l_message(L, "Lua-Shell", "cannot create state: not enough memory");
		return EXIT_FAILURE;
	}
	luaL_setprivate(L, pServer);

	/* call 'pmain' in protected mode */
	lua_pushcfunction(L, &pmain);
	status = lua_pcall(L, 0, 1, 0);
	result = lua_toboolean(L, -1);	/* get result */
	finalreport(L, status);
	lua_close(L);

	return (result && status == LUA_OK) ? EXIT_SUCCESS : EXIT_FAILURE;
}
Beispiel #4
0
int main (int argc, char **argv) {
  jxutils::SetExeDirectoryAsCurrentDirW();
  char* temp[2];
  temp[0] = argv[0];
  temp[1] = "../Data/lua_files/print.lua";
  argc = 2;/*total number of arguments */

  int status, result;
  lua_State *L = luaL_newstate();  /* create state */
  if (L == NULL) {
    l_message(argv[0], "cannot create state: not enough memory");
    return EXIT_FAILURE;
  }
  /* call 'pmain' in protected mode */
  lua_pushcfunction(L, &pmain);
  lua_pushinteger(L, argc);  /* 1st argument */
  lua_pushlightuserdata(L, temp); /* 2nd argument */
  status = lua_pcall(L, 2, 1, 0);
  result = lua_toboolean(L, -1);  /* get result */
  finalreport(L, status);
  getchar();
  lua_close(L);
  return (result && status == LUA_OK) ? EXIT_SUCCESS : EXIT_FAILURE;
}