DBG: userdata in _plugin_registerexprfunction
This commit is contained in:
parent
4657786726
commit
f768f5cbf3
|
@ -101,9 +101,9 @@ PLUG_IMPEXP bool _plugin_waituntilpaused()
|
|||
return DbgIsDebugging();
|
||||
}
|
||||
|
||||
bool _plugin_registerexprfunction(int pluginHandle, const char* name, int argc, CBPLUGINEXPRFUNCTION cbFunction)
|
||||
bool _plugin_registerexprfunction(int pluginHandle, const char* name, int argc, CBPLUGINEXPRFUNCTION cbFunction, void* userdata)
|
||||
{
|
||||
return pluginexprfuncregister(pluginHandle, name, argc, cbFunction);
|
||||
return pluginexprfuncregister(pluginHandle, name, argc, cbFunction, userdata);
|
||||
}
|
||||
|
||||
bool _plugin_unregisterexprfunction(int pluginHandle, const char* name)
|
||||
|
|
|
@ -208,7 +208,7 @@ typedef enum
|
|||
typedef void (*CBPLUGIN)(CBTYPE cbType, void* callbackInfo);
|
||||
typedef bool (*CBPLUGINCOMMAND)(int argc, char** argv);
|
||||
typedef void (*CBPLUGINSCRIPT)();
|
||||
typedef duint(*CBPLUGINEXPRFUNCTION)(int argc, const duint* argv);
|
||||
typedef duint(*CBPLUGINEXPRFUNCTION)(int argc, const duint* argv, void* userdata);
|
||||
|
||||
//exports
|
||||
#ifdef __cplusplus
|
||||
|
@ -232,7 +232,7 @@ PLUG_IMPEXP void _plugin_menuseticon(int hMenu, const ICONDATA* icon);
|
|||
PLUG_IMPEXP void _plugin_menuentryseticon(int pluginHandle, int hEntry, const ICONDATA* icon);
|
||||
PLUG_IMPEXP void _plugin_startscript(CBPLUGINSCRIPT cbScript);
|
||||
PLUG_IMPEXP bool _plugin_waituntilpaused();
|
||||
PLUG_IMPEXP bool _plugin_registerexprfunction(int pluginHandle, const char* name, int argc, CBPLUGINEXPRFUNCTION cbFunction);
|
||||
PLUG_IMPEXP bool _plugin_registerexprfunction(int pluginHandle, const char* name, int argc, CBPLUGINEXPRFUNCTION cbFunction, void* userdata);
|
||||
PLUG_IMPEXP bool _plugin_unregisterexprfunction(int pluginHandle, const char* name);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -27,7 +27,7 @@ static T callFunc(const T* argv, T(*cbFunction)(Ts...), seq<S...>)
|
|||
template<typename... Ts>
|
||||
static bool RegisterEasy(const String & name, duint(*cbFunction)(Ts...))
|
||||
{
|
||||
return ExpressionFunctions::Register(name, sizeof...(Ts), [cbFunction](int argc, const duint * argv)
|
||||
return ExpressionFunctions::Register(name, sizeof...(Ts), [cbFunction](int argc, duint * argv, void* userdata)
|
||||
{
|
||||
return callFunc(argv, cbFunction, typename gens<sizeof...(Ts)>::type());
|
||||
});
|
||||
|
@ -49,7 +49,7 @@ void ExpressionFunctions::Init()
|
|||
RegisterEasy("mod.entry", ModEntryFromAddr);
|
||||
}
|
||||
|
||||
bool ExpressionFunctions::Register(const String & name, int argc, CBEXPRESSIONFUNCTION cbFunction)
|
||||
bool ExpressionFunctions::Register(const String & name, int argc, CBEXPRESSIONFUNCTION cbFunction, void* userdata)
|
||||
{
|
||||
if(!isValidName(name))
|
||||
return false;
|
||||
|
@ -60,6 +60,7 @@ bool ExpressionFunctions::Register(const String & name, int argc, CBEXPRESSIONFU
|
|||
f.name = name;
|
||||
f.argc = argc;
|
||||
f.cbFunction = cbFunction;
|
||||
f.userdata = userdata;
|
||||
mFunctions[name] = f;
|
||||
return true;
|
||||
}
|
||||
|
@ -74,7 +75,7 @@ bool ExpressionFunctions::Unregister(const String & name)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool ExpressionFunctions::Call(const String & name, const std::vector<duint> & argv, duint & result)
|
||||
bool ExpressionFunctions::Call(const String & name, std::vector<duint> & argv, duint & result)
|
||||
{
|
||||
SHARED_ACQUIRE(LockExpressionFunctions);
|
||||
auto found = mFunctions.find(name);
|
||||
|
@ -83,7 +84,7 @@ bool ExpressionFunctions::Call(const String & name, const std::vector<duint> & a
|
|||
const auto & f = found->second;
|
||||
if(f.argc != int(argv.size()))
|
||||
return false;
|
||||
result = f.cbFunction(f.argc, argv.data());
|
||||
result = f.cbFunction(f.argc, argv.data(), f.userdata);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -5,12 +5,12 @@
|
|||
class ExpressionFunctions
|
||||
{
|
||||
public:
|
||||
using CBEXPRESSIONFUNCTION = std::function<duint(int argc, const duint* argv)>;
|
||||
using CBEXPRESSIONFUNCTION = std::function<duint(int argc, duint* argv, void* userdata)>;
|
||||
|
||||
static void Init();
|
||||
static bool Register(const String & name, int argc, CBEXPRESSIONFUNCTION cbFunction);
|
||||
static bool Register(const String & name, int argc, CBEXPRESSIONFUNCTION cbFunction, void* userdata = nullptr);
|
||||
static bool Unregister(const String & name);
|
||||
static bool Call(const String & name, const std::vector<duint> & argv, duint & result);
|
||||
static bool Call(const String & name, std::vector<duint> & argv, duint & result);
|
||||
static bool GetArgc(const String & name, int & argc);
|
||||
|
||||
private:
|
||||
|
@ -19,6 +19,7 @@ private:
|
|||
String name;
|
||||
int argc;
|
||||
CBEXPRESSIONFUNCTION cbFunction;
|
||||
void* userdata;
|
||||
};
|
||||
|
||||
static bool isValidName(const String & name);
|
||||
|
|
|
@ -693,12 +693,12 @@ void pluginmenuentryseticon(int pluginHandle, int hEntry, const ICONDATA* icon)
|
|||
}
|
||||
}
|
||||
|
||||
bool pluginexprfuncregister(int pluginHandle, const char* name, int argc, CBPLUGINEXPRFUNCTION cbFunction)
|
||||
bool pluginexprfuncregister(int pluginHandle, const char* name, int argc, CBPLUGINEXPRFUNCTION cbFunction, void* userdata)
|
||||
{
|
||||
PLUG_EXPRFUNCTION plugExprfunction;
|
||||
plugExprfunction.pluginHandle = pluginHandle;
|
||||
strcpy_s(plugExprfunction.name, name);
|
||||
if(!ExpressionFunctions::Register(name, argc, cbFunction))
|
||||
if(!ExpressionFunctions::Register(name, argc, cbFunction, userdata))
|
||||
return false;
|
||||
EXCLUSIVE_ACQUIRE(LockPluginExprfunctionList);
|
||||
pluginExprfunctionList.push_back(plugExprfunction);
|
||||
|
|
|
@ -66,7 +66,7 @@ bool pluginwinevent(MSG* message, long* result);
|
|||
bool pluginwineventglobal(MSG* message);
|
||||
void pluginmenuseticon(int hMenu, const ICONDATA* icon);
|
||||
void pluginmenuentryseticon(int pluginHandle, int hEntry, const ICONDATA* icon);
|
||||
bool pluginexprfuncregister(int pluginHandle, const char* name, int argc, CBPLUGINEXPRFUNCTION cbFunction);
|
||||
bool pluginexprfuncregister(int pluginHandle, const char* name, int argc, CBPLUGINEXPRFUNCTION cbFunction, void* userdata);
|
||||
bool pluginexprfuncunregister(int pluginHandle, const char* name);
|
||||
|
||||
#endif // _PLUGIN_LOADER_H
|
||||
|
|
Loading…
Reference in New Issue