Use string and integer on the moon

1

Well I have a table as follows:

{
        Number: 15007       Name: "Variance"        Value:  35

}

Before I used a txt format that was like this:

15007,Variance,35

The code in C was something like this:

void read_names(void) {
    struct st *table;
    int var = 0;
    const char *str = NULL;

    table->number = var;
    table->name = str;
    table->value = var;

    return;
}

I want to change to the moon now, I could use libconfig, but I've used it once and it's very limited, an example in lib if I were to do the above table:

void read_names(void) {
        struct st *table;
        int var = 0;
        const char *str = NULL;
        config_setting_t *names = .........

        table->number = config_setting_lookup_int(names, "Number", &var);
        table->name = config_setting_lookup_string(names, "Name", &str);
        table->value = config_setting_lookup_int(names, "Value", &var);

        return;
}

In this way I would be able to read the table that I posted at the beginning of the topic.

But I want to use the moon, which I want to know how I use the same form of the lib and allow me to use integers and string in the names Number, Name and Value, for example:

table->number = função_lua(L, "Number", &var);

If writing can not be that way, you should note that it was just an example.

    
asked by anonymous 29.03.2015 / 20:30

1 answer

1

I understand that you want the indexes of the table to be of type number and string "string":

You can manipulate indexes of the table normally only use the ,

Test the code below on the network: link

tab = { 'indice1', cad = 'cadeia', 'indice2'}
print(tab[1],tab.cad,tab[2])
-- indice1  cadeia  indice2
    
18.07.2017 / 01:13