Example #1
0
void*
luaCheckUserData(lua_State *lua, const char *name, int index) {
    void *ptr = luaL_checkudata(lua, index, name);
    if (NULL == ptr) {
        throw BadType(name, index);
    }
    luaL_argcheck(lua, ptr != NULL, index, "`ud' expected");
    return ptr;

}
Example #2
0
static TypedValue
luaReadTableInternal(lua_State *lua, int index) {
    lua_pushnil(lua);
    TypedValue value = TypedValue::createArrayValue();
    bool is_map  = false;
    bool is_first  = true;
    while (lua_next(lua, index)) {
        if (is_first) {
            is_first = false;
            is_map = !lua_isnumber(lua, -2);
            if (is_map) {
                value = TypedValue::createMapValue();
            }
        }
        std::string key;
        if (is_map) {
            key.assign(lua_tostring(lua, -2));
        }
        switch (lua_type(lua, -1)) {
            case LUA_TNIL:
                value.add(key, TypedValue());
                break;
            case LUA_TBOOLEAN:
                value.add(key, TypedValue(0 != lua_toboolean(lua, -1)));
                break;
            case LUA_TNUMBER: {
                double d = lua_tonumber(lua, -1);
                isLongInteger(d) ? value.add(key, TypedValue((boost::int64_t)d)) :
                    value.add(key, TypedValue(d));
                break;
            }
            case LUA_TSTRING:
                value.add(key, TypedValue(std::string(lua_tostring(lua, -1))));
                break;
            case LUA_TTABLE:
                value.add(key, luaReadTableInternal(lua, lua_gettop(lua)));
                break;
            default:
                throw BadType("nil, bool, number, string or table", -1);
        }
        lua_pop(lua, 1);
    }
    return value;
}
Example #3
0
///////////////////////////////////////////////////////////////////////////////
// validatePixelSizeInBytes - compute pixel size, measured in bytes
///////////////////////////////////////////////////////////////////////////////
GLsizei
Image::validatePixelSizeInBytes() {
	switch (format()) {
	case GL_LUMINANCE:
		_pixelSizeInBytes = 1;
		break;
	case GL_LUMINANCE_ALPHA:
		_pixelSizeInBytes = 2;
		break;
	case GL_RGB:
		_pixelSizeInBytes = 3;
		break;
	case GL_RGBA:
		_pixelSizeInBytes = 4;
		break;
	default:
		throw BadFormat(format());
	}

	switch (type()) {
	case GL_BYTE:
	case GL_UNSIGNED_BYTE:
		break;
	case GL_SHORT:
	case GL_UNSIGNED_SHORT:
		_pixelSizeInBytes <<= 1;
		break;
	case GL_INT:
	case GL_UNSIGNED_INT:
	case GL_FLOAT:
		_pixelSizeInBytes <<= 2;
		break;
	default:
		throw BadType(type());
	}

	validate(vbPixelSizeInBytes);
	return _pixelSizeInBytes;
}
Example #4
0
 T operator()(NoType) const
 {
     // Error: trying to convert an empty value
     PONDER_ERROR(BadType(ValueType::None, mapType<T>()));
 }
Example #5
0
void
luaCheckTable(lua_State *lua, int index) {
    if (!lua_istable(lua, index)) {
        throw BadType("table", index);
    }
}
Example #6
0
void
luaCheckBoolean(lua_State *lua, int index) {
    if (!lua_isboolean(lua, index)) {
        throw BadType("boolean", index);
    }
}
Example #7
0
void
luaCheckString(lua_State *lua, int index) {
    if (!lua_isstring(lua, index)) {
        throw BadType("string", index);
    }
}
Example #8
0
void
luaCheckNumber(lua_State *lua, int index) {
    if (!lua_isnumber(lua, index)) {
        throw BadType("number", index);
    }
}