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

const variables? #12

Closed
krisr opened this issue Sep 15, 2014 · 4 comments
Closed

const variables? #12

krisr opened this issue Sep 15, 2014 · 4 comments

Comments

@krisr
Copy link
Contributor

krisr commented Sep 15, 2014

Hey Steve,

Any plans to support const variables? For example, I would like to export const globals with addVariable if possible, but I'm also happy writing a addProperty + lambda. However, I'm less clear how I would expose a const field on a class, since I haven't checked if you have access to the instance in the lambda.

Thanks again,
Kris

@krisr
Copy link
Contributor Author

krisr commented Sep 15, 2014

Actually, I was able to create a patch that fixes the issues with const non-ref variable primitives. I'll create a PR for your review in case you are interested. I'm sure there is more work required for non-primitives which I can probably handle as well.

@krisr
Copy link
Contributor Author

krisr commented Sep 15, 2014

Here's the commit I'm working on in case you have any design feedback:
krisr@38423f4

It's a little awkward because of the writeable property. I removed it entirely, but that makes the API a little more confusing and less discoverable. Perhaps it would be better to leave it for the const version and assert, or move the specialization for const further up the stack into LuaValue or something.

@SteveKChiu
Copy link
Owner

Wouldn't it be simpler by adding:

    /**
     * Add or replace a const data member.
     */
    template <typename V>
    CppBindClass<T>& addVariable(const char* name, const V T::* v)
    {
        setMemberGetter(name, LuaRef::createFunction(state(), &CppBindClassVariable<T, V>::get, const_cast<V T::*>(v)));
        setMemberReadOnly(name);
        return *this;
    }

@krisr
Copy link
Contributor Author

krisr commented Sep 16, 2014

That looks better. I'll give it a try.

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

No branches or pull requests

2 participants