Пример #1
0
// log([level,] text)
// Writes a line to the logger.
// The one-argument version logs to infostream.
// The two-argument version accept a log level: error, action, info, or verbose.
int ModApiUtil::l_log(lua_State *L)
{
	NO_MAP_LOCK_REQUIRED;
	std::string text;
	LogMessageLevel level = LMT_INFO;
	if (lua_isnone(L, 2)) {
		text = lua_tostring(L, 1);
	}
	else {
		std::string levelname = luaL_checkstring(L, 1);
		text = luaL_checkstring(L, 2);
		if(levelname == "error")
			level = LMT_ERROR;
		else if(levelname == "action")
			level = LMT_ACTION;
		else if(levelname == "verbose")
			level = LMT_VERBOSE;
	}
	log_printline(level, text);
	return 0;
}
Пример #2
0
/* Method: SpawnMissile
 *
 * Spawn a missile near the ship.
 *
 * > missile = ship:SpawnMissile(type, target, power)
 * 
 * Parameters:
 *
 *   shiptype - a string for the missile type. specifying an
 *          ship that is not a missile will result in a Lua error
 *
 *   target - the <Ship> to fire the missile at
 *
 *   power - the power of the missile. If unspecified, the default power for the
 *
 * Return:
 *
 *   missile - The missile spawned, or nil if it was unsuccessful.
 *
 * Availability:
 *
 *   alpha 26
 *
 * Status:
 *
 *   experimental
 */
static int l_ship_spawn_missile(lua_State *l)
{
	Ship *s = LuaObject<Ship>::CheckFromLua(1);
	if (s->GetFlightState() == Ship::HYPERSPACE)
		return luaL_error(l, "Ship:SpawnMissile() cannot be called on a ship in hyperspace");
	ShipType::Id missile_type(luaL_checkstring(l, 2));

	if (missile_type != ShipType::MISSILE_UNGUIDED &&
			missile_type != ShipType::MISSILE_GUIDED &&
			missile_type != ShipType::MISSILE_SMART &&
			missile_type != ShipType::MISSILE_NAVAL)
		luaL_error(l, "Ship type '%s' is not a valid missile type", lua_tostring(l, 2));
	int power = (lua_isnone(l, 3))? -1 : lua_tointeger(l, 3);

	Missile * missile = s->SpawnMissile(missile_type, power);
	if (missile)
		LuaObject<Missile>::PushToLua(missile);
	else
		lua_pushnil(l);
	return 1;
}
Пример #3
0
static int openssl_ts_req_policy_id(lua_State*L)
{
  TS_REQ* req = CHECK_OBJECT(1, TS_REQ, "openssl.ts_req");
  if (lua_isnone(L, 2))
  {
    ASN1_OBJECT* obj = TS_REQ_get_policy_id(req);
    openssl_push_asn1object(L, obj);
    ASN1_OBJECT_free(obj);
    return 1;
  }
  else
  {
    int nid = openssl_get_nid(L, 2);
    ASN1_OBJECT* obj;
    int ret;
    luaL_argcheck(L, nid != NID_undef, 2, "must be asn1_object object identified");
    obj = OBJ_nid2obj(nid);
    ret = TS_REQ_set_policy_id(req, obj);
    return openssl_pushresult(L, ret);
  }
}
Пример #4
0
int ViewportBinder::setTransform(lua_State* L)
{
	StackChecker checker(L, "ViewportBinder::setTransform", 0);
	
	Binder binder(L);
	Viewport* shape = static_cast<Viewport*>(binder.getInstance("Viewport", 1));
	const Matrix4 *matrix = NULL;
	Transform t;
	if (!lua_isnone(L, 2))
	{
		Matrix2D *matrix2 = static_cast<Matrix2D*>(binder.getInstance("Matrix", 2));
		if (matrix2)
		{
			t.setMatrix(matrix2->m11(),matrix2->m12(),matrix2->m21(),matrix2->m22(),matrix2->tx(),matrix2->ty());
			matrix=&t.matrix();
		}
	}
	shape->setTransform(matrix);

	return 0;
}
Пример #5
0
static LUA_FUNCTION(openssl_crl_nextUpdate)
{
  X509_CRL *crl = CHECK_OBJECT(1, X509_CRL, "openssl.x509_crl");
  if (lua_isnone(L, 2))
  {
    ASN1_TIME *tm = X509_CRL_get_nextUpdate(crl);
    PUSH_ASN1_TIME(L, tm);
    return 1;
  }
  else
  {
    int ret;
    time_t time = luaL_checkint(L, 2);
    ASN1_TIME *tm = ASN1_TIME_new();
    ASN1_TIME_set(tm, time);

    ret = X509_CRL_set_nextUpdate(crl, tm);
    ASN1_TIME_free(tm);
    return openssl_pushresult(L, ret);
  }
}
Пример #6
0
int ScriptApiSecurity::sl_g_load(lua_State *L)
{
	size_t len;
	const char *buf;
	std::string code;
	const char *chunk_name = "=(load)";

	luaL_checktype(L, 1, LUA_TFUNCTION);
	if (!lua_isnone(L, 2)) {
		luaL_checktype(L, 2, LUA_TSTRING);
		chunk_name = lua_tostring(L, 2);
	}

	while (true) {
		lua_pushvalue(L, 1);
		lua_call(L, 0, 1);
		int t = lua_type(L, -1);
		if (t == LUA_TNIL) {
			break;
		} else if (t != LUA_TSTRING) {
			lua_pushnil(L);
			lua_pushliteral(L, "Loader didn't return a string");
			return 2;
		}
		buf = lua_tolstring(L, -1, &len);
		code += std::string(buf, len);
		lua_pop(L, 1); // Pop return value
	}
	if (code[0] == LUA_SIGNATURE[0]) {
		lua_pushnil(L);
		lua_pushliteral(L, "Bytecode prohibited when mod security is enabled.");
		return 2;
	}
	if (luaL_loadbuffer(L, code.data(), code.size(), chunk_name)) {
		lua_pushnil(L);
		lua_insert(L, lua_gettop(L) - 1);
		return 2;
	}
	return 1;
}
Пример #7
0
static LUA_FUNCTION(openssl_rsa_decrypt)
{
  RSA* rsa = CHECK_OBJECT(1, RSA, "openssl.rsa");
  size_t l;
  const unsigned char* from = (const unsigned char *) luaL_checklstring(L, 2, &l);
  int padding = openssl_get_padding(L, 3, "pkcs1");
  int ispriv = lua_isnone(L, 4) ? is_private(rsa) : lua_toboolean(L, 4);
  unsigned char* to = OPENSSL_malloc(RSA_size(rsa));
  int flen = l;

  flen = ispriv
         ? RSA_private_decrypt(flen, from, to, rsa, padding)
         : RSA_public_decrypt(flen, from, to, rsa, padding);
  if (flen > 0)
  {
    lua_pushlstring(L, (const char*)to, flen);
    OPENSSL_free(to);
    return 1;
  }
  OPENSSL_free(to);
  return openssl_pushresult(L, flen);
};
Пример #8
0
static int lqtL_indexfunc (lua_State *L) {
    int i = 1;
    if (lua_isuserdata(L, 1) && !lua_islightuserdata(L, 1)) {
        lua_getmetatable(L, 1);
        lua_pushliteral(L, "__get");
        lua_rawget(L, -2);
        if (lua_istable(L, -1)) {
            lua_pushvalue(L, 2);
            lua_gettable(L, -2);
            if (lua_isfunction(L, -1)) {
                lua_CFunction getter = lua_tocfunction(L, -1);
                if (!getter) return luaL_error(L, "Invalid getter %s", lua_tostring(L, 2));
                return getter(L);
            }
        }
        lua_settop(L, 2);
        lua_getfenv(L, 1); // (1)
        lua_pushvalue(L, 2); // (2)
        lua_gettable(L, -2); // (2)
        if (!lua_isnil(L, -1)) {
            lua_remove(L, -2);
            return 1;
        }
        lua_pop(L, 2); // (0)
    }
    lua_pushnil(L); // (+1)
    while (!lua_isnone(L, lua_upvalueindex(i))) { // (+1)
        lua_pop(L, 1); // (+0)
        lua_pushvalue(L, 2); // (+1)
        if (i==1) {
            lua_rawget(L, lua_upvalueindex(i)); // (+1)
        } else {
            lua_gettable(L, lua_upvalueindex(i)); // (+1)
        }
        if (!lua_isnil(L, -1)) break;
        i++;
    }
    return 1; // (+1)
}
Пример #9
0
static int openssl_xext_new_sk(lua_State* L)
{
  size_t i;
  X509_EXTENSION *x = NULL;
  STACK_OF(X509_EXTENSION) *exts;
  int v3 = 1;
  luaL_checktable(L, 1);
  if (!lua_isnone(L, 2))
    v3 = lua_toboolean(L, 2);

  exts = sk_X509_EXTENSION_new_null();

  for (i = 0; i < lua_rawlen(L, 1); i++)
  {
    lua_rawgeti(L, 1, i + 1);
    x = openssl_new_xextension(L, lua_gettop(L), v3);
    if (x)
      sk_X509_EXTENSION_push(exts, x);
  }
  PUSH_OBJECT(exts, "openssl.stack_of_x509_extension");
  return 1;
};
Пример #10
0
static int openssl_ts_req_nonce(lua_State*L)
{
  TS_REQ* req = CHECK_OBJECT(1, TS_REQ, "openssl.ts_req");
  if (lua_isnone(L, 2))
  {
    const ASN1_INTEGER* ai = TS_REQ_get_nonce(req);
    BIGNUM *bn;
    PUSH_ASN1_INTEGER(L, ai);
    bn = ASN1_INTEGER_to_BN(ai, NULL);
    PUSH_OBJECT(bn, "openssl.bn");
    return 2;
  }
  else
  {
    BIGNUM *bn = BN_get(L, 2);
    ASN1_INTEGER *ai = BN_to_ASN1_INTEGER(bn, NULL);
    int ret = TS_REQ_set_nonce(req, ai);
    ASN1_INTEGER_free(ai);
    BN_free(bn);
    return openssl_pushresult(L, ret);
  }
}
Пример #11
0
static LUA_FUNCTION(openssl_digest_ctx_data)
{
  EVP_MD_CTX *ctx = CHECK_OBJECT(1, EVP_MD_CTX, "openssl.evp_digest_ctx");
  if (lua_isnone(L, 2))
  {
    lua_pushlstring(L, ctx->md_data, ctx->digest->ctx_size);
    return 1;
  }
  else
  {
    size_t l;
    const char* d = luaL_checklstring(L, 2, &l);
    if (l == (size_t)ctx->digest->ctx_size)
    {
      memcpy(ctx->md_data, d, l);
    }
    else
      luaL_error(L, "data with wrong data");
  }

  return 0;
}
Пример #12
0
static int openssl_xext_data(lua_State* L)
{
  int ret = 0;
  X509_EXTENSION *x = CHECK_OBJECT(1, X509_EXTENSION, "openssl.x509_extension");
  if (lua_isnone(L, 2))
  {
    ASN1_STRING *s = X509_EXTENSION_get_data(x);
    s = ASN1_STRING_dup(s);
    PUSH_OBJECT(s, "openssl.asn1_string");
    return 1;
  }
  else if (lua_isstring(L, 2))
  {
    size_t size;
    const char* data = lua_tolstring(L, 2, &size);
    ASN1_STRING* s = ASN1_STRING_type_new(V_ASN1_OCTET_STRING);
    if (ASN1_STRING_set(s, data, size) == 1)
    {
      ret = X509_EXTENSION_set_data(x, s);
    }
    ASN1_STRING_free(s);
    return openssl_pushresult(L, ret);
  }
  else
  {
    ASN1_STRING* s = CHECK_GROUP(2, ASN1_STRING, "openssl.asn1group");
    if (ASN1_STRING_type(s) == V_ASN1_OCTET_STRING)
    {
      int ret;
      ret = X509_EXTENSION_set_data(x, s);
      return openssl_pushresult(L, ret);
    }
    else
    {
      luaL_argerror(L, 2, "asn1_string type must be octet");
    }
  }
  return 0;
};
Пример #13
0
/***
get FIPS mode
@function FIPS_mode
@treturn boolean return true when FIPS mode enabled, false when FIPS mode disabled.
*/
static int openssl_fips_mode(lua_State *L)
{
#if defined(LIBRESSL_VERSION_NUMBER)
  return 0;
#else
  int ret =0, on = 0;
  if(lua_isnone(L, 1))
  {
    on = FIPS_mode();
    lua_pushboolean(L, on);
    return 1;
  }

  on = auxiliar_checkboolean(L, 1);
  ret = FIPS_mode_set(on);
  if(ret)
    lua_pushboolean(L, ret);
  else
    ret = openssl_pushresult(L, ret);
  return ret;
#endif
}
Пример #14
0
	bool LuaState::IsOfType(int index, LuaType type) const
	{
		switch (type)
		{
			case LuaType_Boolean:
				return lua_isboolean(m_state, index) != 0;

			case LuaType_Function:
				return lua_isfunction(m_state, index) != 0;

			case LuaType_LightUserdata:
				return lua_islightuserdata(m_state, index) != 0;

			case LuaType_Nil:
				return lua_isnil(m_state, index) != 0;

			case LuaType_None:
				return lua_isnone(m_state, index) != 0;

			case LuaType_Number:
				return lua_isnumber(m_state, index) != 0;

			case LuaType_String:
				return lua_isstring(m_state, index) != 0;

			case LuaType_Table:
				return lua_istable(m_state, index) != 0;

			case LuaType_Thread:
				return lua_isthread(m_state, index) != 0;

			case LuaType_Userdata:
				return lua_isuserdata(m_state, index) != 0;
		}

		NazaraError("Lua type not handled (0x" + String::Number(type, 16) + ')');
		return false;
	}
Пример #15
0
static int openssl_ec_group_point_conversion_form(lua_State*L)
{
  EC_GROUP* group = CHECK_OBJECT(1, EC_GROUP, "openssl.ec_group");
  point_conversion_form_t form = 0;
  if (lua_isnone(L, 2))
  {
    form = EC_GROUP_get_point_conversion_form(group);
    if (form == POINT_CONVERSION_COMPRESSED)
      lua_pushstring(L, "compressed");
    else if (form == POINT_CONVERSION_UNCOMPRESSED)
      lua_pushstring(L, "uncompressed");
    else if (form == POINT_CONVERSION_HYBRID)
      lua_pushstring(L, "hybrid");
    else
      lua_pushnil(L);
    lua_pushinteger(L, form);
    return 2;
  } else if (lua_isstring(L, 2))
  {
    const char* options[] = {"compressed", "uncompressed", "hybrid", NULL};
    int f = luaL_checkoption(L, 2, NULL, options);
    if (f == 0)
      form = POINT_CONVERSION_COMPRESSED;
    else if (f == 1)
      form = POINT_CONVERSION_UNCOMPRESSED;
    else if (f == 2)
      form = POINT_CONVERSION_HYBRID;
    else
      luaL_argerror(L, 2, "not accept value point_conversion_form");
    EC_GROUP_set_point_conversion_form(group, form);
  } else if (lua_isnumber(L, 2))
  {
    form = luaL_checkint(L, 2);
    EC_GROUP_set_point_conversion_form(group, form);
  } else
    luaL_argerror(L, 2, "not accept type of point_conversion_form");
  return 0;
}
Пример #16
0
/***
set extension of x509_req object
@function extensions
@tparam stack_of_x509_extension extensions
@treturn boolean result true for success
*/
static LUA_FUNCTION(openssl_csr_extensions)
{
  X509_REQ *csr = CHECK_OBJECT(1, X509_REQ, "openssl.x509_req");
  if (lua_isnone(L, 2))
  {
    STACK_OF(X509_EXTENSION) *sk = X509_REQ_get_extensions(csr);
    if (sk)
    {
      openssl_sk_x509_extension_totable(L, sk);
      sk_X509_EXTENSION_pop_free(sk, X509_EXTENSION_free);
    }
    else
      lua_pushnil(L);
    return 1;
  }
  else
  {
    STACK_OF(X509_EXTENSION) *sk = openssl_sk_x509_extension_fromtable(L, 2);
    int ret = X509_REQ_add_extensions(csr, sk);
    sk_X509_EXTENSION_pop_free(sk, X509_EXTENSION_free);
    return openssl_pushresult(L, ret);
  }
}
Пример #17
0
int32_t context_lua_t::lua_ref_callback_entry(lua_State *L)
{
	int upvalue_count = 0;
	while (!lua_isnone(L, lua_upvalueindex(upvalue_count + 1))) {
		++upvalue_count;
	}
	ASSERT(upvalue_count > 1);
	lua_CFunction adjust_resume_args = (lua_CFunction)lua_touserdata(L, lua_upvalueindex(upvalue_count));
	if (adjust_resume_args) {
		adjust_resume_args(L);
	}
	--upvalue_count;
	int resume_count = lua_gettop(L);
	lua_checkstack(L, upvalue_count);
	lua_pushvalue(L, lua_upvalueindex(upvalue_count));
	lua_insert(L, 1); /* put callback closure as first arg */
	for (int i = 1; i < upvalue_count; ++i) {
		lua_pushvalue(L, lua_upvalueindex(i));
	}
	/* lua_callback_entry_continue makes the coroutine can be recovered. */
	int status = lua_pcallk(L, upvalue_count + resume_count - 1, LUA_MULTRET, 0, 0, lua_ref_callback_entry_continue);
	return lua_ref_callback_entry_finish(L, (status == LUA_OK));
}
Пример #18
0
/*
 * Function: New
 *
 * Creates a new <SystemPath> object
 *
 * > path = SystemPath.New(sectorX, sectorY, sectorZ, systemIndex, bodyIndex)
 *
 * Parameters:
 *
 *   sectorX - galactic sector X coordinate
 *
 *   sectorY - galactic sector Y coordinate
 *
 *   sectorZ - galactic sector Z coordinate
 *
 *   systemIndex - the numeric index of the system within the sector
 *
 *   bodyIndex - optional, the numeric index of a specific body within the
 *               system. Defaults to 0, which typically corresponds to the
 *               primary star.
 *
 * Availability:
 *
 *   alpha 10, alpha 13 (updated)
 *
 * Status:
 *
 *   stable
 */
static int l_sbodypath_new(lua_State *l)
{
	int sector_x = luaL_checkinteger(l, 1);
	int sector_y = luaL_checkinteger(l, 2);
	int sector_z = luaL_checkinteger(l, 3);
	int system_idx = luaL_checkinteger(l, 4);

	int sbody_id = 0;
	if (!lua_isnone(l, 5))
		sbody_id = luaL_checkinteger(l, 5);
	
	Sector s(sector_x, sector_y, sector_z);
	if (size_t(system_idx) >= s.m_systems.size())
		luaL_error(l, "System %d in sector [%d,%d,%d] does not exist", system_idx, sector_x, sector_y, sector_z);

	// XXX explode if sbody_id doesn't exist in the target system?
	
	SystemPath *path = new SystemPath(sector_x, sector_y, sector_z, system_idx, sbody_id);

	LuaSystemPath::PushToLuaGC(path);

	return 1;
}
Пример #19
0
int ModApiMainMenu::l_delete_favorite(lua_State *L)
{
	GUIEngine* engine = getGuiEngine(L);
	assert(engine != 0);

	std::vector<ServerListSpec> servers;

	std::string listtype = "local";

	if (!lua_isnone(L,2)) {
		listtype = luaL_checkstring(L,2);
	}

	if ((listtype != "local") &&
		(listtype != "online"))
		return 0;

#if USE_CURL
	if(listtype == "online") {
		servers = ServerList::getOnline();
	} else {
		servers = ServerList::getLocal();
	}
#else
	servers = ServerList::getLocal();
#endif

	int fav_idx	= luaL_checkinteger(L,1) -1;

	if ((fav_idx >= 0) &&
			(fav_idx < (int) servers.size())) {

		ServerList::deleteEntry(servers[fav_idx]);
	}

	return 0;
}
Пример #20
0
static int getchar_cb(lua_State* L)
{
	int t = -1;
	if (!lua_isnone(L, 1))
		t = luaL_checkinteger(L, 1);

	dpy_setcursor(cursorx, cursory);
	dpy_sync();

	for (;;)
	{
		uni_t c = dpy_getchar(t);
		if (c <= 0)
		{
			const char* s = dpy_getkeyname(c);
			if (s)
			{
				lua_pushstring(L, s);
				break;
			}
		}

		if (emu_wcwidth(c) > 0)
		{
			static char buffer[8];
			char* p = buffer;

			writeu8(&p, c);
			*p = '\0';

			lua_pushstring(L, buffer);
			break;
		}
	}

	return 1;
}
Пример #21
0
// parse_json(str[, nullvalue])
int ModApiUtil::l_parse_json(lua_State *L)
{
	NO_MAP_LOCK_REQUIRED;

	const char *jsonstr = luaL_checkstring(L, 1);

	// Use passed nullvalue or default to nil
	int nullindex = 2;
	if (lua_isnone(L, nullindex)) {
		lua_pushnil(L);
		nullindex = lua_gettop(L);
	}

	Json::Value root;

	{
		Json::Reader reader;
		std::istringstream stream(jsonstr);

		if (!reader.parse(stream, root)) {
			errorstream << "Failed to parse json data "
				<< reader.getFormattedErrorMessages();
			errorstream << "data: \"" << jsonstr << "\""
				<< std::endl;
			lua_pushnil(L);
			return 1;
		}
	}

	if (!push_json_value(L, root, nullindex)) {
		errorstream << "Failed to parse json data, "
			<< "depth exceeds lua stack limit" << std::endl;
		errorstream << "data: \"" << jsonstr << "\"" << std::endl;
		lua_pushnil(L);
	}
	return 1;
}
Пример #22
0
static int IPairs(lua_State* L)
{
	lua_Number i = lua_tonumber(L, 2);
	luaL_checktype(L, 1, LUA_TTABLE);

	// initializing
	if ((i == 0) && lua_isnone(L, 2)) {
		PushRealTable(L, 1, "sipairs");
		lua_pushcclosure(L, IPairs, 1); // iterator
		lua_pushvalue(L, 1);            // state (table)
		lua_pushnumber(L, 0);           // initial value
		return 3;
	}

	lua_pushnil(L);
	lua_pushnil(L); // gets removed by lua_pop beneath!
	do {
		lua_pop(L, 2); // remove old i,v pair

		// incrementing
		i++;
		lua_pushnumber(L, i);                        // key (i)
		lua_rawgeti(L, lua_upvalueindex(1), (int)i); // value (v)

		// no more elements left in the table
		if (lua_isnil(L, -1)) {
			return 1;
		}
	} while (!SafeType(L, -1));

	// wrap tables
	if (lua_istable(L, -1)) {
		WrapTable(L);
	}

	return 2;
}
Пример #23
0
// log([level,] text)
// Writes a line to the logger.
// The one-argument version logs to infostream.
// The two-argument version accepts a log level.
// Either the special case "deprecated" for deprecation notices, or any specified in
// Logger::stringToLevel(name).
int ModApiUtil::l_log(lua_State *L)
{
	NO_MAP_LOCK_REQUIRED;
	std::string text;
	LogLevel level = LL_NONE;
	if (lua_isnone(L, 2)) {
		text = luaL_checkstring(L, 1);
	} else {
		std::string name = luaL_checkstring(L, 1);
		text = luaL_checkstring(L, 2);
		if (name == "deprecated") {
			log_deprecated(L, text);
			return 0;
		}
		level = Logger::stringToLevel(name);
		if (level == LL_MAX) {
			warningstream << "Tried to log at unknown level '" << name
				<< "'.  Defaulting to \"none\"." << std::endl;
			level = LL_NONE;
		}
	}
	g_logger.log(level, text);
	return 0;
}
Пример #24
0
int ModApiMainMenu::l_get_favorites(lua_State *L)
{
	GUIEngine* engine = getGuiEngine(L);
	assert(engine != 0);

	std::string listtype = "local";

	if (!lua_isnone(L,1)) {
		listtype = luaL_checkstring(L,1);
	}

	std::vector<ServerListSpec> servers;
#if USE_CURL
	if(listtype == "online") {
		servers = ServerList::getOnline();
	} else {
		servers = ServerList::getLocal();
	}
#else
	servers = ServerList::getLocal();
#endif

	lua_newtable(L);
	int top = lua_gettop(L);
	unsigned int index = 1;

	for (unsigned int i = 0; i < servers.size(); i++)
	{
		lua_pushnumber(L,index);

		lua_newtable(L);
		int top_lvl2 = lua_gettop(L);

		if (servers[i]["clients"].asString().size()) {

			const char* clients_raw = servers[i]["clients"].asString().c_str();
			char* endptr = 0;
			int numbervalue = strtol(clients_raw,&endptr,10);

			if ((*clients_raw != 0) && (*endptr == 0)) {
				lua_pushstring(L,"clients");
				lua_pushnumber(L,numbervalue);
				lua_settable(L, top_lvl2);
			}
		}

		if (servers[i]["clients_max"].asString().size()) {

			const char* clients_max_raw = servers[i]["clients_max"].asString().c_str();
			char* endptr = 0;
			int numbervalue = strtol(clients_max_raw,&endptr,10);

			if ((*clients_max_raw != 0) && (*endptr == 0)) {
				lua_pushstring(L,"clients_max");
				lua_pushnumber(L,numbervalue);
				lua_settable(L, top_lvl2);
			}
		}

		if (servers[i]["version"].asString().size()) {
			lua_pushstring(L,"version");
			lua_pushstring(L,servers[i]["version"].asString().c_str());
			lua_settable(L, top_lvl2);
		}

		if (servers[i]["password"].asString().size()) {
			lua_pushstring(L,"password");
			lua_pushboolean(L,true);
			lua_settable(L, top_lvl2);
		}

		if (servers[i]["creative"].asString().size()) {
			lua_pushstring(L,"creative");
			lua_pushboolean(L,true);
			lua_settable(L, top_lvl2);
		}

		if (servers[i]["damage"].asString().size()) {
			lua_pushstring(L,"damage");
			lua_pushboolean(L,true);
			lua_settable(L, top_lvl2);
		}

		if (servers[i]["pvp"].asString().size()) {
			lua_pushstring(L,"pvp");
			lua_pushboolean(L,true);
			lua_settable(L, top_lvl2);
		}

		if (servers[i]["description"].asString().size()) {
			lua_pushstring(L,"description");
			lua_pushstring(L,servers[i]["description"].asString().c_str());
			lua_settable(L, top_lvl2);
		}

		if (servers[i]["name"].asString().size()) {
			lua_pushstring(L,"name");
			lua_pushstring(L,servers[i]["name"].asString().c_str());
			lua_settable(L, top_lvl2);
		}

		if (servers[i]["address"].asString().size()) {
			lua_pushstring(L,"address");
			lua_pushstring(L,servers[i]["address"].asString().c_str());
			lua_settable(L, top_lvl2);
		}

		if (servers[i]["port"].asString().size()) {
			lua_pushstring(L,"port");
			lua_pushstring(L,servers[i]["port"].asString().c_str());
			lua_settable(L, top_lvl2);
		}

		lua_settable(L, top);
		index++;
	}
	return 1;
}
Пример #25
0
static int io_close(lua_State *L) {
	if (lua_isnone(L, 1))  /* no argument? */
		lua_getfield(L, LUA_REGISTRYINDEX, IO_OUTPUT);  /* use standard output */
	tofile(L);  /* make sure argument is an open stream */
	return aux_close(L);
}
Пример #26
0
/*!
 * @breif Draw image
 * drawImage(surface, image)
 * drawImage(surface, {x, y}, image)
 * drawImage(surface, {x, y}, image, {x, y, width, height})
 * drawImage(surface, {x, y, width, height}, image)
 * drawImage(surface, {x, y, width, height}, image, {x, y, width, height})
 * drawImage(surface, x, y, image)
 * drawImage(surface, x, y, image, x, y, width, height)
 * drawImage(surface, x, y, width, height, image)
 * drawImage(surface, x, y, width, height, image, x, y, width, height)
 */
static int32_t
luaSDL_drawImage(
	lua_State *L
)
{
	SDL_Surface *surface = (SDL_Surface *) lua_touserdata(L, 1);
	int32_t result;
	SDL_Surface *image;

	if (lua_isnone(L, 3)) { /* image */
		image = (SDL_Surface *)lua_touserdata(L, 2);
		if (image == NULL) {
			lua_pushnil(L);
			return 1;
		}
		result = SDL_BlitSurface(image, NULL, surface, NULL);
	}
	else if (!lua_istable(L, 2)) { /* number mode */
		if (lua_islightuserdata(L, 4)) {
			SDL_Rect dstrect;
			dstrect.x = (int16_t)lua_tointeger(L, 2);
			dstrect.y = (int16_t)lua_tointeger(L, 3);
			image = (SDL_Surface *)lua_touserdata(L, 4);
			if (lua_isnoneornil(L, 5)) { /* x, y, image */
				result = SDL_BlitSurface(image, NULL, surface, &dstrect);
			}
			else { /* x, y, image, x, y, width, height */
				SDL_Rect srcrect;
				srcrect.x = (int16_t)lua_tointeger(L, 5);
				srcrect.y = (int16_t)lua_tointeger(L, 6);
				srcrect.w = (uint16_t)lua_tointeger(L, 7);
				srcrect.h = (uint16_t)lua_tointeger(L, 8);
				result = SDL_BlitSurface(image, &srcrect, surface, &dstrect);
			}
		}
		else {
			SDL_Rect dstrect;
			dstrect.x = (int16_t)lua_tointeger(L, 2);
			dstrect.y = (int16_t)lua_tointeger(L, 3);
			dstrect.w = (uint16_t)lua_tointeger(L, 4);
			dstrect.h = (uint16_t)lua_tointeger(L, 5);
			image = (SDL_Surface *)lua_touserdata(L, 6);
			if (lua_isnoneornil(L, 7)) { /* x, y, width, height, image */
				result = drawImageZoom(image, NULL, surface, &dstrect);
			}
			else { /* x, y, width, height, image, x, y, width, height */
				SDL_Rect srcrect;
				srcrect.x = (int16_t)lua_tointeger(L, 5);
				srcrect.y = (int16_t)lua_tointeger(L, 6);
				srcrect.w = (uint16_t)lua_tointeger(L, 7);
				srcrect.h = (uint16_t)lua_tointeger(L, 8);
				result = drawImageZoom(image, &srcrect, surface, &dstrect);
			}
		}
	}
	else if (lua_isnone(L, 4)) {

		lua_getfield(L, 2, "x");
		lua_getfield(L, 2, "y");
		lua_getfield(L, 2, "width");
		lua_getfield(L, 2, "height");
		if (lua_isnil(L, 6) || lua_isnil(L, 7)) { /* {x, y}, image */
			SDL_Rect dstrect;
			dstrect.x = (int16_t)lua_tointeger(L, 4);
			dstrect.y = (int16_t)lua_tointeger(L, 5);
			image = (SDL_Surface *)lua_touserdata(L, 3);
			if (image == NULL) {
				lua_pushnil(L);
				return 1;
			}
			result = SDL_BlitSurface(image, NULL, surface, &dstrect);
		}
		else { /* {x, ,y ,width, height}, image */
			SDL_Rect dstrect;

			dstrect.x = (int16_t)lua_tointeger(L, 4);
			dstrect.y = (int16_t)lua_tointeger(L, 5);
			dstrect.w = (uint16_t)lua_tointeger(L, 6);
			dstrect.h = (uint16_t)lua_tointeger(L, 7);
			image = (SDL_Surface *)lua_touserdata(L, 3);
			if (image == NULL) {
				lua_pushnil(L);
				return 1;
			}
			result = drawImageZoom(image, NULL, surface, &dstrect);
		}
	}
	else {
		SDL_Rect srcrect;
		lua_getfield(L, 2, "x");
		lua_getfield(L, 2, "y");
		lua_getfield(L, 2, "width");
		lua_getfield(L, 2, "height");
		lua_getfield(L, 4, "x");
		lua_getfield(L, 4, "y");
		lua_getfield(L, 4, "width");
		lua_getfield(L, 4, "height");
		image = (SDL_Surface *)lua_touserdata(L, 3);
		if (image == NULL) {
			lua_pushnil(L);
			return 1;
		}

		srcrect.x = (int16_t)lua_tointeger(L, 9);
		srcrect.y = (int16_t)lua_tointeger(L, 10);
		srcrect.w = (uint16_t)lua_tointeger(L, 11);
		srcrect.h = (uint16_t)lua_tointeger(L, 12);
		if (lua_isnil(L, 7) || lua_isnil(L, 8)) { /* {x, y}, image, {x, y, width, height} */
			SDL_Rect dstrect;
			dstrect.x = (int16_t)lua_tointeger(L, 5);
			dstrect.y = (int16_t)lua_tointeger(L, 6);
			result = SDL_BlitSurface(image, &srcrect, surface, &dstrect);
		}
		else { /* {x, y, width, height}, image, {x, y, width, height} */
			SDL_Rect dstrect;
			dstrect.x = (int16_t)lua_tointeger(L, 5);
			dstrect.y = (int16_t)lua_tointeger(L, 6);
			dstrect.w = (uint16_t)lua_tointeger(L, 7);
			dstrect.h = (uint16_t)lua_tointeger(L, 8);
			result = drawImageZoom(image, &srcrect, surface, &dstrect);
		}
	}

	if (result == 0) {
		lua_pushinteger(L, SP_OK);
	}
	else {
		fprintf(stderr, "[%s] Error : %s\n", __FUNCTION__, SDL_GetError());
		lua_pushinteger(L, SP_FAIL);
	}
	return 1;
}
Пример #27
0
JNIEXPORT jboolean JNICALL Java_m_lua_Lua_isNone
		(JNIEnv* env, jobject thiz, jlong nativeObj, jint idx) {
	pushJNIEnv(env, nativeObj);
	return (jboolean) lua_isnone((lua_State*) nativeObj, idx);
}
Пример #28
0
static int io_close (lua_State *L) {
    if (lua_isnone(L, 1))
        LUA_IO_GETFIELD(IO_OUTPUT);
    tofile(L);  /* make sure argument is a file */
    return aux_close(L);
}
Пример #29
0
static int io_close (lua_State *L) {
  if (lua_isnone(L, 1))
    lua_rawgeti(L, LUA_ENVIRONINDEX, IO_OUTPUT);
  tofile(L);  /* make sure argument is a file */
  return aux_close(L);
}
Пример #30
0
template<> bool Eluna::CHECKVAL<bool>(lua_State* L, int narg, bool def)
{
    return lua_isnone(L, narg) ? def : lua_isnumber(L, narg) ? luaL_optnumber(L, narg, 1) ? true : false : lua_toboolean(L, narg);
}