Example #1
0
	int ProtocolManager::_BytesToTable(lua_State* L){
		// check arg
		if(lua_gettop(L) < 3){
			lua_pushnil(L);
			lua_pushfstring(L, "fail to call %s, invalid arg", __func__);
			return 2;
		}
		const int64_t group_id =luaL_checkinteger(L, 1);
		const int64_t proto_id =luaL_checkinteger(L, 2);
		Bytes* bs =0;
		if(!get_object_from_lua< Bytes* >(L, 3, bs) || !bs){
			lua_pushnil(L);
			lua_pushfstring(L, "fail to call %s, invalid arg #3", __func__);
			return 2;
		}

		// create proto
		ProtocolBase* proto =Instance()->createProtocol(group_id, proto_id);
		if(!proto){
			lua_pushnil(L);
			lua_pushfstring(L, "fail to call %s, [group_id %lld, proto_id %lld] create protocol error", __func__, (long long)group_id, (long long)proto_id);
			return 2;
		}
		if(!proto->fromBytes(bs)){
			lua_pushnil(L);
			lua_pushfstring(L, "fail to call %s, [group_id %lld, proto_id %lld] unmarshal error", __func__, (long long)group_id, (long long)proto_id);
			return 2;
		}
		if(!proto->toLua(L)){
			lua_pushnil(L);
			lua_pushfstring(L, "fail to call %s, [group_id %lld, proto_id %lld] encode to lua error", __func__, (long long)group_id, (long long)proto_id);
			return 2;
		}
		return 1;
	}
Example #2
0
	int ProtocolManager::_ObjectToTable(lua_State* L){
		// check arg
		if(lua_gettop(L) < 1){
			lua_pushnil(L);
			lua_pushfstring(L, "fail to call %s, invalid arg", __func__);
			return 2;
		}
		ProtocolBase* proto =0;
		if(!get_object_from_lua< ProtocolBase* >(L, 1, proto) || !proto){
			lua_pushnil(L);
			lua_pushfstring(L, "fail to call %s, invalid arg #3", __func__);
			return 2;
		}

		// create proto
		if(!proto->toLua(L)){
			lua_pushnil(L);
			lua_pushfstring(L, "fail to call %s, ProtocolBase to lua table error", __func__);
			return 2;
		}
		return 1;
	}