Example #1
0
/* the next function is called unprotected, so it must avoid errors */
static void finalreport(lua_State *L, int status) 
{
	if (status != LUA_OK) {
		const char *msg = (lua_type(L, -1) == LUA_TSTRING) ? lua_tostring(L, -1)
			: NULL;
		if (msg == NULL) msg = "(error object is not a string)";
		l_message(progname, msg);
		lua_pop(L, 1);
	}
}
Example #2
0
File: main.c Project: lzubiaur/woot
static int report(lua_State *L, int status)
{
  if (status && !lua_isnil(L, -1)) {
    const char *msg = lua_tostring(L, -1);
    if (msg == NULL) msg = "(error object is not a string)";
    l_message(NULL, msg);
    lua_pop(L, 1);
  }
  return status;
}
Example #3
0
static int report (int status) {
  const char *msg;
  if (status) {
    msg = lua_tostring(L, -1);
    if (msg == NULL) msg = "(error with no message)";
    l_message(progname, msg);
    lua_pop(L, 1);
  }
  return status;
}
Example #4
0
/*
** Prints (calling the Lua 'print' function) any values on the stack
*/
static void l_print (lua_State *L) {
  int n = lua_gettop(L);
  if (n > 0) {  /* any result to be printed? */
    luaL_checkstack(L, LUA_MINSTACK, "too many results to print");
    lua_getglobal(L, "print");
    lua_insert(L, 1);
    if (lua_pcall(L, n, 0, 0) != LUA_OK)
      l_message(progname, lua_pushfstring(L, "error calling 'print' (%s)",
                                             lua_tostring(L, -1)));
  }
}
Example #5
0
static int report (lua_State *L, int status) {
  if (status != LUA_OK && !lua_isnil(L, -1)) {
    const char *msg = lua_tostring(L, -1);
    if (msg == NULL) msg = "(error object is not a string)";
    l_message(progname, msg);
    lua_pop(L, 1);
    /* force a complete garbage collection in case of errors */
    lua_gc(L, LUA_GCCOLLECT, 0);
  }
  return status;
}
Example #6
0
static int report (lua_State *L, int status) {
  if (status && !lua_isnil(L, -1)) {
    const char *msg = lua_tostring(L, -1);
    if (msg == NULL) msg = "(error object is not a string)";
#if !defined(TEK_LIB_EXEC_SILENT)
    l_message(TEK_LIB_EXEC_PROGNAME, msg);
#endif
    lua_pop(L, 1);
  }
  return status;
}
int language_report(lua_State *_L, int status)
{
    lua_State *L = parser_L;
    if (status && !lua_isnil(L, -1)) {
        const char *msg = lua_tostring(L, -1);
        if (msg == NULL) msg = "(error object is not a string)";
        l_message("<luajit-lang-toolkit parser>", msg);
        lua_pop(L, 1);
    }
    return status;
}
Example #8
0
static int report(lua_State *L, int status)
{
    if (status && !lua_isnil(L, -1)) {
        const char *msg = lua_tostring(L, -1);
        if (msg == NULL)
            msg = "(error object is not a string)";
        l_message(progname, msg);
        lua_pop(L, 1);
    }
    fflush(stdout);
    fflush(stderr);
    return status;
}
Example #9
0
//table = file.list()
static int file_slist( lua_State* L )
{
  spiffs_DIR d;
  struct spiffs_dirent e;
  struct spiffs_dirent *pe = &e;
  char buff[LUAL_BUFFERSIZE];
  SPIFFS_opendir(&fs, "/", &d);
  while ((pe = SPIFFS_readdir(&d, pe))) {
    sprintf(buff," %s size:%i\r\n", pe->name, pe->size);
    l_message(NULL,buff);
  }
  SPIFFS_closedir(&d);
  return 1;
}
Example #10
0
static void redirect_stdio() {
	char *stdoutpath, *stderrpath;

	stdoutpath = malloc(PATH_MAX+1);
	if (!stdoutpath) {
		l_message("Error", "malloc failure for stdoutpath");
		exit(-1);
	}
	stderrpath = malloc(PATH_MAX+1);
	if (!stderrpath) {
		l_message("Error", "stderrpath failure for binpath");
		exit(-1);
	}

	get_stdout_file_path(stdoutpath);
	get_stderr_file_path(stderrpath);
    	
	freopen(stdoutpath, TEXT("w"), stdout);
	freopen(stderrpath, TEXT("w"), stderr);
	
	free(stdoutpath);
	free(stderrpath);
}
Example #11
0
/**
**  Check error status, and print error message and exit
**  if status is different of 0.
**
**  @param status       status of the last lua call. (0: success)
**  @param exitOnError  exit the program on error
**
**  @return             0 in success, else exit.
*/
static int report(int status, bool exitOnError)
{
	const char *msg;

	if (status) {
		msg = lua_tostring(Lua, -1);
		if (msg == NULL) {
			msg = "(error with no message)";
		}
		l_message(NULL, msg, exitOnError);
		lua_pop(Lua, 1);
	}
	return status;
}
Example #12
0
//=================================
static int https_on( lua_State* L )
{
	size_t sl;
    const char *method = NULL;

	method = luaL_checklstring( L, 1, &sl );
	if (method == NULL) {
	  l_message(NULL, "Method string expected" );
	  return 0;
	}

	if ((lua_type(L, 2) == LUA_TFUNCTION) || (lua_type(L, 2) == LUA_TLIGHTFUNCTION))
	  lua_pushvalue(L, 2);
	else {
	  l_message(NULL, "Function arg expected" );
	  return 0;
	}

	if (strcmp(method,"response") == 0) {
		if (g_https_response_cb_ref != LUA_NOREF) {
			luaL_unref(L, LUA_REGISTRYINDEX, g_https_response_cb_ref);
		}
		g_https_response_cb_ref = luaL_ref(L, LUA_REGISTRYINDEX);
	}
	else if (strcmp(method,"header") == 0) {
		if (g_https_header_cb_ref != LUA_NOREF) {
			luaL_unref(L, LUA_REGISTRYINDEX, g_https_header_cb_ref);
		}
		g_https_header_cb_ref = luaL_ref(L, LUA_REGISTRYINDEX);
	}
	else {
	  lua_pop(L, 1);
	  l_message(NULL, "Unknown method" );
	}

	return 0;
}
Example #13
0
static int report (lua_State *L, int status) {
  if (status && !lua_isnil(L, -1)) {
  	const char *msg;
    if (lua_istable(L, -1)) {
      lua_getfield(L, LUA_GLOBALSINDEX, "tostring");
      lua_insert(L, -2);
      lua_call(L, 1, 1);
    }
    msg = lua_tostring(L, -1);
    if (msg == NULL) msg = "(error object is not a string)";
    l_message(progname, msg);
    lua_pop(L, 1);
  }
  return status;
}
Example #14
0
int main(int argc, char **argv)
{
  int status;
  lua_State *L = lua_open();  /* create state */
  if (L == NULL) {
    l_message(argv[0], "cannot create state: not enough memory");
    return EXIT_FAILURE;
  }
  smain.argc = argc;
  smain.argv = argv;
  status = lua_cpcall(L, pmain, NULL);
  report(L, status);
  lua_close(L);
  return (status || smain.status) ? EXIT_FAILURE : EXIT_SUCCESS;
}
Example #15
0
int main (int argc, char *argv[]) {
  int status;
  struct Smain s;
  lua_State *l = lua_open();  /* create state */
  if (l == NULL) {
    l_message(argv[0], "cannot create state: not enough memory");
    return EXIT_FAILURE;
  }
  s.argc = argc;
  s.argv = argv;
  status = lua_cpcall(l, &pmain, &s);
  report(status);
  lua_close(l);
  return (status || s.status) ? EXIT_FAILURE : EXIT_SUCCESS;
}
Example #16
0
int main (int argc, char **argv) {
  int status, result;
  lua_State *L = luaL_newstate();  /* 创新新的lua_State */
  if (L == NULL) {
    l_message(argv[0], "cannot create state: not enough memory");
    return EXIT_FAILURE;
  }
  lua_pushcfunction(L, &pmain);  /* 在保护模式下调用pmain函数 */
  lua_pushinteger(L, argc);  /* 第一个参数 */
  lua_pushlightuserdata(L, argv); /* 第二个参数 */
  status = lua_pcall(L, 2, 1, 0);  /* 开始调用 */
  result = lua_toboolean(L, -1);  /* 得到结果 */
  report(L, status);
  lua_close(L);
  return (result && status == LUA_OK) ? EXIT_SUCCESS : EXIT_FAILURE;
}
Example #17
0
static int rtc_standby( lua_State* L )
{
   char buff[32];
   int nsec = luaL_checkinteger( L, 1 );
   if ((nsec < 0) || (nsec > 84559)) {
     lua_pushstring(L, "wrong interval"); 
     return 1;
   }
   sprintf(buff,"Going to standby for %d seconds\r\n", nsec);
   l_message(NULL,buff);
   mico_rtos_suspend_all_thread();
   MicoSystemStandBy(nsec);
   mico_rtos_resume_all_thread();
   lua_pushstring(L, "RETURN FROM STANDBY"); 
   return 1;
}
Example #18
0
File: lua.c Project: ryo/netbsd-src
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;
  }
  lua_pushcfunction(L, &pmain);  /* to call 'pmain' in protected mode */
  lua_pushinteger(L, argc);  /* 1st argument */
  lua_pushlightuserdata(L, argv); /* 2nd argument */
  status = lua_pcall(L, 2, 1, 0);  /* do the call */
  result = lua_toboolean(L, -1);  /* get result */
  report(L, status);
  lua_close(L);
  return (result && status == LUA_OK) ? EXIT_SUCCESS : EXIT_FAILURE;
}
Example #19
0
int main (int argc, char **argv) {
  int status;
  struct Smain s;
  lua_State *L = lua_open();  /* create state */
  if (L == NULL) {
    l_message(argv[0], "cannot create state: not enough memory");
    return EXIT_FAILURE;
  }
  s.argc = argc;
  s.argv = argv;
  status = lua_cpcall(L, &pmain, &s);
  report(L, status);
  if (status == 0 && s.status == 0)
	  printf("ok !");
  lua_close(L);
  return (status || s.status) ? EXIT_FAILURE : EXIT_SUCCESS;
}
Example #20
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);
}
Example #21
0
static int loadjitmodule (lua_State *L, const char *notfound) {
	lua_getglobal(L, "require");
	lua_pushliteral(L, "jit.");
	lua_pushvalue(L, -3);
	lua_concat(L, 2);
	if (lua_pcall(L, 1, 1, 0)) {
		const char *msg = lua_tostring(L, -1);
		if (msg && !strncmp(msg, "module ", 7)) {
			l_message(L, notfound);
			return 1;
		}
		else
			return report(L, 1);
	}
	lua_getfield(L, -1, "start");
	lua_remove(L, -2);  /* drop module table */
	return 0;
}
Example #22
0
File: lua.c Project: 0w/torch
int main (int argc, char **argv) {
  int status;
  struct Smain s;
#if HAVE_LUA_EXECUTABLE_DIR
  lua_executable_dir(argv[0]);
#endif
  lua_State *L = lua_open();  /* create state */
  if (L == NULL) {
    l_message(argv[0], "cannot create state: not enough memory");
    return EXIT_FAILURE;
  }
  s.argc = argc;
  s.argv = argv;
  status = lua_cpcall(L, &pmain, &s);
  report(L, status);
  lua_close(L);
  return (status || s.status) ? EXIT_FAILURE : EXIT_SUCCESS;
}
Example #23
0
int lua_do(lua_State * L)
{
    int status = loadline(L);
    if (status != -1) {
        if (status == 0)
            status = docall(L, 0, 0);
        report(L, status);
        if (status == 0 && lua_gettop(L) > 0) {     /* any result to print? */
            lua_getglobal(L, "print");
            lua_insert(L, 1);
            if (lua_pcall(L, lua_gettop(L) - 1, 0, 0) != 0)
                l_message(NULL, lua_pushfstring(L, "error calling `print' (%s)",
                lua_tostring(L, -1)));
        }
    }
    lua_settop(L, 0);             /* clear stack */
    return 0;
}
Example #24
0
int main(int argc, char **argv) {
    int status;
    struct Smain s;
    lua_State *L = lua_open(); /* create state */
    if (L == NULL) {
        l_message(argv[0], "cannot create state: not enough memory");
        return EXIT_FAILURE;
    }

    /* Tell LuaPath our runtime directory */
    set_exec_path(argv[0]);

    s.argc = argc;
    s.argv = argv;
    status = lua_cpcall(L, &pmain, &s);
    report(L, status);
    lua_close(L);
    return (status || s.status) ? EXIT_FAILURE : EXIT_SUCCESS;
}
Example #25
0
static void manual_input (void) {
  int status;
  const char *oldprogname = progname;
  progname = NULL;
  while ((status = load_string()) != -1) {
    if (status == 0) status = lcall(0, 0);
    report(status);
    if (status == 0 && lua_gettop(L) > 0) {  /* any result to print? */
      lua_getglobal(L, "print");
      lua_insert(L, 1);
      if (lua_pcall(L, lua_gettop(L)-1, 0, 0) != 0)
        l_message(progname, lua_pushfstring(L, "error calling `print' (%s)",
                                               lua_tostring(L, -1)));
    }
  }
  lua_settop(L, 0);  /* clear stack */
  fputs("\n", stdout);
  progname = oldprogname;
}
Example #26
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;
}
Example #27
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;
}
static void dotty (lua_State *L) {
  int status;
  const char *oldprogname = progname;
  progname = NULL;
  while ((status = loadline(L)) != -1) {
    if (status == 0) status = docall(L, 0, 0);
    report(L, status);
    if (status == 0 && lua_gettop(L) > 0) {
      lua_getglobal(L, "print");
      lua_insert(L, 1);
      if (lua_pcall(L, lua_gettop(L)-1, 0, 0) != 0)
        l_message(progname, lua_pushfstring(L,
                               "error calling " LUA_QL("print") " (%s)",
                               lua_tostring(L, -1)));
    }
  }
  lua_settop(L, 0);
  printf("\n");
  progname = oldprogname;
}
Example #29
0
static void dotty (lua_State *L) {
  int status;
  const char *oldprogname = progname;
  progname = NULL;
  while ((status = loadline(L)) != -1) {
    if (status == 0) status = docall(L, 0, 0);
    report(L, status);
    if (status == 0 && lua_gettop(L) > 0) {  /* any result to print? */
      lua_getglobal(L, "print");
      lua_insert(L, 1);
      if (lua_pcall(L, lua_gettop(L)-1, 0, 0) != 0)
        l_message(progname, lua_pushfstring(L,
                               "error calling " LUA_QL("print") " (%s)",
                               lua_tostring(L, -1)));
    }
  }
  lua_settop(L, 0);  /* clear stack */
  zipfs_fputs("\n", zipfs_stdout);
  zipfs_fflush(zipfs_stdout);
  progname = oldprogname;
}
Example #30
0
static void dotty (lua_State *L) {
  int status;
  const char *oldprogname = progname;
  progname = NULL;
  while ((status = loadline(L)) != -1) {
    if (status == LUA_OK) status = docall(L, 0, LUA_MULTRET);
    report(L, status);
    if (status == LUA_OK && lua_gettop(L) > 0) {  /* any result to print? */
      luaL_checkstack(L, LUA_MINSTACK, "too many results to print");
      lua_getglobal(L, "print");
      lua_insert(L, 1);
      if (lua_pcall(L, lua_gettop(L)-1, 0, 0) != LUA_OK)
        l_message(progname, lua_pushfstring(L,
                               "error calling " LUA_QL("print") " (%s)",
                               lua_tostring(L, -1)));
    }
  }
  lua_settop(L, 0);  /* clear stack */
  luai_writeline();
  progname = oldprogname;
}