Mesen
Mesen copied to clipboard
Lua 3rd party libraries
I tried to use iup binaries with mesen, but can't choose correct version for it. I tried use dlls from together (for windows-64, dlls from msvs-17): https://sourceforge.net/projects/iup/files/3.26/Windows%20Libraries/Dynamic/iup-3.26_Win64_dll15_lib.zip/download https://sourceforge.net/projects/iup/files/3.26/Windows%20Libraries/Dynamic/Lua53/iup-3.26-Lua53_Win64_dll15_lib.zip/download And from (for windows-32, dlls for msvs-17): https://sourceforge.net/projects/iup/files/3.26/Windows%20Libraries/Dynamic/iup-3.26_Win32_dll15_lib.zip/download https://sourceforge.net/projects/iup/files/3.26/Windows%20Libraries/Dynamic/Lua53/iup-3.26-Lua53_Win32_dll15_lib.zip/download But both cases return error:
Loading script...
error loading module 'iuplua53' from file 'D:\ROM\Dendy\mesen\iuplua53.dll':
%1 is not a valid win32 application
Is it possible to use iup binaries with mesen? Also, it will be good to have some hint from Mesen gui (maybe in About window), what version of lua and compilers used while building.
I think, it will be good to have some lua gui library for use it from scripts (maybe included in distribution).
I'm not quite sure what could be causing them to fail to load - I've never heard of "iup" binaries before, though, so I haven't tested this. I haven't done anything with Lua's integration that would disable this, as far as I am aware. The version embedded into Mesen should be 5.3.4, since that was the most recent version available when I added Lua scripting support.
I'll have to take a look, but it might be a while before I can.
I have actually used some external Lua libraries with succes. (penlight, for example, to name a nice one)
Quite a few useful ones (numlua or luafilesystem for example) seem to fail on a dynamic library loading related issue, could possibly be related to OP given that dlls and .so's perform similar functions between Windows and Linux (although the errors mesages seem to indicate different problems, semantically):
-- test.lua
require 'numlua'
matrix.pretty(matrix.mul(matrix.ones(1,10), matrix.zeros(1,10)))
$ mono Mesen.exe test.lua game.nes
# from the Mesen console:
error loading module 'numlua' from file '/usr/local/lib/lua/5.3/numlua.so':
dynamic libraries not enabled; check your Lua installation
Of course, the libraries in question load just fine if I start lua outside of Mesen.
Regardless of whether the error messages are related, it would be really nice to have proper lua 3d party lib support.
I made it work! Not sure if I made any mistakes though, as it was actually pretty easy. As the error of my previous message indicated, dynamic library loading was not properly enabled. Hence, importing lua libraries that relied on .so/.dll files failed.
To properly enable dynamic library loading in the embedded lua on *nix systems, you should pass -ldl -DLUA_USE_DLOPEN during compilation. (see Lua/loadlib.c, line 97; Lua/lauconf.h, line 70). -ldl is needed to interact with the dlopen functionality found on e.g. Linux machines, thereby accomplishing dynamic library loading. Something similar applies to Windows --- LUA_DL_DLL should be set to 'true' (see Lua/loadlib.c, line 143). Additional flags could be needed on Windows machines.
If you want, I can figure out the best place to put these flags in the makefile, test, and make a PR. Downside is that I might not have a Windows machine to test on until saturday, when my roommate comes back.
This flag is enabled for windows by default, so this is not the reason for error for windows version
Interesting, how do you figure? Is it related to line ~53 in luaconf.h:
#if !defined(LUA_USE_C89) && defined(_WIN32) && !defined(_WIN32_WCE)
#define LUA_USE_WINDOWS /* enable goodies for regular Windows */
#endif
I just checked that code inside #ifdef LUA_USE_WINDOWS ... #endif and #ifdef LUA_DL_DLL #endif is reached by compiler. I didn't test that some dlls will loaded by mesen yet.