Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lua内实现java接口遇到的问题 #2

Open
mulingLHY opened this issue Mar 21, 2021 · 0 comments
Open

lua内实现java接口遇到的问题 #2

mulingLHY opened this issue Mar 21, 2021 · 0 comments

Comments

@mulingLHY
Copy link

在实现接口逻辑的lua函数里如果返回数字,而java层函数返回值声明不是基本类型,那么将会被强制转化为Integer,原因在于LuaState里convertLuaNumber的实现逻辑存在问题

......
else if (retType.isAssignableFrom(Number.class))
		{
			// Checks all possibilities of number types
			if (retType.isAssignableFrom(Integer.class))
			{
				return new Integer(db.intValue());
			}
			else if (retType.isAssignableFrom(Long.class))
			{
				return new Long(db.longValue());
			}
			else if (retType.isAssignableFrom(Float.class))
			{
				return new Float(db.floatValue());
			}
			else if (retType.isAssignableFrom(Double.class))
			{
				return db;
			}
			else if (retType.isAssignableFrom(Byte.class))
			{
				return new Byte(db.byteValue());
			}
			else if (retType.isAssignableFrom(Short.class))
			{
				return new Short(db.shortValue());
			}
		}

这一系列isAssignableFrom的判断应该是写反了,否则如果retType是Object,那么所有判断都是符合的,但实际上总是运行第一个判断逻辑,这与上面实际遇到的问题是一致的

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant