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

Update parser #2375

Merged
merged 2 commits into from
Mar 8, 2022
Merged

Update parser #2375

merged 2 commits into from
Mar 8, 2022

Conversation

IrishBruse
Copy link
Contributor

So I was parsing the raylib_api.json file and I found that var args are not parsed correctly

RLAPI void TraceLog(int logLevel, const char *text, ...);         // Show trace log messages (LOG_DEBUG, LOG_INFO, LOG_WARNING, LOG_ERROR...)
    {
      "name": "TraceLog",
      "description": "Show trace log messages (LOG_DEBUG, LOG_INFO, LOG_WARNING, LOG_ERROR...)",
      "returnType": "void",
      "params": {
        "logLevel": "int",
        "text": "const char *",
        "": "" <- ... here was really confusing to figure out what this was
      }
    },

The fix ive added will give a type and name to variable len args

    {
      "name": "TraceLog",
      "description": "Show trace log messages (LOG_DEBUG, LOG_INFO, LOG_WARNING, LOG_ERROR...)",
      "returnType": "void",
      "params": [
        {
          "type": "int",
          "name": "logLevel"
        },
        {
          "type": "const char *",
          "name": "text"
        },
        {
          "type": "...",
          "name": "args"
        }
      ]
    },

I also added a format type of ALL so that its easier to refresh the bindings with each new release :)
parser.exe -f ALL

Output file:      raylib_api.txt
Output file:      raylib_api.lua
Output file:      raylib_api.json
Output file:      raylib_api.xml

is printed when running the command now

@Peter0x44
Copy link
Contributor

Peter0x44 commented Mar 8, 2022

quite pedantic, but if a function like the following:

struct a {};
void something(a b);

were ever to be added to the raylib API, then the parser would think that is a varargs
I think it would be better to check if it contains a ., because that cannot be a valid C identifier
Also, wouldn't it make more sense to keep the logic contained in the GetTypeDataAndName function? I don't why the check for the length being 3 needs to be outside of it

If you're going to add an option to generate everything, then you should probably also modify the Makefile to use it.

@IrishBruse
Copy link
Contributor Author

I think that should fix all the feedback you gave me in the discord thanks for it im not very experienced writing C code I mostly know c#. I have been writting a code generator here https://github.com/IrishBruse/Raylib-CsLo/tree/safe-codegen
and ran into an issue with the json file said above also having all the files in the git is handy as we submodule this repo and use the json to generate our bindings.

parser/raylib_parser.c Outdated Show resolved Hide resolved
@raysan5
Copy link
Owner

raysan5 commented Mar 8, 2022

@IrishBruse I prefer to avoid adding all the generated files, just let the users generate the ones they desire.

parser/raylib_parser.c Outdated Show resolved Hide resolved
parser/raylib_parser.c Outdated Show resolved Hide resolved
@IrishBruse
Copy link
Contributor Author

Ok removed the all flag and cleaned up the commits

@raysan5 raysan5 merged commit 43dbe67 into raysan5:master Mar 8, 2022
@raysan5
Copy link
Owner

raysan5 commented Mar 8, 2022

@IrishBruse Thanks for the review, merging!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants