The below example was made for the Pawn scripting language. It has extremely similar syntax as C, and AFAIK the pre-processor behavior is the same. The language does not support overloaded functions, so this was a simple work-around using macros.
Code: Select all
#define OF::%0(%1) static stock __%0__(){return _:SPF0:SPF1:0;}of_%0_(%1,)
// Check for parameters - if none, return immediately; otherwise, split for further parsing
#define SPF0:SPF1:0;}%0(,) 0;}%0()
#define SPF1:0;}%0(%1,%2) SPF2:SPF3:SPF4:SPF5:0;}%0(|||%1|||%2)
// Add checking for strings and ints - this assumes there are two+ parameters left
#define SPF2:SPF3:SPF4:SPF5:0;}%0(%9|||%1[]|||%2,%3) SPF2:SPF3:SPF4:SPF5:0;}%0s(%9%1[],|||%2|||%3)
#define SPF3:SPF4:SPF5:0;}%0(%9|||%1|||%2,%3) SPF2:SPF3:SPF4:SPF5:0;}%0i(%9%1,|||%2|||%3)
// Add checking for strings and ints - this assumes only one parameter is left
#define SPF4:SPF5:0;}%0(%9|||%1[]|||) 0;}%0s(%9%1[])
#define SPF5:0;}%0(%9|||%1|||) 0;}%0i(%9%1)
The intended result of this was to have syntax like such
Code: Select all
// remember there are no "data types", everything is a "cell"
OF::Function(int_value){ /* ... */ }
OF::Function(string[]){ /* ... */ }
OF::Function(int_value,string[]){ /* ... */ }
Code: Select all
of_Function_i(int_value){}
of_Function_s(string[]){}
of_Function_is(int_value,string[]){}
Anyone else have some crazy macros to share?