示例#1
0
文件: zmsg.c 项目: jrossi/lzmq
int luazmq_msg_init_data_array(lua_State *L){
  size_t top = lua_rawlen(L, 1);
  size_t i;
  size_t size = 0;
  for(i = 1; i<=top; ++i){
    lua_rawgeti(L,1,i);
    size += lua_rawlen(L,-1);
    lua_pop(L, 1);
  }
  if (0 == size) return luazmq_msg_init(L);

  {
    zmessage *zmsg = luazmq_newudata(L, zmessage, LUAZMQ_MESSAGE);
    int err = zmq_msg_init_size(&zmsg->msg, size);
    size_t pos;
    if(-1 == err) return luazmq_fail(L, NULL);
    for(pos = 0, i = 1; i<=top; ++i){
      const char *data;
      lua_rawgeti(L, 1, i);
      data = luaL_checklstring(L,-1,&size);
      memcpy((char*)zmq_msg_data(&zmsg->msg) + pos, data, size);
      pos += size;
      lua_pop(L, 1);
    }
  }

  return 1;
}
示例#2
0
文件: zsocket.c 项目: ajtulloch/lzmq
static int luazmq_skt_recv_new_msg (lua_State *L){
  if(lua_isuserdata(L,2)) return luazmq_skt_recv_msg(L);
  luaL_optint(L, 2, 0);
  {
    int n = luazmq_msg_init(L);
    if(n != 1)return n;
    lua_insert(L, 2);
    n = luazmq_skt_recv_msg(L);
    if(lua_isnil(L, -n)){
      zmessage *msg = luazmq_getmessage_at(L, 2);
      zmq_msg_close(&msg->msg);
      msg->flags |= LUAZMQ_FLAG_CLOSED;
    }
    return n;
  }
}