Old 08-13-2019, 02:20 PM   #1
mespotine
Human being with feelings
 
mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig, Germany
Posts: 1,396
Default Does this load external dlls in Lua in Reaper?

While looking for something completely different, I stumbled upon this function:

package.loadlib

from the reference-manual:

Quote:
package.loadlib (libname, funcname)
Dynamically links the host program with the C library libname. Inside this library, looks for a function funcname and returns this function as a C function. (So, funcname must follow the protocol (see lua_CFunction)).

This is a low-level function. It completely bypasses the package and module system. Unlike require, it does not perform any path searching and does not automatically adds extensions. libname must be the complete file name of the C library, including if necessary a path and extension. funcname must be the exact name exported by the C library (which may depend on the C compiler and linker used).

This function is not supported by ANSI C. As such, it is only available on some platforms (Windows, Linux, Mac OS X, Solaris, BSD, plus other Unix systems that support the dlfcn standard).
This function is accepted by Lua in Reaper and now I wonder: Can we use this, to load dlls/dylibs/so-files in Reaper?

Has someone of you tried to use this already?
__________________
Ultraschall-API - a Lua-functions-library4Reaper: https://forum.cockos.com/showthread....98#post2067798
Reaper Internals - Developerdocs4Reaper: https://forum.cockos.com/showthread.php?t=207635
mespotine is offline   Reply With Quote
Old 08-13-2019, 03:40 PM   #2
Xenakios
Human being with feelings
 
Xenakios's Avatar
 
Join Date: Feb 2007
Location: Oulu, Finland
Posts: 7,784
Default

I didn't yet try it but I think this isn't very promising :

Code:
funcname must follow the protocol (see lua_CFunction)
Obviously, generic C libraries are not going to use the Lua call protocol except by chance.

Even if some really basic stuff would work, there probably isn't any way to write and read into/from C structs, which would be a pretty crucial thing to do with most libraries.

Binary Lua modules would still be hopeless to use. They only export a single function, that requires the lua_State* to be given as a parameter, which Reaper doesn't give access to.

edit : Doesn't look good. This just crashed Reaper with an access violation.

Code:
path = "C:\\Program Files\\Mega-Nerd\\libsndfile\\bin\\libsndfile-1.dll"
local f = assert(package.loadlib(path, "sf_version_string"))
str = f()
That was just trying to call a simple C function with the following signature :

Code:
const char * sf_version_string (void) ;
__________________
For info on SWS Reaper extension plugin (including Xenakios' previous extension/actions) :
http://www.sws-extension.org/
https://github.com/Jeff0S/sws
--
Xenakios blog (about HourGlass, Paul(X)Stretch and λ) :
http://xenakios.wordpress.com/

Last edited by Xenakios; 08-13-2019 at 04:47 PM.
Xenakios is online now   Reply With Quote
Old 08-15-2019, 01:32 PM   #3
mespotine
Human being with feelings
 
mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig, Germany
Posts: 1,396
Default

Ahhh...whatapity... :/

Thanks for trying it
__________________
Ultraschall-API - a Lua-functions-library4Reaper: https://forum.cockos.com/showthread....98#post2067798
Reaper Internals - Developerdocs4Reaper: https://forum.cockos.com/showthread.php?t=207635
mespotine is offline   Reply With Quote
Old 08-16-2019, 03:33 PM   #4
snooks
Human being with feelings
 
Join Date: Sep 2015
Posts: 1,584
Default

Interesting, this does allow us to call C! But not any C, as mentioned in the docs this only works with lua C functions, eg...

Code:
// for Windows dlls
#define API_FUNC extern "C" __declspec( dllexport )

API_FUNC int test(lua_State* L)
{
    lua_pushstring(L, "Hello, C world");
    return 1;
}
You need to statically link Lua when compiling your C code - full Windows static .libs (and include files) are here...

https://sourceforge.net/projects/lua...raries/Static/

(It would be nice if the devs could build REAPER with a Lua as a separate shared lib to enable using ordinary Lua C libs)
snooks is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 03:34 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2019, vBulletin Solutions Inc.