YetAnotherForum
Welcome Guest Search | Active Topics | Log In | Register

Retrieving values from Table
matty
#1 Posted : Monday, June 12, 2017 3:54:36 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 6/12/2017(UTC)
Posts: 5

Thanks: 0 times
Was thanked: 0 time(s) in 0 post(s)
So I have a squirrel function that calls a C function the argument being is a table. I would like to be able to check and retrieve (key, value) pairs from the table, but sq_rawget always throws the error "rawget works only on array/table/instance and class" despite sq_gettype returning OT_TABLE.

Code:

// squirrel
tableTest = {
    test_one = "string"
    test_two = 123
    test_three = true
}


Code:

// C
if (sq_gettype(v, -1) == OT_TABLE) {
    printf("this is a table\n");
    printf("table size: %d\n", sq_getsize(v, -1));

    if (SQ_FAILED(sq_rawget(v, -1))) {
        const char* err;
        sq_getlasterror(v);
        sq_getstring(v, -1, &err);
        printf("error: %s\n", err); // error "the index doesn't exist"
    }

    // return sq_rawget(v, -1); // error "rawget works only on array/table/instance and class"
}


from what I understand from the function sq_rawget will pop the first (key, value) onto the stack and I expect a structure like so...

Code:

(table before sq_rawget)
| (+index) | (-index) | value        |
| 2        | -1       | table        |
| 1        | -2       | root         |

(table after sq_rawget)
| (+index) | (-index) | value        |
| 4        | -1       | "string"     |
| 3        | -2       | "test_one"   |
| 2        | -3       | table        |
| 1        | -4       | root         |


So my question is how do I properly extract (key, values) from a table?
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Clean Slate theme by Jaben Cargman (Tiny Gecko)
Powered by YAF 1.9.4 | YAF © 2003-2010, Yet Another Forum.NET
This page was generated in 0.057 seconds.