ID:1875712
 
Applies to:DM Language
Status: Open

Issue hasn't been assigned a status value.
Would it be feasible at all for numbers to be passed to and from dlls, using a function call such as:

// in SomeDLL.h
float declspec(dllexport) extern "C" SomeFunction(int argc,const float* argv);

// in SomeDLL.cpp
float SomeFunction(int argc,const float* argv){
float retVal = 0;
for(int i = 0;i<argc;++i){
retVal += argv[i];
}
return retVal;
}

// In SomeProc.dm
mob/verb/testNumber()
src << call("SomeDLL","SomeFunction",callType=NUMBER)(1,2,3) // Outputs "6"


I can see this being a really useful feature for many (including myself) that use DLLs, although I'm not sure how it would work for call()() at the moment (hence the callType argument)

How feasable would a feature like this be, and could this possibly be seen soon?
It'd be nice to be able to pass some kind of a pointer to the DLL so we could pull multiple return values out of a single call, but I really don't see that being a thing.
Even just having more than a single type to work with would be nice.
can I get a bumpity bump? Pretty pls?
What you might be able to do as a workaround is something like the following:

/proc/ext_call(dll, func) // (dll, func, call_args...)
var/call_args = args.Copy() // make a copy of args to modify
call_args.Cut(1, 3) // remove the dll and func name from args

return json_decode(call(dll, func)(json_encode(call_args)))


It's not perfect, and it'd be slower than if this behavior was native, but it would give you arbitrary-type arguments to functions, including mixed-type; find a fast C JSON library (or enforce specific formats for each function), and decode the args/encode the result in C; to make your example SomeDLL SomeFunction(1, 2, 3) call you'd do:

mob/verb/testNumber()
src << ext_call("SomeDLL","SomeFunction",1,2,3) // Outputs "6"

with the C side looking something like the following, with types and functions beginning with json_ coming from a hypothetical C JSON library:
char* SomeFunction(int argc,const char** argv){
// todo: check argc>0
json_object* obj = json_decode(argv[0]);
// todo: check it's really a list
float retVal = 0;
for(int i = 0; i < json_list_length(obj); ++i){
retVal += json_list_get_float(obj, i);
}
return json_encode_float(retVal);
}
bump for 513?
You can directly pass floats to a call()() iirc, just set your C function as a float