fungos / cr

cr.h: A Simple C Hot Reload Header-only Library
https://fungos.github.io/cr-simple-c-hot-reload/
MIT License
1.54k stars 101 forks source link

[Feature] Call any Function #45

Open xunilrj opened 4 years ago

xunilrj commented 4 years ago

I don't know if this is goes against the philosophy of the library or not, but I created a fork where you can call any function. With an extra syntax for C++.

My first try is here: https://github.com/xunilrj/cr/commit/c1638e89c1550350575e3daae35400242247e240

I created some flags that makes this feature totally opt-in.

#define CR_HOST
#define CR_ANYFUNCTION
#define CR_CPP
#include "cr.h"
...
cr_plugin_load(plugin, "c:/game.dll");
cr_plugin_load_functions(plugin, "f1,f2,f3");
...

The C version:

auto f1 = (double(*)(double))cr_plugin_get_function(plugin, 0);
auto r1 = f(1.0f);
auto f2 = (double(*)(double,double))cr_plugin_get_function(plugin, 1);
auto r2 = f(1.0f, 2.0f);

The C++ version:

auto r1 = cr_plugin_call<double>(plugin, 0, 1.0f);
auto r2 = cr_plugin_call<double>(plugin, 1, 1.0f, 2.0f);