예제 #1
0
파일: main_lua.c 프로젝트: eswartz/emul
static struct peer_extra *lua_push_pse(lua_State *L, PeerServer *ps)
{
    struct peer_extra *pse;

    lua_rawgeti(L, LUA_REGISTRYINDEX, peers_refp->ref);
    lua_pushstring(L, ps->id);          /* Key */
    lua_rawget(L, -2);
    if((pse = (struct peer_extra *)lua_touserdata(L, -1)) != NULL) {
        assert(lua_isclass(L, -1, "tcf_peer"));
        assert(pse->managed);
    } else {
        assert(lua_isnil(L, -1));
        lua_pop(L, 1);

        pse = lua_alloc_pse(L, ps);
        pse->managed = 1;

        /* Register mapping from PS to LUA object */
        lua_pushstring(L, ps->id);          /* Key */
        lua_pushvalue(L, -2);               /* Value */
        lua_rawset(L, -4);                  /* peers[id] = pse */
    }
    lua_remove(L, -2);                  /* Remove peers table */
    /* Returns userdata for peer on LUA stack */
    return pse;
}
예제 #2
0
파일: main_lua.c 프로젝트: eswartz/emul
static struct peer_extra *lookup_pse(lua_State *L, PeerServer *ps)
{
    struct peer_extra *pse;

    lua_rawgeti(L, LUA_REGISTRYINDEX, peers_refp->ref);
    lua_pushstring(L, ps->id);          /* Key */
    lua_rawget(L, -2);
    if((pse = (struct peer_extra *)lua_touserdata(L, -1)) == NULL) {
        assert(lua_isnil(L, -1));
        lua_pop(L, 2);
        return NULL;
    }
    assert(lua_isclass(L, -1, "tcf_peer"));
    lua_pop(L, 2);
    return pse;
}
예제 #3
0
bool lua_bindvalidateparams(const char* dt, lua_State* L)
{
	// validates function/method arguments
	for (int i = 0; dt[i] != LU_NIL; ++i)
	{
		if (dt[i] == LU_OPT)
			return true;

		int idx = i + 1;
		switch (dt[i])
		{
		case LU_BOOL:
			if (!lua_isboolean(L, idx))
				return false;
			break;
		case LU_ENUM:
		case LU_INT:
		case LU_FLOAT:
		case LU_DOUBLE:
		case LU_NUMBER:
			if (!lua_isnumber(L, idx))
				return false;
			break;
		case LU_STRING:
			if (!lua_isstring(L, idx))
				return false;
			break;
		case LU_INSTANCE:
			if (!lua_isclass(L, idx))
				return false;
			break;
		case LU_FUNCTION:
			if (!lua_isfunction(L, i + 1))
				return false;
			break;
		}
	}
	return true;
}