WSLUA_CONSTRUCTOR PseudoHeader_eth(lua_State* L) {
    /*
     Creates an ethernet pseudoheader.
     */

#define WSLUA_OPTARG_PseudoHeader_eth_FCSLEN 1 /* The fcs length */

    PseudoHeader ph = (PseudoHeader)g_malloc(sizeof(struct lua_pseudo_header));
    ph->type = PHDR_ETH;
    ph->wph = (union wtap_pseudo_header *)g_malloc(sizeof(union wtap_pseudo_header));
    ph->wph->eth.fcs_len = (gint)luaL_optinteger(L,WSLUA_OPTARG_PseudoHeader_eth_FCSLEN,-1);

    pushPseudoHeader(L,ph);

    WSLUA_RETURN(1); /* The ethernet pseudoheader */
}
Exemple #2
0
static int l_cursor_load(lua_State *L)
{
    THCursor* pCursor = luaT_testuserdata<THCursor>(L);
    THSpriteSheet* pSheet = luaT_testuserdata<THSpriteSheet>(L, 2);
    if(pCursor->createFromSprite(pSheet, static_cast<int>(luaL_checkinteger(L, 3)),
                                 static_cast<int>(luaL_optinteger(L, 4, 0)), static_cast<int>(luaL_optinteger(L, 5, 0))))
    {
        lua_settop(L, 1);
        return 1;
    }
    else
    {
        lua_pushboolean(L, 0);
        return 1;
    }
}
static int ime_int_to_hex_string(lua_State* L){
    lua_Integer val = luaL_checkinteger(L, 1);
    lua_Integer width = luaL_optinteger(L, 2, -1);

    luaL_Buffer buf;
    luaL_buffinit(L, &buf);

    gchar * str = g_strdup_printf("%0*x", width, val);
    luaL_addstring(&buf, str);
    g_free(str);

    luaL_pushresult(&buf);
    lua_remove(L, 2);
    lua_remove(L, 1);
    return 1;
}
Exemple #4
0
WSLUA_METHOD TvbRange_string(lua_State* L) {
    /* Obtain a string from a `TvbRange`. */
#define WSLUA_OPTARG_TvbRange_string_ENCODING 2 /* The encoding to use. Defaults to ENC_ASCII. */
    TvbRange tvbr = checkTvbRange(L,1);
    guint encoding = (guint)luaL_optinteger(L,WSLUA_OPTARG_TvbRange_string_ENCODING, ENC_ASCII|ENC_NA);

    if ( !(tvbr && tvbr->tvb)) return 0;
    if (tvbr->tvb->expired) {
        luaL_error(L,"expired tvb");
        return 0;
    }

    lua_pushlstring(L, (gchar*)tvb_get_string_enc(wmem_packet_scope(),tvbr->tvb->ws_tvb,tvbr->offset,tvbr->len,encoding), tvbr->len);

    WSLUA_RETURN(1); /* The string */
}
Exemple #5
0
// Read a timeout spec from the user and return it
// The timeout spec has the format [timer_id, timeout]. Both arguments are optional: 
// If none is specified -> defaults to infinite timeout
// If timer_id is specified, but timeout is not specified -> defaults to infinite timeout
// If timeout is PLATFORM_TIMER_INF_TIMEOUT -> also infinite timeout (independent of timer_id)
// If both are specified -> wait the specified timeout on the specified timer_id
// If timer_id is 'nil' the system timer will be used
void cmn_get_timeout_data( lua_State *L, int pidx, unsigned *pid, timer_data_type *ptimeout )
{
  lua_Number tempn;

  *ptimeout = PLATFORM_TIMER_INF_TIMEOUT; 
  *pid = ( unsigned )luaL_optinteger( L, pidx, PLATFORM_TIMER_SYS_ID );
  if( lua_type( L, pidx + 1 ) == LUA_TNUMBER )
  {
    tempn = lua_tonumber( L, pidx + 1 );
    if( tempn < 0 || tempn > PLATFORM_TIMER_INF_TIMEOUT )
      luaL_error( L, "invalid timeout value" );
    *ptimeout = ( timer_data_type )tempn;
  }
  if( *pid == PLATFORM_TIMER_SYS_ID && !platform_timer_sys_available() )
    luaL_error( L, "the system timer is not implemented on this platform" );
}
Exemple #6
0
static int unpack (lua_State *L) {
  lua_Integer i, e;
  lua_Unsigned n;
  luaL_checktype(L, 1, LUA_TTABLE);
  i = luaL_optinteger(L, 2, 1);
  e = luaL_opt(L, luaL_checkinteger, 3, luaL_len(L, 1));
  if (i > e) return 0;  /* empty range */
  n = (lua_Unsigned)e - i;  /* number of elements minus 1 (avoid overflows) */
  if (n >= (unsigned int)INT_MAX  || !lua_checkstack(L, ++n))
    return luaL_error(L, "too many results to unpack");
  do {  /* must have at least one element */
    lua_rawgeti(L, 1, i);  /* push arg[i..e] */
  } while (i++ < e); 

  return n;
}
Exemple #7
0
int Shape::computeAABB(lua_State *L) const
{
	float x = Physics::scaleDown((float)luaL_checknumber(L, 1));
	float y = Physics::scaleDown((float)luaL_checknumber(L, 2));
	float r = (float)luaL_checknumber(L, 3);
	int childIndex = (int) luaL_optinteger(L, 4, 1) - 1; // Convert from 1-based index
	b2Transform transform(b2Vec2(x, y), b2Rot(r));
	b2AABB box;
	shape->ComputeAABB(&box, transform, childIndex);
	box = Physics::scaleUp(box);
	lua_pushnumber(L, box.lowerBound.x);
	lua_pushnumber(L, box.lowerBound.y);
	lua_pushnumber(L, box.upperBound.x);
	lua_pushnumber(L, box.upperBound.y);
	return 4;
}
Exemple #8
0
// listen for connections:
int lua_uv_stream_listen(lua_State * L) {
	uv_stream_t * s = lua_generic_object<uv_stream_t>(L, 1);
	luaL_checktype(L, 2, LUA_TFUNCTION);
	int backlog = luaL_optinteger(L, 3, 128);
	
	// bind ptr to callback function:
	lua_pushlightuserdata(L, s);
	lua_pushvalue(L, 2);	// func
	lua_pushvalue(L, 1);	// stream
	lua_pushcclosure(L, lua_uv_stream_listen_cb_closure, 2);	// closure(func, timer)
	lua_rawset(L, LUA_REGISTRYINDEX);
	
	uv_listen(s, backlog, lua_uv_stream_listen_cb);
	lua_uv_ok(L);
	return 0;
}
Exemple #9
0
static int tremove (lua_State *L) {
  lua_Integer size = aux_getn(L, 1, TAB_RW);
  lua_Integer pos = luaL_optinteger(L, 2, size);
  if (pos != size)  /* validate 'pos' if given */
    /* check whether 'pos' is in [1, size + 1] */
    luaL_argcheck(L, (lua_Unsigned)pos - 1u <= (lua_Unsigned)size, 1,
                     "position out of bounds");
  lua_geti(L, 1, pos);  /* result = t[pos] */
  for ( ; pos < size; pos++) {
    lua_geti(L, 1, pos + 1);
    lua_seti(L, 1, pos);  /* t[pos] = t[pos + 1] */
  }
  lua_pushnil(L);
  lua_seti(L, 1, pos);  /* remove entry t[pos] */
  return 1;
}
Exemple #10
0
static int str_find_aux (lua_State *L, int mode) {  /* EXT */
  size_t ls, lp;
  const char *s = luaL_checklstring(L, 1, &ls);
  const char *p = luaL_checklstring(L, 2, &lp);
  lua_Integer init = posrelat(luaL_optinteger(L, 3, 1), ls);
  if (init < 1) init = 1;
  else if (init > (lua_Integer)ls + 1) {  /* start after string's end? */
    lua_pushnil(L);  /* cannot find anything */
    return 1;
  }
  /* explicit request or no special characters? */  /* EXT */
  if (mode == MODE_FIND && (lua_toboolean(L, 4) || nospecials(p, lp))) {
    /* do a plain search */
    const char *s2 = lmemfind(s + init - 1, ls - (size_t)init + 1, p, lp);
    if (s2) {
      lua_pushinteger(L, (s2 - s) + 1);
      lua_pushinteger(L, (s2 - s) + lp);
      return 2;
    }
  }
  else {
    MatchState ms;
    const char *s1 = s + init - 1;
    int anchor = (*p == '^');
    prepstate(&ms, L, s, ls, p, lp);  /* EXT (moved before anchor check) */
    if (anchor)
      p++;  /* skip anchor character */  /* EXT */
    do {
      const char *res;
      reprepstate(&ms);
      if ((res=match(&ms, s1, p)) != NULL) {
        if (mode == MODE_FIND) {  /* EXT */
          lua_pushinteger(L, (s1 - s) + 1);  /* start */
          lua_pushinteger(L, res - s);   /* end */
          return push_captures(&ms, NULL, 0) + 2;
        }
        else if (mode == MODE_MATCH)  /* EXT */
          return push_captures(&ms, s1, res);
        else {  /* EXT */
          return build_result_table(&ms, s1, res);
        }
      }
    } while (s1++ < ms.src_end && !anchor);
  }
  lua_pushnil(L);  /* not found */
  return 1;
}
Exemple #11
0
/*
    zlib.inflate(
        source: string | function | { read: function, close: function },
        windowBits: number, [15]
        dictionary: [""]
    )
*/
static int lzlib_inflate(lua_State *L)
{
    int windowBits;
    lz_stream *s;
    int have_peek = 0;
    const char *dictionary;
    size_t dictionary_len;

    if (lua_istable(L, 1) || lua_isuserdata(L, 1)) {
        /* is there a :read function? */
        lua_getfield(L, 1, "read");
        if (!lua_isfunction(L, -1)) {
            luaL_argerror(L, 1, "input parameter does not provide :read function");
        }
        lua_pop(L, 1);
        /* check for peek function */
        lua_getfield(L, 1, "peek");
        have_peek = lua_isfunction(L, -1);
        lua_pop(L, 1);
    }
    else if (!lua_isstring(L, 1) && !lua_isfunction(L, 1)) {
        luaL_argerror(L, 1, "input parameter must be a string, function, table or userdata value");
    }

    windowBits = (int) luaL_optinteger(L, 2, 15);
    dictionary = luaL_optlstring(L, 3, NULL, &dictionary_len);

    s = lzstream_new(L, 1);

    if (windowBits > 0 && windowBits < 16) {
        windowBits |= 32;
    }

    if (inflateInit2(&s->zstream, windowBits) != Z_OK) {
        lua_pushliteral(L, "call to inflateInit2 failed");
        lua_error(L);
    }

    if (dictionary) {
        s->dictionary = (const Bytef *) dictionary;
        s->dictionary_len = dictionary_len;
    }

    s->peek = have_peek;
    s->state = LZ_INFLATE;
    return 1;
}
Exemple #12
0
int 
scheduler_start(lua_State *L) {
	luaL_checktype(L,1,LUA_TTABLE);
	hive_createenv(L);
	struct global_queue * gmq = lua_newuserdata(L, sizeof(*gmq));
	globalmq_init(gmq);

	lua_pushvalue(L,-1);
	hive_setenv(L, "message_queue");

	lua_State *sL;

	sL = scheduler_newtask(L);
	luaL_requiref(sL, "cell.system", cell_system_lib, 0);
	lua_pop(sL,1);
	struct cell * sys = cell_new(sL, "system.lua");
	if (sys == NULL) {
		scheduler_deletetask(sL);
		return 0;
	}
	lua_pushlightuserdata(L, sys);
	hive_setenv(L, "system_pointer");
	scheduler_starttask(sL);
	
	lua_getfield(L,1,"main");
	const char * mainfile = luaL_checkstring(L, -1);
	sL = scheduler_newtask(L);
	void * c = cell_new(sL, mainfile);
	if (c == NULL) {
		cell_close(sys);
		return 0;
	}
	scheduler_starttask(sL);
	lua_pop(L,1);	// pop string mainfile
	
	lua_getfield(L,1, "thread");
	int thread = luaL_optinteger(L, -1, DEFAULT_THREAD);
	lua_pop(L,1);

	struct timer * t = lua_newuserdata(L, sizeof(*t));
	timer_init(t,sys,gmq);

	_start(gmq,thread,t);
	cell_close(sys);

	return 0;
}
Exemple #13
0
static int LUA_C_tcp_accept(lua_State* ls)
  {
  SOCKET_ST* st = (SOCKET_ST*)luaL_checkudata(ls, 1, gk_tcp_register);

  if(st->bind_port == 0)
    return TCP_ERROR(ls, st, "TCP Client不能接受连接");

  const size_t timeout = luaL_optinteger(ls, 2, -1);

  timeval t;
  t.tv_sec = timeout / 1000;
  t.tv_usec = timeout % 1000;

  const timeval* lpt = (timeout == -1) ? nullptr : &t;

  fd_set s;
  s.fd_count = 1;
  s.fd_array[0] = st->sock;

  switch(select(1, &s, nullptr, nullptr, lpt))
    {
    case SOCKET_ERROR:
      return TCP_ERROR(ls, st, "TCP监听连接失败");
    case 0:
      lua_pushnil(ls);
      lua_pushstring(ls, "timeout");
      return 2;
    default:
      break;
    }

  sockaddr_in addr;
  memset(&addr, 0, sizeof(addr));
  int namelen = sizeof(addr);
  const SOCKET hS = accept(st->sock, (sockaddr*)&addr, &namelen);
  if(hS == INVALID_SOCKET)
    return TCP_ERROR(ls, st, xmsg() << "TCP接受连接失败:" << WSAGetLastError());

  st = (SOCKET_ST*)lua_newuserdata(ls, sizeof(*st));
  st->sock = hS;
  st->addr = addr;
  st->bind_port = 0;

  luaL_setmetatable(ls, gk_tcp_register);
  return 1;
  }
Exemple #14
0
static int GetText(lua_State *L)
{
  char* buffer;
  const char *title = luaL_checkstring(L,1);
  const char *text = luaL_checkstring(L,2);
  int maxsize = (int)luaL_optinteger(L, 3, 10240);
  buffer = malloc(maxsize+1);
  iupStrCopyN(buffer, maxsize, text);
  if (IupGetText(title, buffer, maxsize))
  {
    lua_pushstring(L, buffer);
    free(buffer);
    return 1;
  }
  free(buffer);
  return 0;
}
Exemple #15
0
WSLUA_METHOD TvbRange_strsize(lua_State* L) {
        /* Find the size of a zero terminated string from a `TvbRange`.
           The size of the string includes the terminating zero.

           @since 1.11.3
         */
#define WSLUA_OPTARG_TvbRange_strsize_ENCODING 2 /* The encoding to use. Defaults to ENC_ASCII. */
    TvbRange tvbr = checkTvbRange(L,1);
    guint encoding = (guint)luaL_optinteger(L,WSLUA_OPTARG_TvbRange_strsize_ENCODING, ENC_ASCII|ENC_NA);
    gint offset;
    gunichar2 uchar;

    if ( !(tvbr && tvbr->tvb)) return 0;
    if (tvbr->tvb->expired) {
        luaL_error(L,"expired tvb");
        return 0;
    }

    switch (encoding & ENC_CHARENCODING_MASK) {

    case ENC_UTF_16:
    case ENC_UCS_2:
        offset = tvbr->offset;
        do {
            if (!tvb_bytes_exist (tvbr->tvb->ws_tvb, offset, 2)) {
                luaL_error(L,"out of bounds");
                return 0;
            }
            /* Endianness doesn't matter when looking for null */
            uchar = tvb_get_ntohs (tvbr->tvb->ws_tvb, offset);
            offset += 2;
        } while (uchar != 0);
        lua_pushinteger(L, tvb_unicode_strsize(tvbr->tvb->ws_tvb, tvbr->offset));
        break;

    default:
        if (tvb_find_guint8 (tvbr->tvb->ws_tvb, tvbr->offset, -1, 0) == -1) {
            luaL_error(L,"out of bounds");
            return 0;
        }
        lua_pushinteger(L, tvb_strsize(tvbr->tvb->ws_tvb, tvbr->offset));
        break;
    }

    WSLUA_RETURN(1); /* Length of the zero terminated string. */
}
Exemple #16
0
static int luaC_lunum_linear(lua_State *L)
{
  const lua_Number  e1 = luaL_checknumber(L, 1);
  const lua_Number  e2 = luaL_checknumber(L, 2);
  const lua_Integer N  = luaL_checkinteger(L, 3);
  if (N <= 1) { return luaL_error(L, "Invalid size %d", N); }
  const ArrayType T = (ArrayType) luaL_optinteger(L, 4, ARRAY_TYPE_DOUBLE);

  Array A = array_new_zeros(N, T);
  void *a = A.data;
  
  ARRAY_ASSIGN_OP(T, EXPR_ASSIGN_LINEAR);
  
  lunum_pusharray1(L, &A);
  
  return 1;
}
Exemple #17
0
static int luaC_lunum_array(lua_State *L)
{
  if (lua_type(L, 2) == LUA_TSTRING) {
    const ArrayType T = array_typeflag(lua_tostring(L, 2)[0]);
    lunum_upcast(L, 1, T, 1);
  }
  else {
    const ArrayType T = (ArrayType) luaL_optinteger(L, 2, ARRAY_TYPE_DOUBLE);
    lunum_upcast(L, 1, T, 1);
  }
  lua_replace(L, 1); /* place array at bottom of stack */
  if (!lua_isnone(L, 2)) lua_remove(L, 2); /* remove arg 2 if given */
  if (lua_istable(L, 2)) {
    luaC_lunum_resize(L); /* reshape array to third arg if given */
  }
  return 1;
}
Exemple #18
0
int PixelBinder::setColor(lua_State* L)
{
	Binder binder(L);

	Pixel* bitmap = static_cast<Pixel*>(binder.getInstance("Pixel", 1));

	unsigned int color = luaL_optinteger(L, 2, 0);
	lua_Number alpha = luaL_optnumber(L, 3, 1.0);

	int r = (color >> 16) & 0xff;
	int g = (color >> 8) & 0xff;
	int b = color & 0xff;

	bitmap->setColor(r/255.f,g/255.f,b/255.f,alpha);

	return 0;
}
Exemple #19
0
static
int
mosq_subscribe(lua_State *L)
{
	mosq_t *ctx = mosq_get(L, 1);
	int mid;
	const char *sub = luaL_checkstring(L, 2);
	int qos = luaL_optinteger(L, 3, 0);

	int rc = mosquitto_subscribe(ctx->mosq, &mid, sub, qos);

	if (rc != MOSQ_ERR_SUCCESS) {
		return make_mosq_status_result(L, rc);
	}

	return make_int_result(L, true, mid);
}
Exemple #20
0
/*
 * Method: AddEquip
 *
 * Add an equipment or cargo item to its appropriate equipment slot
 *
 * > num_added = ship:AddEquip(item, count)
 *
 * Parameters:
 *
 *   item - a <Constants.EquipType> string for the item
 *
 *   count - optional. The number of this item to add. Defaults to 1.
 *
 * Return:
 *
 *   num_added - the number of items added. Can be less than count if there
 *               was not enough room.
 *
 * Example:
 *
 * > ship:AddEquip("ANIMAL_MEAT", 10)
 *
 * Availability:
 *
 *   alpha 10
 *
 * Status:
 *
 *   experimental
 */
static int l_ship_add_equip(lua_State *l)
{
    Ship *s = LuaObject<Ship>::CheckFromLua(1);
    Equip::Type e = static_cast<Equip::Type>(LuaConstants::GetConstantFromArg(l, "EquipType", 2));

    int num = luaL_optinteger(l, 3, 1);
    if (num < 0)
        return luaL_error(l, "Can't add a negative number of equipment items.");

    const shipstats_t &stats = s->GetStats();
    if (Equip::types[e].mass != 0)
        num = std::min(stats.free_capacity / (Equip::types[e].mass), num);

    lua_pushinteger(l, s->m_equipment.Add(e, num));
    s->UpdateEquipStats();
    return 1;
}
Exemple #21
0
static int ln_add(lua_State *L) {
	struct luanotify *N = luaL_checkudata(L, 1, CQS_NOTIFY);
	const char *name = luaL_checkstring(L, 2);
	int flags = luaL_optinteger(L, 3, NOTIFY_ALL);
	int error;

	if ((error = notify_add(N->notify, name, flags))) {
		lua_pushboolean(L, 0);
		lua_pushinteger(L, error);

		return 2;
	} else {
		lua_pushboolean(L, 1);

		return 1;
	}
} /* ln_add() */
Exemple #22
0
static int f_seek (lua_State *L) {
  static const int mode[] = {SEEK_SET, SEEK_CUR, SEEK_END};
  static const char *const modenames[] = {"set", "cur", "end", NULL};
  FILE *f = tofile(L);
  int op = luaL_checkoption(L, 2, "cur", modenames);
  lua_Integer p3 = luaL_optinteger(L, 3, 0);
  l_seeknum offset = (l_seeknum)p3;
  luaL_argcheck(L, (lua_Integer)offset == p3, 3,
                  "not an integer in proper range");
  op = l_fseek(f, offset, mode[op]);
  if (op)
    return luaL_fileresult(L, 0, NULL);  /* error */
  else {
    lua_pushinteger(L, (lua_Integer)l_ftell(f));
    return 1;
  }
}
static int ctx_will_set(lua_State *L)
{
	ctx_t *ctx = ctx_check(L, 1);
	const char *topic = luaL_checkstring(L, 2);
	size_t payloadlen = 0;
	const void *payload = NULL;

	if (!lua_isnil(L, 3)) {
		payload = lua_tolstring(L, 3, &payloadlen);
	};

	int qos = luaL_optinteger(L, 4, 0);
	bool retain = lua_toboolean(L, 5);

	int rc = mosquitto_will_set(ctx->mosq, topic, payloadlen, payload, qos, retain);
	return mosq__pstatus(L, rc);
}
Exemple #24
0
static int tconcat (lua_State *L) {
  luaL_Buffer b;
  lua_Integer last = aux_getn(L, 1, TAB_R);
  size_t lsep;
  const char *sep = luaL_optlstring(L, 2, "", &lsep);
  lua_Integer i = luaL_optinteger(L, 3, 1);
  last = luaL_opt(L, luaL_checkinteger, 4, last);
  luaL_buffinit(L, &b);
  for (; i < last; i++) {
    addfield(L, &b, i);
    luaL_addlstring(&b, sep, lsep);
  }
  if (i == last)  /* add last value (if interval was not empty) */
    addfield(L, &b, i);
  luaL_pushresult(&b);
  return 1;
}
Exemple #25
0
static int l_rawbitmap_draw(lua_State *L)
{
    THRawBitmap* pBitmap = luaT_testuserdata<THRawBitmap>(L);
    THRenderTarget* pCanvas = luaT_testuserdata<THRenderTarget>(L, 2);

    if(lua_gettop(L) >= 8)
    {
        pBitmap->draw(pCanvas, static_cast<int>(luaL_checkinteger(L, 3)), static_cast<int>(luaL_checkinteger(L, 4)),
            static_cast<int>(luaL_checkinteger(L, 5)), static_cast<int>(luaL_checkinteger(L, 6)), static_cast<int>(luaL_checkinteger(L, 7)),
            static_cast<int>(luaL_checkinteger(L, 8)));
    }
    else
        pBitmap->draw(pCanvas, static_cast<int>(luaL_optinteger(L, 3, 0)), static_cast<int>(luaL_optinteger(L, 4, 0)));

    lua_settop(L, 1);
    return 1;
}
Exemple #26
0
/***
Draw a triangle outline on the current screen.
@function linedTriangle
@tparam integer x1 horizontal coordinate of a vertex of the triangle, in pixels
@tparam integer y1 vertical coordinate of a vertex of the triangle, in pixels
@tparam integer x2 horizontal coordinate of a vertex of the triangle, in pixels
@tparam integer y2 vertical coordinate of a vertex of the triangle, in pixels
@tparam integer x3 horizontal coordinate of a vertex of the triangle, in pixels
@tparam integer y3 vertical coordinate of a vertex of the triangle, in pixels
@tparam[opt=1] number lineWidth line's thickness, in pixels
@tparam[opt=default color] integer color drawing color
*/
static int gfx_linedTriangle(lua_State *L) {
	int x1 = luaL_checkinteger(L, 1);
	int y1 = luaL_checkinteger(L, 2);
	int x2 = luaL_checkinteger(L, 3);
	int y2 = luaL_checkinteger(L, 4);
	int x3 = luaL_checkinteger(L, 5);
	int y3 = luaL_checkinteger(L, 6);
	float lineWidth = luaL_optnumber(L, 7, 1.0f);

	u32 color = luaL_optinteger(L, 8, color_default);

	sf2d_draw_line(x1, y1, x2, y2, lineWidth, color);
	sf2d_draw_line(x2, y2, x3, y3, lineWidth, color);
	sf2d_draw_line(x3, y3, x1, y1, lineWidth, color);

	return 0;
}
Exemple #27
0
// Lua: drv.on(self, event, cb_fn)
static int pcm_drv_on( lua_State *L )
{
  size_t len;
  const char *event;
  uint8_t is_func = FALSE;

  GET_PUD();

  event = luaL_checklstring( L, 2, &len );

  if ((lua_type( L, 3 ) == LUA_TFUNCTION) ||
      (lua_type( L, 3 ) == LUA_TLIGHTFUNCTION)) {
    lua_pushvalue( L, 3 );  // copy argument (func) to the top of stack
    is_func = TRUE;
  }

  if ((len == 4) && (c_strcmp( event, "data" ) == 0)) {
    luaL_unref( L, LUA_REGISTRYINDEX, cfg->cb_data_ref);
    cfg->cb_data_ref = COND_REF( is_func );
  } else if ((len == 7) && (c_strcmp( event, "drained" ) == 0)) {
    luaL_unref( L, LUA_REGISTRYINDEX, cfg->cb_drained_ref);
    cfg->cb_drained_ref = COND_REF( is_func );
  } else if ((len == 6) && (c_strcmp( event, "paused" ) == 0)) {
    luaL_unref( L, LUA_REGISTRYINDEX, cfg->cb_paused_ref);
    cfg->cb_paused_ref = COND_REF( is_func );
  } else if ((len == 7) && (c_strcmp( event, "stopped" ) == 0)) {
    luaL_unref( L, LUA_REGISTRYINDEX, cfg->cb_stopped_ref);
    cfg->cb_stopped_ref = COND_REF( is_func );
  } else if ((len == 2) && (c_strcmp( event, "vu" ) == 0)) {
    luaL_unref( L, LUA_REGISTRYINDEX, cfg->cb_vu_ref);
    cfg->cb_vu_ref = COND_REF( is_func );

    int freq = luaL_optinteger( L, 4, 10 );
    luaL_argcheck( L, (freq > 0) && (freq <= 200), 4, "invalid range" );
    cfg->vu_freq = (uint8_t)freq;
  } else {
    if (is_func) {
      // need to pop pushed function arg
      lua_pop( L, 1 );
    }
    return luaL_error( L, "method not supported" );
  }

  return 0;
}
Exemple #28
0
/**
 * Return the nth certificate of the peer's chain.
 */
static int meth_getpeercertificate(lua_State *L)
{
  int n;
  X509 *cert;
  STACK_OF(X509) *certs;
  p_ssl ssl = (p_ssl)luaL_checkudata(L, 1, "SSL:Connection");
  if (ssl->state != LSEC_STATE_CONNECTED) {
    lua_pushnil(L);
    lua_pushstring(L, "closed");
    return 2;
  }
  /* Default to the first cert */ 
  n = (int)luaL_optinteger(L, 2, 1);                           
  /* This function is 1-based, but OpenSSL is 0-based */
  --n;
  if (n < 0) {
    lua_pushnil(L);
    lua_pushliteral(L, "invalid certificate index");
    return 2;
  }
  if (n == 0) {
    cert = SSL_get_peer_certificate(ssl->ssl);
    if (cert)
      lsec_pushx509(L, cert);
    else
      lua_pushnil(L);
    return 1;
  }
  /* In a server-context, the stack doesn't contain the peer cert,
   * so adjust accordingly.
   */
  if (ssl->ssl->server)
    --n;
  certs = SSL_get_peer_cert_chain(ssl->ssl);
  if (n >= sk_X509_num(certs)) {
    lua_pushnil(L);
    return 1;
  }
  cert = sk_X509_value(certs, n);
  /* Increment the reference counting of the object. */
  /* See SSL_get_peer_certificate() source code.     */
  CRYPTO_add(&cert->references, 1, CRYPTO_LOCK_X509);
  lsec_pushx509(L, cert);
  return 1;
}
Exemple #29
0
static int GetAllAttributes(lua_State *L)
{
  int n, i, max_n = luaL_optinteger(L, 1, 0);
  char **names;
  if (!max_n) max_n = IupGetAllAttributes(iuplua_checkihandle(L,1), NULL, 0);
  names = (char **) malloc (max_n * sizeof(char *));
  n = IupGetAllAttributes(iuplua_checkihandle(L,1),names,max_n);
  lua_createtable(L, n, 0);
  for (i=0; i<n; i++)
  {
    lua_pushinteger(L,i+1);
    lua_pushstring(L,names[i]);
    lua_settable(L,-3);
  }
  lua_pushinteger(L,n);
  free(names);
  return 2;
}
Exemple #30
0
int LuaGameObject::GossipMenuAddItem(lua_State* L, GameObject* /*ptr*/)
{
    uint8 icon = static_cast<uint8>(luaL_checkinteger(L, 1));
    const char* menu_text = luaL_checkstring(L, 2);
    int IntId = static_cast<int>(luaL_checkinteger(L, 3));
    bool coded = (luaL_checkinteger(L, 4)) ? true : false;
    const char* boxmessage = luaL_optstring(L, 5, "");
    uint32_t boxmoney = static_cast<uint32_t>(luaL_optinteger(L, 6, 0));

    if (LuaGlobal::instance()->m_menu == NULL)
    {
        LOG_ERROR("There is no menu to add items to!");
        return 0;
    }

    LuaGlobal::instance()->m_menu->AddItem(icon, menu_text, IntId, boxmoney, boxmessage, coded);
    return 0;
}