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

[Question] Lua and passing array as function argument #63

Closed
TheAifam5 opened this issue Mar 1, 2015 · 3 comments
Closed

[Question] Lua and passing array as function argument #63

TheAifam5 opened this issue Mar 1, 2015 · 3 comments
Labels

Comments

@TheAifam5
Copy link

Hi,
I have problem, how to pass array (from LUA) to C++ function?
And how to get array size and items?

LUA:

srututuArray({0xDA8208, 0x13A8, 0x4, 0x0018})
@eugeneko
Copy link

eugeneko commented Mar 1, 2015

Just write simple wrapper over std::vector like built-in Qt wrappers.

@SteveKChiu
Copy link
Owner

You can use LuaRef to capture the Lua value, something like the following:

void srututuArray(LuaRef list)
{
    for (int i = 1, n = list.len(); i <= n; i++) {
        int item = list.get<int>(i);
        ...
    }
}

or you can use Lua::getList to convert LuaRef to std::vector (or other list containers):

void srututuArray(LuaRef ref)
{
    std::vector<int> list = Lua::getList<std::vector<int>>(ref);
    ...
}

@SteveKChiu
Copy link
Owner

This seems to be resolved, please open new issue if you have more questions.

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

3 participants