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

Problem with CppBindClass::addConstant #61

Closed
wizofoz opened this issue Jan 27, 2015 · 5 comments
Closed

Problem with CppBindClass::addConstant #61

wizofoz opened this issue Jan 27, 2015 · 5 comments
Labels

Comments

@wizofoz
Copy link

wizofoz commented Jan 27, 2015

I'm stuck with a problem with CppBindClass::setConstant but after several hours I haven't solved it yet.

CPP:

.beginModule("myModule")
    .addConstant("myConst", 10) 
.endModule()

.beginClass<myClass>("myClass")
    .addConstant("myConst", 10) 
.endClass()

Lua:

print(myModule.myConst)  -- prints 10 correctly
print(myClass.myConst) -- Problem here: prints 'nil' value
print(myClass.___getters.myConst) -- prints 10 correctly

TDM GCC 4.9.2 64 bit under WIndows 7 with LuaJIT 2.0.3

Unfortunately it seems that I'm unable to solve this myself... any advice?
Thank you again very much

@SteveKChiu
Copy link
Owner

The meta method seems to have some problem, some changes lost during re-factoring the code, I will fix it ASAP.

@SteveKChiu SteveKChiu added the bug label Jan 27, 2015
SteveKChiu added a commit that referenced this issue Jan 28, 2015
@wizofoz
Copy link
Author

wizofoz commented Jan 28, 2015

Thank you for your prompt fix, it works perfectly! Now I can merge some modules that I had to use only for enums constants with classes

@wizofoz wizofoz closed this as completed Jan 28, 2015
@Sakari369
Copy link

I am seeing this same issue @SteveKChiu

CPP

    LuaIntf::LuaBinding(_lua).beginClass<InputHandler>("InputHandler")
        .addConstructor(LUA_ARGS())
        .addFunction("keyHeld",         &InputHandler::keyHeld)
        .addConstant("KEY_RIGHT",       GLFW_KEY_RIGHT)
        .addConstant("KEY_LEFT",        GLFW_KEY_LEFT)
        .addConstant("KEY_DOWN",        GLFW_KEY_RIGHT)
        .addConstant("KEY_UP",          GLFW_KEY_UP)
        .addConstant("constant",        10)
    .endClass();

lua

    print(input.KEY_RIGHT)
    print(input.___getters)
    print(#input.___getters)

output

nil
table: 0x7fb87953d040
0

Seems it is not adding these constants at all.
Mac Os X, Apple LLVM version 6.1.0 (clang-602.0.53) (based on LLVM 3.6.0svn)
Target: x86_64-apple-darwin14.5.0
Thread model: posix

@l0ud
Copy link

l0ud commented Jan 8, 2016

@inDigiNeous
Maybe it's just example, but you're using "input" instead of class name "InputHandler" in your code.

@SteveKChiu
Copy link
Owner

Yes constant need to be accessed by class name, not by instance.
It is pretty much the same as static property.

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

No branches or pull requests

4 participants