Esempio n. 1
0
static int cpArbiter_getPoint(lua_State *L) {
    cpArbiter *arb = toarbiter(L);
    int i = luaL_checkint(L, 2);
    push_cpVect(L, cpArbiterGetPoint(arb, i));
    return 2;
}
Esempio n. 2
0
File: main.c Progetto: daid/F3B
int luaSetSignNr(lua_State* L)
{
    setSignNr(luaL_checkint(L, 1), luaL_checkint(L, 2));
    return 0;
}
Esempio n. 3
0
static int luasrc_SpewActivate (lua_State *L) {
  SpewActivate(luaL_checkstring(L, 1), luaL_checkint(L, 2));
  return 0;
}
Esempio n. 4
0
static int luasrc_UTIL_ClientPrintAll (lua_State *L) {
  UTIL_ClientPrintAll(luaL_checkint(L, 1), luaL_checkstring(L, 2));
  return 0;
}
Esempio n. 5
0
static int math_randomseed (lua_State *L) {
  srand(luaL_checkint(L, 1));
  return 0;
}
Esempio n. 6
0
    int CEntityBase::lTable2Insert(lua_State* L)
    {
        //param 1 is userdata

        uint32_t nCbId = (uint32_t)luaL_checkint(L, 2);	//callback id
        const char* pszTbl = luaL_checkstring(L, 3);	//table name
        luaL_checkany(L, 4);							//table

        if(!lua_istable(L, 4))
        {
            lua_pushstring(L, "tableInsert,param 4 need a table.");
            lua_error(L);
            return 0;
        }

        world* the_world = GetWorld();
        CMailBox* mb = the_world->GetServerMailbox(SERVER_DBMGR);
        if(mb == NULL)
        {
            return 0;
        }

        CDefParser& def = the_world->GetDefParser();
        const SEntityDef* pDef = def.GetEntityDefByName(pszTbl);
        if(pDef == NULL)
        {
            lua_pushfstring(L, "error entity name:%s", pszTbl);
            lua_error(L);
            return 0;
        }

        CPluto* u = new CPluto;
        u->Encode(MSGID_DBMGR_TABLE2_INSERT) << m_mymb.m_nServerMailboxId << m_id << nCbId << def.GetTypeId(pszTbl);

        lua_pushnil(L);
        while(lua_next(L, 4) != 0)
        {
            const char* pszKey = luaL_checkstring(L, -2);

            map<string, _SEntityDefProperties*>::const_iterator iter = pDef->m_properties.find(pszKey);
            if(iter != pDef->m_properties.end())
            {
                _SEntityDefProperties* p = iter->second;
                if(p && p->m_bSaveDb)
                {
                    u->FillField<uint16_t>(pDef->m_propertiesMap.GetIntByStr(pszKey));
                    u->FillPlutoFromLua(p->m_nType, L, 6);
                    lua_pop(L, 1);
                    continue;
                }
            }

            delete u;
            lua_pushfstring(L, "%s hasn't field %s or field not need to save.", pszTbl, pszKey);
            lua_error(L);
            return 0;
        }

        u->endPluto();
        //print_hex_pluto(*u);

        mb->PushPluto(u);

        return 0;
    }
Esempio n. 7
0
void GetConfigRetry(lua_State* L, int index, uint16_t* retry) {
    if (!lua_isnil(L, index)) {
        *retry = (uint16_t) luaL_checkint(L, index);
    }
}
Esempio n. 8
0
static int str_format (lua_State *L) {
  int top = lua_gettop(L);
  int arg = 1;
  size_t sfl;
  const char *strfrmt = luaL_checklstring(L, arg, &sfl);
  const char *strfrmt_end = strfrmt+sfl;
  luaL_Buffer b;
  luaL_buffinit(L, &b);
  while (strfrmt < strfrmt_end) {
    if (*strfrmt != L_ESC)
      luaL_addchar(&b, *strfrmt++);
    else if (*++strfrmt == L_ESC)
      luaL_addchar(&b, *strfrmt++);  /* %% */
    else { /* format item */
      char form[MAX_FORMAT];  /* to store the format (`%...') */
      char *buff = luaL_prepbuffsize(&b, MAX_ITEM);  /* to put formatted item */
      int nb = 0;  /* number of bytes in added item */
      if (++arg > top)
        luaL_argerror(L, arg, "no value");
      strfrmt = scanformat(L, strfrmt, form);
      switch (*strfrmt++) {
        case 'c': {
          nb = sprintf(buff, form, luaL_checkint(L, arg));
          break;
        }
        case 'd': case 'i': {
          lua_Number n = luaL_checknumber(L, arg);
          LUA_INTFRM_T ni = (LUA_INTFRM_T)n;
          lua_Number diff = n - (lua_Number)ni;
          luaL_argcheck(L, -1 < diff && diff < 1, arg,
                        "not a number in proper range");
          addlenmod(form, LUA_INTFRMLEN);
          nb = sprintf(buff, form, ni);
          break;
        }
        case 'o': case 'u': case 'x': case 'X': {
          lua_Number n = luaL_checknumber(L, arg);
          unsigned LUA_INTFRM_T ni = (unsigned LUA_INTFRM_T)n;
          lua_Number diff = n - (lua_Number)ni;
          luaL_argcheck(L, -1 < diff && diff < 1, arg,
                        "not a non-negative number in proper range");
          addlenmod(form, LUA_INTFRMLEN);
          nb = sprintf(buff, form, ni);
          break;
        }
        case 'e': case 'E': case 'f':
#if defined(LUA_USE_AFORMAT)
        case 'a': case 'A':
#endif
        case 'g': case 'G': {
          addlenmod(form, LUA_FLTFRMLEN);
          nb = sprintf(buff, form, (LUA_FLTFRM_T)luaL_checknumber(L, arg));
          break;
        }
        case 'q': {
          addquoted(L, &b, arg);
          break;
        }
        case 's': {
          size_t l;
          const char *s = luaL_tolstring(L, arg, &l);
          if (!strchr(form, '.') && l >= 100) {
            /* no precision and string is too long to be formatted;
               keep original string */
            luaL_addvalue(&b);
            break;
          }
          else {
            nb = sprintf(buff, form, s);
            lua_pop(L, 1);  /* remove result from 'luaL_tolstring' */
            break;
          }
        }
        default: {  /* also treat cases `pnLlh' */
          return luaL_error(L, "invalid option " LUA_QL("%%%c") " to "
                               LUA_QL("format"), *(strfrmt - 1));
        }
      }
      luaL_addsize(&b, nb);
    }
  }
  luaL_pushresult(&b);
  return 1;
}
Esempio n. 9
0
static int
ngx_http_lua_shdict_flush_expired(lua_State *L)
{
    ngx_queue_t                 *q, *prev;
    ngx_http_lua_shdict_node_t  *sd;
    ngx_http_lua_shdict_ctx_t   *ctx;
    ngx_shm_zone_t              *zone;
    ngx_time_t                  *tp;
    int                          freed = 0;
    int                          attempts = 0;
    ngx_rbtree_node_t           *node;
    uint64_t                     now;
    int                          n;

    n = lua_gettop(L);

    if (n != 1 && n != 2) {
        return luaL_error(L, "expecting 1 or 2 argument(s), but saw %d", n);
    }

    luaL_checktype(L, 1, LUA_TLIGHTUSERDATA);

    zone = lua_touserdata(L, 1);
    if (zone == NULL) {
        return luaL_error(L, "bad user data for the ngx_shm_zone_t pointer");
    }

    if (n == 2) {
        attempts = luaL_checkint(L, 2);
    }

    ctx = zone->data;

    ngx_shmtx_lock(&ctx->shpool->mutex);

    if (ngx_queue_empty(&ctx->sh->queue)) {
        ngx_shmtx_unlock(&ctx->shpool->mutex);
        lua_pushnumber(L, 0);
        return 1;
    }

    tp = ngx_timeofday();

    now = (uint64_t) tp->sec * 1000 + tp->msec;

    q = ngx_queue_last(&ctx->sh->queue);

    while (q != ngx_queue_sentinel(&ctx->sh->queue)) {
        prev = ngx_queue_prev(q);

        sd = ngx_queue_data(q, ngx_http_lua_shdict_node_t, queue);

        if (sd->expires != 0 && sd->expires <= now) {
            ngx_queue_remove(q);

            node = (ngx_rbtree_node_t *)
                ((u_char *) sd - offsetof(ngx_rbtree_node_t, color));

            ngx_rbtree_delete(&ctx->sh->rbtree, node);
            ngx_slab_free_locked(ctx->shpool, node);
            freed++;

            if (attempts && freed == attempts) {
                break;
            }
        }

        q = prev;
    }

    ngx_shmtx_unlock(&ctx->shpool->mutex);

    lua_pushnumber(L, freed);
    return 1;
}
Esempio n. 10
0
static LUA_FUNCTION(openssl_crl_new)
{
  int i;
  int n = lua_gettop(L);
  X509_CRL * crl = X509_CRL_new();
  int ret = X509_CRL_set_version(crl, 0);
  X509* cacert = NULL;
  EVP_PKEY* capkey = NULL;
  const EVP_MD* md = NULL;
  int step;

  for (i = 1; ret == 1 && i <= n; i++)
  {
    if (i == 1)
    {
      luaL_argcheck(L, lua_istable(L, 1), 1, "must be table contains rovked entry table{reason,time,sn}");
      if (lua_rawlen(L, i) > 0)
      {
        int j, m;
        m = lua_rawlen(L, i);

        for (j = 1; ret == 1 && j <= m; j++)
        {
          X509_REVOKED *revoked;
          BIGNUM* sn;
          lua_rawgeti(L, i, j);
          luaL_checktable(L, -1);

          lua_getfield(L, -1, "reason");
          lua_getfield(L, -2, "time");
          lua_getfield(L, -3, "sn");
          sn = BN_get(L, -1);
          revoked = create_revoked(sn, lua_tointeger(L, -2), reason_get(L, -3));
          if (revoked)
          {
            ret = X509_CRL_add0_revoked(crl, revoked);
          }
          BN_free(sn);
          lua_pop(L, 3);
          lua_pop(L, 1);
        };
      }
    };
    if (i == 2)
    {
      cacert = CHECK_OBJECT(2, X509, "openssl.x509");
      ret = X509_CRL_set_issuer_name(crl, X509_get_issuer_name(cacert));
    }
    if (i == 3)
    {
      capkey = CHECK_OBJECT(3, EVP_PKEY, "openssl.evp_pkey");
      luaL_argcheck(L, openssl_pkey_is_private(capkey), 3, "must be private key");
      luaL_argcheck(L, X509_check_private_key(cacert, capkey) == 1, 3, "evp_pkey not match with x509 in #2");
    }
  }
  md = lua_isnoneornil(L, 4) ? EVP_get_digestbyname("sha1") : get_digest(L, 4);
  step = lua_isnoneornil(L, 5) ? 7 * 24 * 3600 : luaL_checkint(L, 5);

  if (ret == 1)
  {
    time_t lastUpdate;
    time_t nextUpdate;
    ASN1_TIME *ltm, *ntm;

    time(&lastUpdate);
    nextUpdate = lastUpdate + step;

    ltm = ASN1_TIME_new();
    ntm = ASN1_TIME_new();
    ASN1_TIME_set(ltm, lastUpdate);
    ASN1_TIME_set(ntm, nextUpdate);
    ret = X509_CRL_set_lastUpdate(crl, ltm);
    if (ret == 1)
      ret = X509_CRL_set_nextUpdate(crl, ntm);
    ASN1_TIME_free(ltm);
    ASN1_TIME_free(ntm);
  }
  if (cacert && capkey && md)
  {
    ret = (X509_CRL_sign(crl, capkey, md) == EVP_PKEY_size(capkey));
  }
  if (ret == 1)
  {
    PUSH_OBJECT(crl, "openssl.x509_crl");
  }
  else
  {
    X509_CRL_free(crl);
    return openssl_pushresult(L, ret);
  };

  return 1;
}
Esempio n. 11
0
static int lua_drawBMPV(lua_State *L){
int argc = lua_gettop(L);
    if ((argc != 4) && (argc != 5)) return luaL_error(L, "wrong number of arguments");
	int x = luaL_checkint(L, 1);
	int y = luaL_checkint(L, 2);
	BMPV* src = (BMPV*)luaL_checkint(L, 3);
	u32 bytesRead;
	int screen = luaL_checkint(L, 4);
	int side = 0;
	if (argc == 5){
	side = luaL_checkint(L,5);
	}
	if (src->isPlaying){
		if (src->currentFrame >= src->tot_frame){
			if (src->loop == 1){
				src->currentFrame = 0;
				if (!GW_MODE){
					src->moltiplier = 1;
				}
				src->tick = osGetTime();
			}else{
				src->isPlaying = false;
				src->moltiplier = 1;
				CSND_setchannel_playbackstate(src->ch1, 0);
				if (src->audiobuf2 != NULL) CSND_setchannel_playbackstate(src->ch2, 0);
				CSND_sharedmemtype0_cmdupdatestate(0);
			}
			if (src->audiobuf2 == NULL){
				FSFILE_Read(src->sourceFile, &bytesRead, 28, src->audiobuf, src->mem_size);
				GSPGPU_FlushDataCache(NULL, src->audiobuf, src->mem_size);
			}else{
				u8* tmp_buffer = (u8*)linearAlloc(src->mem_size);
				FSFILE_Read(src->sourceFile, &bytesRead, 28, tmp_buffer, src->mem_size);
				u32 size_tbp = src->mem_size;
				u32 off=0;
				u32 i=0;
				u16 z;
				while (i < size_tbp){
					z=0;
					while (z < (src->bytepersample/2)){
						src->audiobuf[off+z] = tmp_buffer[i+z];
						src->audiobuf2[off+z] = tmp_buffer[i+z+(src->bytepersample/2)];
						z++;
					}
					z=0;
					i=i+src->bytepersample;
					off=off+(src->bytepersample/2);
				}
			linearFree(tmp_buffer);
			GSPGPU_FlushDataCache(NULL, src->audiobuf, (src->mem_size)/2);
			GSPGPU_FlushDataCache(NULL, src->audiobuf2, (src->mem_size)/2);
			}
		}else{
			if (((src->samplerate * src->bytepersample * ((osGetTime() - src->tick) / 1000)) > ((src->mem_size / 2) * src->moltiplier)) && (src->isPlaying)){
			if ((src->moltiplier % 2) == 1){
			//Update and flush first half-buffer
			if (src->audiobuf2 == NULL){
				FSFILE_Read(src->sourceFile, &bytesRead, 28+(((src->mem_size)/2)*(src->moltiplier + 1)), src->audiobuf, (src->mem_size)/2);
				if (bytesRead != ((src->mem_size)/2)){
				FSFILE_Read(src->sourceFile, &bytesRead, 28, src->audiobuf, (src->mem_size)/2);
				src->moltiplier = src->moltiplier + 1;
				}
				src->moltiplier = src->moltiplier + 1;
				GSPGPU_FlushDataCache(NULL, src->audiobuf, src->mem_size);
			}else{
				u8* tmp_buffer = (u8*)linearAlloc((src->mem_size)/2);
				FSFILE_Read(src->sourceFile, &bytesRead, 28+(src->mem_size/2)*(src->moltiplier + 1), tmp_buffer, (src->mem_size)/2);
				if (bytesRead != ((src->mem_size)/2)){
				FSFILE_Read(src->sourceFile, &bytesRead, 28, tmp_buffer, (src->mem_size)/2);
				src->moltiplier = src->moltiplier + 1;
				}
				src->moltiplier = src->moltiplier + 1;
				u32 size_tbp = (src->mem_size)/2;
				u32 off=0;
				u32 i=0;
				u16 z;
				while (i < size_tbp){
					z=0;
					while (z < (src->bytepersample/2)){
						src->audiobuf[off+z] = tmp_buffer[i+z];
						src->audiobuf2[off+z] = tmp_buffer[i+z+(src->bytepersample/2)];
						z++;
					}
					i=i+src->bytepersample;
					off=off+(src->bytepersample/2);
				}
				linearFree(tmp_buffer);
				GSPGPU_FlushDataCache(NULL, src->audiobuf, (src->mem_size)/2);
				GSPGPU_FlushDataCache(NULL, src->audiobuf2, (src->mem_size)/2);
			}
		}else{
			u32 bytesRead;
			//Update and flush second half-buffer
			if (src->audiobuf2 == NULL){
				FSFILE_Read(src->sourceFile, &bytesRead, 28+(((src->mem_size)/2)*(src->moltiplier + 1)), src->audiobuf+((src->mem_size)/2), (src->mem_size)/2);
				src->moltiplier = src->moltiplier + 1;
				GSPGPU_FlushDataCache(NULL, src->audiobuf, src->mem_size);
			}else{
				u8* tmp_buffer = (u8*)linearAlloc((src->mem_size)/2);
				FSFILE_Read(src->sourceFile, &bytesRead, 28+(src->mem_size/2)*(src->moltiplier + 1), tmp_buffer, (src->mem_size)/2);
				src->moltiplier = src->moltiplier + 1;
				u32 size_tbp = (src->mem_size)/2;
				u32 off=0;
				u32 i=0;
				u16 z;
				while (i < size_tbp){
					z=0;
					while (z < (src->bytepersample/2)){
						src->audiobuf[(src->mem_size)/4+off+z] = tmp_buffer[i+z];
						src->audiobuf2[(src->mem_size)/4+off+z] = tmp_buffer[i+z+(src->bytepersample/2)];
						z++;
					}
				i=i+src->bytepersample;
				off=off+(src->bytepersample/2);
				}
				linearFree(tmp_buffer);
				GSPGPU_FlushDataCache(NULL, src->audiobuf, (src->mem_size)/2);
				GSPGPU_FlushDataCache(NULL, src->audiobuf2, (src->mem_size)/2);
			}
		}
		}
			src->currentFrame =((osGetTime() - src->tick) * src->framerate / 1000);
			Bitmap bitmap;
			bitmap.width = src->width;
			bitmap.height = src->height;
			bitmap.bitperpixel = 24;
			u32 frame_size = src->width * src->height * 3;
			u32 bytesRead;
			FSFILE_Read(src->sourceFile, &bytesRead, 28+src->audio_size+(src->currentFrame*frame_size), src->framebuf, frame_size);
			bitmap.pixels = src->framebuf;
			if (screen > 1) PrintImageBitmap(x,y,&bitmap,screen);
			else PrintScreenBitmap(x,y,&bitmap,screen,side);
		}
	}else{
		if (src->tick != 0){
			Bitmap bitmap;
			bitmap.width = src->width;
			bitmap.height = src->height;
			bitmap.bitperpixel = 24;
			u32 frame_size = src->width * src->height * 3;
			u32 bytesRead;
			FSFILE_Read(src->sourceFile, &bytesRead, 28+src->audio_size+(src->currentFrame*frame_size), src->framebuf, frame_size);
			bitmap.pixels = src->framebuf;
			if (screen > 1) PrintImageBitmap(x,y,&bitmap,screen);
			else PrintScreenBitmap(x,y,&bitmap,screen,side);
		}
	}
	return 0;
}
Esempio n. 12
0
static int cvar_RevertFlaggedConVars (lua_State *L) {
  cvar->RevertFlaggedConVars(luaL_checkint(L, 1));
  return 0;
}
Esempio n. 13
0
static int math_ldexp (lua_State *L) {
  lua_Number x = luaL_checknumber(L, 1);
  int ep = luaL_checkint(L, 2);
  lua_pushnumber(L, l_mathop(ldexp)(x, ep));
  return 1;
}
Esempio n. 14
0
/**
 * create a new canvas
 * args: width, height, [title]
 */
int Canvas::_new(lua_State *l) {
	const char *title = "Aroma";

	int width = luaL_checkint(l, 2);
	int height = luaL_checkint(l, 3);
	if (lua_gettop(l) > 3) {
		title = luaL_checkstring(l, 4);
	}

	GLContext* context = new GLFWContext(width, height, title);
	if (!context->make_current()) {
		return luaL_error(l, "fatal error: failed to open window");
	}

	_canvas = new Canvas(context);

	Viewport &view = _canvas->view;

	lua_newtable(l);

	// functions

	setfunction("run", Canvas::_run);

	setfunction("rect", Canvas::_rect);
	setfunction("line", Canvas::_line);

	setfunction("viewport", Canvas::_viewport);
	setfunction("view3d", Canvas::_view3d);

	setfunction("look", Canvas::_look);
	setfunction("strip", Canvas::_strip);

	setfunction("rotate", Canvas::_rotate);
	setfunction("scale", Canvas::_scale);
	setfunction("translate", Canvas::_translate);

	setfunction("noise", Canvas::_noise);

	setfunction("save", Canvas::_save);
	setfunction("restore", Canvas::_restore);

	setfunction("getTime", Canvas::_getTime);
	setfunction("clear_color", Canvas::_clearColor);
	setfunction("clear", Canvas::_clear);
	setfunction("flush", Canvas::_flush);

	setfunction("set_mouse", Canvas::_setMouse);
	setfunction("hide_mouse", Canvas::_hideMouse);
	setfunction("show_mouse", Canvas::_showMouse);

	setfunction("key", Canvas::_key);
	setfunction("key_up", Canvas::_key_up);
	setfunction("key_down", Canvas::_key_down);

	// load libraries
	AromaRegister *lib = aroma_libs;
	while (*lib) {
		(*lib++)(l);
	}

	// properties
	setnumber("dt", 0);
	setnumber("time", glfwGetTime());

	setnumber("width", view.getWidth());
	setnumber("height", view.getHeight());


	// mouse input
	lua_newtable(l);
	setint("x", 0);
	setint("y", 0);
	setbool("left", false);
	setbool("right", false);

	lua_setfield(l, -2, "mouse");
	
	// create the input table
	lua_newtable(l);
	setnumber("xaxis", 0);
	setnumber("yaxis", 0);

	setbool("left", false);
	setbool("right", false);
	setbool("up", false);
	setbool("down", false);

	setbool("a", false);
	setbool("b", false);
	setbool("c", false);
	setbool("d", false);

	setbool("start", false);
	setbool("select", false);

	setbool("l", false);
	setbool("r", false);

	lua_setfield(l, -2, "input");

	// the keys
	push_key_table(l);
	lua_setfield(l, -2, "keys");

	// create meta table
	lua_newtable(l);		
	setfunction("__call", _call);
	lua_setmetatable(l, -2);

	return 1;
}
Esempio n. 15
0
static int kcSetTrim(lua_State *L) {
	KOPTContext *kc = (KOPTContext*) luaL_checkudata(L, 1, "koptcontext");
	kc->trim = luaL_checkint(L, 2);
	return 0;
}
Esempio n. 16
0
static int
ngx_http_lua_shdict_get_keys(lua_State *L)
{
    ngx_queue_t                 *q, *prev;
    ngx_http_lua_shdict_node_t  *sd;
    ngx_http_lua_shdict_ctx_t   *ctx;
    ngx_shm_zone_t              *zone;
    ngx_time_t                  *tp;
    int                          total = 0;
    int                          attempts = 1024;
    uint64_t                     now;
    int                          n;

    n = lua_gettop(L);

    if (n != 1 && n != 2) {
        return luaL_error(L, "expecting 1 or 2 argument(s), "
                          "but saw %d", n);
    }

    luaL_checktype(L, 1, LUA_TLIGHTUSERDATA);

    zone = lua_touserdata(L, 1);
    if (zone == NULL) {
        return luaL_error(L, "bad user data for the ngx_shm_zone_t pointer");
    }

    if (n == 2) {
        attempts = luaL_checkint(L, 2);
    }

    ctx = zone->data;

    ngx_shmtx_lock(&ctx->shpool->mutex);

    if (ngx_queue_empty(&ctx->sh->queue)) {
        ngx_shmtx_unlock(&ctx->shpool->mutex);
        lua_createtable(L, 0, 0);
        return 1;
    }

    tp = ngx_timeofday();

    now = (uint64_t) tp->sec * 1000 + tp->msec;

    /* first run through: get total number of elements we need to allocate */

    q = ngx_queue_last(&ctx->sh->queue);

    while (q != ngx_queue_sentinel(&ctx->sh->queue)) {
        prev = ngx_queue_prev(q);

        sd = ngx_queue_data(q, ngx_http_lua_shdict_node_t, queue);

        if (sd->expires == 0 || sd->expires > now) {
            total++;
            if (attempts && total == attempts) {
                break;
            }
        }

        q = prev;
    }

    lua_createtable(L, total, 0);

    /* second run through: add keys to table */

    total = 0;
    q = ngx_queue_last(&ctx->sh->queue);

    while (q != ngx_queue_sentinel(&ctx->sh->queue)) {
        prev = ngx_queue_prev(q);

        sd = ngx_queue_data(q, ngx_http_lua_shdict_node_t, queue);

        if (sd->expires == 0 || sd->expires > now) {
            lua_pushlstring(L, (char *) sd->data, sd->key_len);
            lua_rawseti(L, -2, ++total);
            if (attempts && total == attempts) {
                break;
            }
        }

        q = prev;
    }

    ngx_shmtx_unlock(&ctx->shpool->mutex);

    /* table is at top of stack */
    return 1;
}
Esempio n. 17
0
    //根据一个已知的mb,坐标等数据创建cell entity
    int CEntityBase::lCreateCellEntity(lua_State* L)
    {

        //已经有cell或者cell正在创建之中
        if(m_nCellState != E_HASNT_CELL)
        {
            lua_pushinteger(L, 1);
            return 1;
        }

        //first param userdata
        //其他参数: base_mailbox, x, y, string
        if(!lua_istable(L, 2))
        {
            lua_pushstring(L, "createCellEntity need a table param");
            lua_error(L);
            return -1;
        }

        //检查目标base的server_id
        lua_rawgeti(L, 2, g_nMailBoxServerIdKey);
        int nServerId = luaL_checkint(L, -1);

        lua_rawgeti(L, 2, g_nMailBoxEntityIdKey);
        TENTITYID nId = (TENTITYID)luaL_checkint(L, -1);

        int16_t x = (int16_t)luaL_checkint(L, 3);
        int16_t y = (int16_t)luaL_checkint(L, 4);
        const char* szMask = luaL_checkstring(L, 5);
        //LogDebug("CEntityBase::lCreateCellEntity", szMask);
        CPluto* u = new CPluto;
        u->Encode(MSGID_BASEAPP_CREATE_CELL_VIA_MYCELL);
        (*u) << nId << m_mymb << x << y << szMask;
        PickleCellPropsToPluto(*u);
        (*u) << EndPluto;

        world* the_world = GetWorld();
        if(nServerId == the_world->GetMailboxId())
        {
            m_nCellState = E_CELL_IN_CREATING;
            the_world->GetServer()->AddLocalRpcPluto(u);
        }
        else
        {
            CMailBox* mb = the_world->GetServerMailbox(nServerId);
            if(mb)
            {
                m_nCellState = E_CELL_IN_CREATING;

                //LogDebug("CEntityBase::lCreateCellEntity", "nServerId=%d;the_world->GetMailboxId()=%d;u->GetLen()=%d;", nServerId, the_world->GetMailboxId(),u->GetLen());

                mb->PushPluto(u);
            }
            else
            {
                delete u;
            }
        }

        lua_pushinteger(L, 0);
        return 1;
    }
Esempio n. 18
0
static int l_town_map_draw(lua_State *L)
{
    luaL_checktype(L, 1, LUA_TTABLE);
    THMap *pMap = luaT_testuserdata<THMap>(L, 2);
    THRenderTarget *pCanvas = luaT_testuserdata<THRenderTarget>(L, 3);
    int iCanvasXBase = luaL_checkint(L, 4);
    int iCanvasYBase = luaL_checkint(L, 5);
    bool bShowHeat = lua_toboolean(L, 6) != 0;

    uint32_t iColourMyHosp = pCanvas->mapColour(0, 0, 70);
    uint32_t iColourWall = pCanvas->mapColour(255, 255, 255);
    uint32_t iColourDoor = pCanvas->mapColour(200, 200, 200);
    uint32_t iColourPurchasable = pCanvas->mapColour(255, 0, 0);

    const THMapNode *pNode = pMap->getNodeUnchecked(0, 0);
    const THMapNode *pOriginalNode = pMap->getOriginalNodeUnchecked(0, 0);
    int iCanvasY = iCanvasYBase + 3;
    for(int iY = 0; iY < pMap->getHeight(); ++iY, iCanvasY += 3)
    {
        int iCanvasX = iCanvasXBase;
        for(int iX = 0; iX < pMap->getWidth(); ++iX, ++pNode, ++pOriginalNode, iCanvasX += 3)
        {
            if(pOriginalNode->iFlags & THMN_Hospital)
            {
                uint32_t iColour = iColourMyHosp;
                if(!(pNode->iFlags & THMN_Hospital))
                {
                    // TODO: Replace 1 with player number
                    if(pMap->isParcelPurchasable(pNode->iParcelId, 1))
                        iColour = iColourPurchasable;
                    else
                        goto dont_paint_tile;
                }
                else if(bShowHeat)
                {
                    uint16_t iTemp = pMap->getNodeTemperature(pNode);
                    if(iTemp < 5200) // Less than 4 degrees
                        iTemp = 0;
                    else if(iTemp > 32767) // More than 25 degrees
                        iTemp = 255;
                    else // NB: 108 == (32767 - 5200) / 255
                        iTemp = (iTemp - 5200) / 108;
                    iColour = pCanvas->mapColour(static_cast<uint8_t>(iTemp), 0, 70);
                }
                pCanvas->fillRect(iColour, iCanvasX, iCanvasY, 3, 3);
            }
            dont_paint_tile:
#define IsWall(blk) ((82 <= ((blk) & 0xFF)) && (((blk) & 0xFF) <= 164))
#define IsWallDrawn(n) pMap->getNodeOwner(pNode) != 0 ? \
    IsWall(pNode->iBlock[n]) : IsWall(pOriginalNode->iBlock[n])
            if(IsWallDrawn(1))
                pCanvas->fillRect(iColourWall, iCanvasX, iCanvasY, 3, 1);
            if(IsWallDrawn(2))
                pCanvas->fillRect(iColourWall, iCanvasX, iCanvasY, 1, 3);
#undef IsWallDrawn
#undef IsWall
            if(pNode->iFlags & THMN_DoorNorth)
                pCanvas->fillRect(iColourDoor, iCanvasX, iCanvasY - 2, 2, 3);
            if(pNode->iFlags & THMN_DoorWest)
                pCanvas->fillRect(iColourDoor, iCanvasX - 3, iCanvasY, 3, 2);
        }
    }

    return 0;
}
Esempio n. 19
0
// WARNING x10 coeff du to timer in x100ms (openAT)
void GetConfigTimeout(lua_State* L, int index, uint16_t* timeout) {
    if (!lua_isnil(L, index)) {
        *timeout = (uint16_t) 10 * luaL_checkint(L, index);
    }
}
Esempio n. 20
0
static int kcSetColumns(lua_State *L) {
	KOPTContext *kc = (KOPTContext*) luaL_checkudata(L, 1, "koptcontext");
	kc->columns = luaL_checkint(L, 2);
	return 0;
}
Esempio n. 21
0
static int luasrc_UTIL_PlayerByIndex (lua_State *L) {
  lua_pushplayer(L, UTIL_PlayerByIndex(luaL_checkint(L, 1)));
  return 1;
}
Esempio n. 22
0
static int kcSetOffset(lua_State *L) {
	KOPTContext *kc = (KOPTContext*) luaL_checkudata(L, 1, "koptcontext");
	kc->offset_x = luaL_checkint(L, 2);
	kc->offset_y = luaL_checkint(L, 3);
	return 0;
}
Esempio n. 23
0
static int math_ldexp (lua_State *L) {
  lua_pushnumber(L, ldexp(luaL_checknumber(L, 1), luaL_checkint(L, 2)));
  return 1;
}
Esempio n. 24
0
static int kcSetDeviceDim(lua_State *L) {
	KOPTContext *kc = (KOPTContext*) luaL_checkudata(L, 1, "koptcontext");
	kc->dev_width = luaL_checkint(L, 2);
	kc->dev_height = luaL_checkint(L, 3);
	return 0;
}
static int create(lua_State* pState)
{
    int mode = MODE_ECB;

    int top = lua_gettop(pState);
    size_t keyLen = 0;
    size_t IVLen = 0;
    int segment_size = 0;
    const char* key = NULL; 
    const char* IV = NULL;   
    AESObject* aes = NULL;

    key = luaL_checklstring(pState, 1, &keyLen);
    switch(keyLen) 
    {
        case 16:
        case 24:
        case 32:
            break;
        default:
            luaL_error(pState, "AES key must be either 16, 24, or 32 bytes long");
            return 0;
    }

    if (top > 1)
    {
        //check mode
        mode = luaL_checkint(pState, 2);
    }

    if (top > 2)
    {
        //check iv
        IV = luaL_checklstring(pState, 3, &IVLen);
    }

    if (top > 3)
    {
        //check segment size
        segment_size = luaL_checkint(pState, 4);
    }

    switch(mode)
    {
        case MODE_ECB:
        case MODE_CBC:
        case MODE_CFB:
        case MODE_OFB:
            break;
        default:
            luaL_error(pState, "Not Support AES Mode");
            return 0;
    }

    if (IVLen != BLOCK_SIZE && mode != MODE_ECB && mode != MODE_CTR)
    {
        luaL_error(pState, "IV must be %d bytes long", BLOCK_SIZE);
        return 0;
    }

    if (mode == MODE_CFB) 
    {
        if (segment_size == 0) 
            segment_size = 8;
        
        if (segment_size < 1 || segment_size > BLOCK_SIZE*8 
            || ((segment_size & 7) != 0)) 
        {
            luaL_error(pState,  "segment_size must be multiple of 8 (bits) between 1 and %d", BLOCK_SIZE*8);
            return 0;
        }
    }

    aes = (AESObject*)lua_newuserdata(pState, sizeof(AESObject));
    aes->mode = mode;
    aes->segment_size = segment_size;
    aes->count = BLOCK_SIZE;

    memset(aes->IV, 0, BLOCK_SIZE);
    memset(aes->oldCipher, 0, BLOCK_SIZE);
    memcpy(aes->IV, IV, IVLen);

    lua_pushlightuserdata(pState, &pycrypto_aes_key);
    lua_gettable(pState, LUA_REGISTRYINDEX);

    lua_setmetatable(pState, -2);

    if(block_init(&(aes->st), key, keyLen) != 0)
    {
        luaL_error(pState, "init aes object error %s %d", key, keyLen);
        return 0;
    }

    return 1;
}
Esempio n. 26
0
static int kcSetStraighten(lua_State *L) {
	KOPTContext *kc = (KOPTContext*) luaL_checkudata(L, 1, "koptcontext");
	kc->straighten = luaL_checkint(L, 2);
	return 0;
}
Esempio n. 27
0
static int luasrc_NetLog (lua_State *L) {
  NetLog(luaL_checkint(L, 1), luaL_checkstring(L, 2));
  return 0;
}
Esempio n. 28
0
static int kcSetJustification(lua_State *L) {
	KOPTContext *kc = (KOPTContext*) luaL_checkudata(L, 1, "koptcontext");
	kc->justification = luaL_checkint(L, 2);
	return 0;
}
Esempio n. 29
0
static int luasrc_IsSpewActive (lua_State *L) {
  lua_pushboolean(L, IsSpewActive(luaL_checkstring(L, 1), luaL_checkint(L, 2)));
  return 1;
}
int
ngx_http_lua_body_filter_param_set(lua_State *L, ngx_http_request_t *r,
        ngx_http_lua_ctx_t *ctx)
{
    int                      type;
    int                      idx;
    u_char                  *data;
    size_t                   size;
    unsigned                 last;
    ngx_chain_t             *cl;
    ngx_chain_t             *in;
    ngx_buf_tag_t            tag;

    idx = luaL_checkint(L, 2);

    dd("index: %d", idx);

    if (idx != 1 && idx != 2) {
        return luaL_error(L, "bad index: %d", idx);
    }

    if (idx == 2) {
        /* overwriting the eof flag */
        last = lua_toboolean(L, 3);

        lua_pushlightuserdata(L, &ngx_http_lua_body_filter_chain_key);
        lua_rawget(L, LUA_GLOBALSINDEX);
        in = lua_touserdata(L, -1);

        if (last) {
            if (in) {
                for (cl = in; cl; cl = cl->next) {
                    if (cl->next == NULL) {
                        cl->buf->last_buf = 1;
                        break;
                    }
                }

            } else {
                tag = (ngx_buf_tag_t) &ngx_http_lua_module;

                cl = ngx_http_lua_chains_get_free_buf(r->connection->log,
                                                      r->pool, &ctx->free_bufs,
                                                      0, tag);

                if (cl == NULL) {
                    return luaL_error(L, "out of memory");
                }

                cl->buf->last_buf = 1;

                lua_pushlightuserdata(L, &ngx_http_lua_body_filter_chain_key);
                lua_pushlightuserdata(L, cl);
                lua_rawset(L, LUA_GLOBALSINDEX);
            }

        } else {
            /* last == 0 */

            if (in) {
                for (size = 0, cl = in; cl; cl = cl->next) {
                    if (cl->buf->last_buf) {
                        cl->buf->last_buf = 0;
                    }

                    size += cl->buf->last - cl->buf->pos;
                }

                if (size == 0) {
                    lua_pushlightuserdata(L,
                                          &ngx_http_lua_body_filter_chain_key);
                    lua_pushlightuserdata(L, NULL);
                    lua_rawset(L, LUA_GLOBALSINDEX);
                }
            }
        }

        return 0;
    }

    /* idx == 1, overwriting the chunk data */

    type = lua_type(L, 3);

    switch (type) {
    case LUA_TSTRING:
    case LUA_TNUMBER:
        data = (u_char *) lua_tolstring(L, 3, &size);
        break;

    case LUA_TNIL:
        /* discard the buffers */
        lua_pushlightuserdata(L, &ngx_http_lua_body_filter_chain_key);
        lua_pushlightuserdata(L, NULL);
        lua_rawset(L, LUA_GLOBALSINDEX);
        return 0;

    case LUA_TTABLE:
        size = ngx_http_lua_calc_strlen_in_table(L, 3 /* index */,
                                                 1 /* strict */);
        data = NULL;
        break;

    default:
        return luaL_error(L, "bad chunk data type: %s",
                          lua_typename(L, type));
    }

    lua_pushlightuserdata(L, &ngx_http_lua_body_filter_chain_key);
    lua_rawget(L, LUA_GLOBALSINDEX);
    in = lua_touserdata(L, -1);
    lua_pop(L, 1);

    last = 0;
    for (cl = in; cl; cl = cl->next) {
        if (cl->buf->last_buf) {
            last = 1;
        }

        /* mark the buf as consumed */
        cl->buf->pos = cl->buf->last;
    }

    if (size == 0) {
        if (last) {
            if (in) {
                in->buf->last_buf = 1;

            } else {

                tag = (ngx_buf_tag_t) &ngx_http_lua_module;

                cl = ngx_http_lua_chains_get_free_buf(r->connection->log,
                                                      r->pool, &ctx->free_bufs,
                                                      0, tag);

                if (cl == NULL) {
                    return luaL_error(L, "out of memory");
                }

                cl->buf->last_buf = 1;

                lua_pushlightuserdata(L, &ngx_http_lua_body_filter_chain_key);
                lua_pushlightuserdata(L, cl);
                lua_rawset(L, LUA_GLOBALSINDEX);
            }
        }

        return 0;
    }

    tag = (ngx_buf_tag_t) &ngx_http_lua_module;

    cl = ngx_http_lua_chains_get_free_buf(r->connection->log, r->pool,
                                          &ctx->free_bufs, size, tag);
    if (cl == NULL) {
        return luaL_error(L, "out of memory");
    }

    if (type == LUA_TTABLE) {
        cl->buf->last = ngx_http_lua_copy_str_in_table(L, cl->buf->last);

    } else {
        cl->buf->last = ngx_copy(cl->buf->pos, data, size);
    }

    cl->buf->last_buf = last;

    lua_pushlightuserdata(L, &ngx_http_lua_body_filter_chain_key);
    lua_pushlightuserdata(L, cl);
    lua_rawset(L, LUA_GLOBALSINDEX);
    return 0;
}