Accessing static data of functions
schveiguy at gmail.com
Tue Oct 19 14:19:41 UTC 2021
On 10/14/21 10:21 AM, Ogi wrote:
> Is there any way to get/set static variables defined in functions from
> the outside? Also, is there any way to access the types defined inside
> in function to get/set their static members?
> I’m writing a game engine that should support a dynamic plugin system
> similar to what Manu Evans described in his [Using D Alongside a Game
> Engine](https://youtu.be/FKceA691Wcg) talk. Basically, game objects are
> defined in modules to be compiled as DLLs and loaded dynamically. This
> allows making modifications without even restarting the game. Plugin
> manager detects a modification in a plugin source file, serializes all
> game objects into text, unloads a DLL, recompiles it, loads it again and
> deserialize the game objects back.
> So far so good, I’m now able to serialize/deserialize game objects
> (including private fields), and any global variables defined in a
> plugin, and any static members of the types defined in a plugin. But I
> don’t know what to do with the stuff that could be defined inside of a
> function, I can’t find any trait or a template that could access it.
As long as it has a mangle, you can access it.
Now, how to get at that mangle? I think it's impossible to do
introspectively (or even detect that those things exist). But if you
have control of the code, it's possible.
More information about the Digitalmars-d