arturocepeda / Cflat

Embeddable lightweight scripting language with C++ syntax
49 stars 8 forks source link

Pre Process Macros & Functions Name Issue #6

Closed CycloneRing closed 2 years ago

CycloneRing commented 2 years ago

Hi, Just found your amazing repo thanks for this, Code looks very clean, I want to give it a try for my game engine scripting! However I faced a bug and one question.

Question : Is pre-processing macros supported? I did some tests and it didn't work but I saw in your code you implemented it? for example

#define my_function __registred_func_1

Bug : When i use tab space " " before my function, compiler count the tab space as the name of function...

This works :

void print(const char* str)
{
RegistredPrint(str);
}

But this throws error :

void print(const char* str)
{
    RegistredPrint(str); // ERROR :  undefined function ('   RegistredPrint') or invalid arguments in call
}

I know it can be fixed by replacing all tab spaces with null before compiling but if it be fixed in the repo it would be great.

Thanks

arturocepeda commented 2 years ago

Hi Cyclone!

Wow, good catch, thank you for the bug report! I have just committed a fix, the tokenizer should now skip the tabs.

Regarding the macro support: at the moment you can define macros, but only on the C++ side, by using the defineMacro method from the environment. Then you can use the macro in your script code. Adding support for the #define directive in scripts is on my TODO list, though. I'll see if I can add it during the weekend, shouldn't take long.

CycloneRing commented 2 years ago

Awesome! Keep it up mate 🥇

arturocepeda commented 2 years ago

@CycloneRing: #define directives in script code are now supported!