Code Monkey home page Code Monkey logo

Comments (5)

P-p-H-d avatar P-p-H-d commented on May 23, 2024

I get the following warning when I try your code:

error: incompatible type for argument 1 of ‘color_parse_str’
                GET_STR(color_get_str), PARSE_STR(color_parse_str))

Indeed, color_parse_str expects a T* instead of a T:
bool color_parse_str(color_t *ptr, const char str[], const char **endptr) {
So your association between the operator and the method in the oplist shall be defined as:
PARSE_STR(color_parse_str M_IPTR)
(Later you can use also PARSE_STR(API_2(color_parse_str)) but it is still WIP and is not working for tuple)

from mlib.

mario-tux avatar mario-tux commented on May 23, 2024

I think the warning is different because I was using clang.
I'm not sure to understand your explanation. In m-core.h I can see parse_str methods where the first argument is something like type *. Maybe this work if type is a M-LIB container (so an array[1]-type) but I can't imagine how to manage it with a native type.
Can you give some hint how to manage this using the actual API? Thanks

from mlib.

mario-tux avatar mario-tux commented on May 23, 2024

Ok, sorry I spotted only now the note on the usage of the M_IPTR keywork in the OPLIST definition.

I'm wondering what's the aim of the API_2 mechanism.

from mlib.

P-p-H-d avatar P-p-H-d commented on May 23, 2024

The API_* mechanism is a more general mechanism to adapt the call of the operator to the needs of the methods. It defines how to call effectively the method:

void method_by_ref(type out, ...);           // API_0
void method_by_addr(type *out, ...);     // API_2
out = method_by_ret_value(...);            // API_4

API is not the right term for this, but I wasn't able to find the right term. API CALL ?
It is a WIP as it is not supported by all the library yet.

M_IPTR is the current way of doing it. But I wasn't able to generalize the trick used for this to support the method_by_ret_value.

In your example, you just need to write:

#define COLOR_OPLIST                                                           \
    M_OPEXTEND(M_DEFAULT_OPLIST, OUT_STR(color_out_str), IN_STR(color_in_str), \
               GET_STR(color_get_str), PARSE_STR(color_parse_str M_IPTR))

from mlib.

mario-tux avatar mario-tux commented on May 23, 2024

Ok, many thanks.

from mlib.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.