loadlib (lua's DLL import function) - crash on function call *SOLVED*
Posted: Mon May 01, 2023 1:41 pm
I know that this is a long shot, but I was wondering if anyone had an idea about a crash I'm seeing when playing with the nutcracker release.
I've been experimenting with lua's (built-in) "loadlib()" function. loadlib() lets you import a DLL file that contains functions written in C with a particular protocol called "lua_CFunction". The C functions, once imported into lua, can be treated like regular lua functions.
Btw, I know that this would break the "Modding and Asset usage terms" if distributed.
So, I've been able to import a DLL and run it's functions from the lua 5.1 console application. And I can import the DLL into Grimlock 2, and also print the imported function's tostring value (or nil, if the import failed). However, when I try to run any of the imported functions, Grimlock 2 crashes. No error message, just the crash.
I just wonder if there's a known explanation or, better yet, a solution for this crash. I think I've read that Grimrock's lua engine isn't vanilla, which would certainly explain it.
EDIT: I just successfully called an "idle" function, which takes no parameters and returns nothing. The crashing is definitely dependent on taking and/or returning a value. Most likely the "lua_to..." and "lua_push..." function families. FYI, I made sure that the dll is 32 bit, strings are multibyte (not unicode) and lua 5.1 is used.
Also, handling numbers crashes Grimrock 2, but handling strings freezes Grimrock 2 instead (with the music still playing).
I've been experimenting with lua's (built-in) "loadlib()" function. loadlib() lets you import a DLL file that contains functions written in C with a particular protocol called "lua_CFunction". The C functions, once imported into lua, can be treated like regular lua functions.
Btw, I know that this would break the "Modding and Asset usage terms" if distributed.
So, I've been able to import a DLL and run it's functions from the lua 5.1 console application. And I can import the DLL into Grimlock 2, and also print the imported function's tostring value (or nil, if the import failed). However, when I try to run any of the imported functions, Grimlock 2 crashes. No error message, just the crash.
I just wonder if there's a known explanation or, better yet, a solution for this crash. I think I've read that Grimrock's lua engine isn't vanilla, which would certainly explain it.
EDIT: I just successfully called an "idle" function, which takes no parameters and returns nothing. The crashing is definitely dependent on taking and/or returning a value. Most likely the "lua_to..." and "lua_push..." function families. FYI, I made sure that the dll is 32 bit, strings are multibyte (not unicode) and lua 5.1 is used.
Also, handling numbers crashes Grimrock 2, but handling strings freezes Grimrock 2 instead (with the music still playing).