示例#1
0
int sexe_exec_pevent(sexe_t *S, int e_type, shjson_t *arg)
{
  shjson_t *json;
  int err;

  if (!arg) {
    json = shjson_init(NULL);
    err = sexe_event_handle(S, e_type, json);
    shjson_free(&json);
  } else {
    err = sexe_event_handle(S, e_type, arg);
  }
  if (err)
    return (err);

  return (0);
}
示例#2
0
static int _lfunc_trigger_event(lua_State *L)
{
  shjson_t *json;
  int e_type = (int)luaL_checknumber(L, 1);
  int t_reg = 0;

  json = NULL;
  if (lua_istable(L, 2)) {
    lua_pushvalue(L, 2);
    json = sexe_table_get(L);
  }

  /* second optional arg; table of data. */
  sexe_event_handle(L, e_type, json);

  if (json)
    shjson_free(&json);

}
示例#3
0
/**
 * The "os.trigger(<string>[,<table>])" function will trigger all callbacks for the specifid event name to be called with an optional object argument.
 */
int lfunc_trigger_event(sexe_t *L)
{
  const char *e_name;
  shjson_t *json;
  int t_reg = 0;
	int ret_bool;
	int err;

	/* first argument: event name */
	e_name = (int)luaL_checkstring(L, 1);

  /* second optional arg; table of data. */
  json = NULL;
  if (lua_istable(L, 2)) {
    lua_pushvalue(L, 2);
    json = sexe_table_get(L);
  }

	ret_bool = 1; 
	err = sexe_event_handle(L, e_name, json);
	if (err)
		ret_bool = 0;

#if 0

	/* iterate through registered functions for event */
	{
	  shkey_t *key = sexe_event_key(e_name);
		char *e_hex = shkey_hex(key);
		lua_getglobal(L, EVENT_ENV);
		if (lua_isnil(L, -1)) {
			return (0); /* error */
		}
		lua_getfield(L, -1, e_hex);
		if (lua_isnil(L, -1)) {
			return (0); /* error */
		}

		lua_pushnil(L);
		while (lua_next(L, -2)) {
			int t = lua_type(L, -1);
			if (t == LUA_TFUNCTION) {
				/* copy function call onto stack  lua_pushvalue(L, 1); */
				/* 1. user args */
				if (json)
					sexe_table_set(L, json);
				else
					lua_pushnil(L);
				/* 2. event name */
				lua_pushstring(L, e_name);
				/* exec */
				lua_pcall(L, 2, 0, 0); 
			} else {
				lua_pop(L, 1); /* value */
			}

			//lua_pop(L, 1); /* key */
		}
	}
#endif

  if (json)
    shjson_free(&json);

	/* return single boolean */
	lua_pushboolean(L, ret_bool);
	return (1);
}