Advertisement

Registering #define values with engine

Started by February 14, 2020 11:13 PM
2 comments, last by vballDrummer 4 years, 9 months ago

I'm registering methods that use #defines for default parameter values , ex:

#define IO_HIGH 1
#define IO_LOW 0

Registration is successful, but the values are undefined when the script is compiled. I'm guessing b/c #defines are just macro substitutions by the preprocessor. I can use the #define value directly in the Registration call. That works fine, but of course is a bit error prone for the future. The only other thing I can think of is to create an enum of #defines that are parameter defaults and register those. Is there a more maintainable solution?

In C++ I personally prefer using constants or enums over pre-processor defines when all it should do is represent a constant value. The end result is the same, but usually the compiler and debugger handles enums and constants better than pre-processor defines.

Regardless of my preferences, while you can use a pre-processor for angelscript too, it will not work for the registered function signatures (unless you modify the library to invoke the pre-processor when the default argument expression should be compiled). So, when registering a method/function with AngelScript that uses C++ pre-processor defines in the default arguments you need to translate these to something that AngelScript understand when informing the function signature. That can be either including the literal value, or it could be to register an enum first which can then be used in the default arg.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Advertisement

Totally agree, my preference too, but I'm required to use a 3rd party header/library. I'll be using a registered enum to map the macros to angelscript known type(s)

This topic is closed to new replies.

Advertisement