Dynamic load from another context
Wolftein
agustin.l.alvarez at hotmail.com
Wed Oct 30 19:45:34 PDT 2013
I'm trying to design a plug-in system for my game, and i would
like to share static members from both context (Application,
Shared Library). I found out that i can get the address of a
__gshared at compile time, so my question is, is it possible to
build an associative array at compile-time?
What i'm trying to do is:
/// Template to get the address of a function.
template GetAddress(alias T)
{
enum GetAddress = &T;
}
template DeclareAddress(alias T, string name)
{
enum DeclareAddress = "__gshared " ~ T.stringof ~ " " ~ name;
}
Template RegisterAddress(alias T)
{
addToAssociativeArray!(GetAddress!T);
}
mixin( DeclareAddress!(uint, shared_uint) );
RegisterAddress!(shared_uint);
Then i could register some shared variables like events and when
the plug-in is loaded, iterate over that array and set the
correct values at runtime.
More information about the Digitalmars-d-learn
mailing list