allegory-software / allegory-sdk

:candy: Self-contained cross-platform programming environment for developing web-based database-driven business apps in LuaJIT and JavaScript
MIT License
79 stars 6 forks source link

Issue with vmdef.lua #5

Closed gvanem closed 1 year ago

gvanem commented 1 year ago

I'm struggling with a simple luajit.exe md5_test.lua command. Error is:

luajit.exe: F:\MinGW32\src\LUA\Allegory-Software\\lua\glue.lua:289: module 'table.isarray' not found:
        no field package.preload['table.isarray']
        ...

It seems the special <root>/lua/jit/vmdef_windows.lua must be used to build lua*.dll. Correct? But how and where should be placed? The build file is rather unclear.

And yes, I have patched the LuaJit sources from the *.patch files.

capr commented 1 year ago

Hi, that's my fault for updating the binaries on the master branch instead of the dev branch. Fixed.

You might want to check out the dev branch though. A new release will also come shortly (in a few weeks I hope).

gvanem commented 1 year ago

I think you misunderstood. I'm not using any pre-built stuff. But I've rather built everything myself using MSVC and clang-cl. And since I have problems cloning the dev blanch, I'm sticking to master at the moment. But would it be git clone <url> --branch dev <dir>?

capr commented 1 year ago

Well the master branch depends on luajit binary being OpenResty. That's why you get the error in glue.lua. Just implement table.isarray in Lua then if you're using stock LuaJIT (though honestly I don't even think it's used anywhere, maybe just remove it?).

To switch to dev just do git checkout dev on your already cloned repos (don't forget to switch branch on bin/windows too).

gvanem commented 1 year ago

Just implement table.isarray in Lua then if you're using stock LuaJIT

After briefly looking at the master / dev diffs, I did this patch:

--- a/lua/glue.lua 2022-11-24 13:27:03
+++ b/lua/glue.lua 2022-11-25 19:51:55
@@ -286,8 +286,20 @@
 isint    = function(v) return type(v) == 'number' and floor(v) == v end
 istab    = function(v) return type(v) == 'table'  end
 isbool   = function(v) return v == true or v == false end
-isarray  = require'table.isarray'
-isempty  = require'table.isempty'
+isempty  = function(v) return next(v) == nil end
 isfunc   = function(v) return type(v) == 'function' end
 iscdata  = function(v) return type(v) == 'cdata'  end

And now md5_test.lua works fine!

stock LuaJIT

You mean the official LuaJIT? Doesn't we need to apply the patches? Hence it's no longer a stock LuaJIT IMHO:

capr commented 1 year ago

Yea, those where built-ins in OpenResty but when I switched to official LuaJIT I had to change them. isarray I never used so I removed it, and isempty() implemented in terms of next() is ok because next() is no longer NYI AFAIK (not that I care, I don't rely on the JIT).

Those LuaJIT patches are optional, you can use stock LuaJIT if you want, the SDK won't care.

gvanem commented 1 year ago

Those LuaJIT patches are optional.

Ok, but this whole SDK and LuaJIT is strange. Even sock_test.lua fails on WSAGetLastError = C.WSAGetLastError:

luajit.exe: sock.lua:925: cannot resolve symbol 'WSAGetLastError': Function not found.

Adding some trace to lj_clib.c, I found LuaJIT tried to load this function from gdi32.dll and fails.

But even after fixing this, I see this pesky libwinpthread-1.dll gets loaded into the process. I note it uses CreateThread(), but only for profiling. Why not for the rest too?

capr commented 1 year ago

That is strange. I dunno what to tell you. I ran sock_test.lua on both master and dev and it loads fine (there are some errors but unrelated to library loading -- I'll fix those before next release).

I also checked if any libs (including luajit) depend on libwinpthread-1.dll and none do. That lib is only loaded if you sue pthread.lua or os_thread.lua.