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

pushJavaObject注入对象的类成员类型Integer无法识别 #4

Open
jsuisen opened this issue Jul 31, 2019 · 1 comment
Open

pushJavaObject注入对象的类成员类型Integer无法识别 #4

jsuisen opened this issue Jul 31, 2019 · 1 comment

Comments

@jsuisen
Copy link

jsuisen commented Jul 31, 2019

Java:

    MyBean myBean;
    //测试全局变量参数读写
    @Test
    public void testUpdateMyBean() {
        try {
            Log.d("testUpdateMyBean", "=============== test1");
            LuaState lua = LuaStateFactory.newLuaState();
            lua.openLibs();
    
            myBean = new MyBean();
            myBean.name = "zhang3";
            myBean.age = 18;
    
            System.out.println(myBean);
    
            lua.pushJavaObject(myBean);
            lua.setGlobal("myBean");
    
            String str = Config.getRawString(ctx, R.raw.testupdatemybean);
            System.out.println(str);
            int result = lua.LdoString(str);
            System.out.println("result==" + result);
            String msg = lua.toString(-1);
            System.out.println("msg==" + msg);
    
            lua.getGlobal("myBean");
            myBean = (MyBean) lua.toJavaObject(-1);
            lua.pop(1);
            System.out.println(myBean);
    
            lua.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        Log.d("testUpdateMyBean", "=============== test2");
    }
    
    public static class MyBean {
        private String name;
        private Integer age;
    
        public String getName() {
            return name;
        }
    
        public void setName(String name) {
            this.name = name;
        }
    
        public Integer getAge() {
            return age;
        }
    
        public void setAge(Integer age) {
            this.age = age;
        }
    
        @Override
        public String toString() {
            return "MyBean{" +
                    "name='" + name + '\'' +
                    ", age=" + age +
                    '}';
        }
    }

testupdatemybean.lua:

        myBean:setName('li4')
        myBean:setAge(50)

错误日志:

Invalid method call. No such method.

@ichenhe
Copy link
Owner

ichenhe commented Aug 11, 2019

可能确实存在问题,暂时没时间细看。
暂时直接使用 int?

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

2 participants