Well, I have an abstract virtual machine (“PAWN“) which is running from my code and the scripts can execute functions, those functions are registered to the script from the C code which gets executed by my C++ code.
The c++ code has to supply an array in the form of
{ "name_i_want_the_function_to_have_in_the_script" , function_in_my_cpp_code }
if the function is not in the array, it cannot be executed. (because it doesn”t “exist”)
So this brings us to this:
My functions look like this:
//Pawn Functions
#define PWNFUNC(a) static cell AMX_NATIVE_CALL a(AMX *amx, cell *params)
namespace PawnFunc
{
PWNFUNC(GGV)
{
return pGameInterface->FindGameVersion();
}
};//namespace PawnFunc
and the array with the scripting functions information is in another file, like this:
AMX_NATIVE_INFO custom_Natives[] =
{
{ "GetGameVersion", PawnFunc::GGV },
{ 0,0 }
};
and the question is now:
is it possible to make that array auto updated? (before/at compile time or code initialization time)
as for now I have to add each function manually. Which is sometimes annoying and more prone for errors.
I would like to change it so I could do:
//Pawn Functions
#define PWNFUNC(a,b) ...?...
namespace PawnFunc
{
PWNFUNC(GGV,GetGameVersion)//{ "GetGameVersion", PawnFunc::GGV }, is now added to "custom_Natives" array
{
return pGameInterface->FindGameVersion();
}
};//namespace PawnFunc
Is this possible at all? If yes, how could I achieve this?
maybe it is possible to loop the namespace?
Edit: here is some pseudo code: http://ideone.com/btG2lx
And also a note: I can do it at runtime, but then it has to be done at DLLMain (my program is a DLL).
This
#definewill do the job, if you use astd::vectoras the storage for your script info.(Note that the standard guarantees that you’ll still get a C-style array from
&custom_Natives[0])Now code like this will both define the function and add the script entry to
custom_Natives.