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

Metadata for each argument #21

Closed
computerquip-streamlabs opened this issue Aug 1, 2018 · 2 comments
Closed

Metadata for each argument #21

computerquip-streamlabs opened this issue Aug 1, 2018 · 2 comments

Comments

@computerquip-streamlabs
Copy link

Might be useful told hold an enum value in arg_hdr to have the ability to cast back from void*.

@computerquip-streamlabs
Copy link
Author

computerquip-streamlabs commented Aug 1, 2018

I implemented this in my code. It's kinda gross but looks like this essentially:

enum arg_type {
    ARG_LITERAL,
    ARG_STRING,
    ARG_INTEGER,
    ARG_END
};

...

    void *arg_table[] = {
        help,
        dump_args,
        base_url,
        app_dir,
        temp_dir,
        pids,
        end
    };

    /* We need type information to dump parameters generically */
    enum arg_type arg_table_types[] = {
        ARG_LITERAL,
        ARG_LITERAL,
        ARG_STRING,
        ARG_STRING,
        ARG_STRING,
        ARG_INTEGER,
        ARG_END
    };

    if (dump_args->count > 0) {
        for (int i = 0; i < arg_table_sz; ++i) {
            const arg_type type = arg_table_types[i];

            switch (type) {
            case ARG_LITERAL:
                print_literal_arg((struct arg_lit*)arg_table[i]);
                break;
            case ARG_STRING:
                print_string_arg((struct arg_str*)arg_table[i]);
                break;
            case ARG_INTEGER:
                print_integer_arg((struct arg_int*)arg_table[i]);
                break;
            case ARG_END:
                print_end_arg((struct arg_end*)arg_table[i]);
                break;
            }
        }
    }

this let's me generically print each argument and their values.

@tomghuang
Copy link
Contributor

You can try the information in const char* arg_hdr::datatype.

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