5 ms·
Wow, that's an impressive PR with very well written and succinct code. Macro-fusion too! B-extension support!? I see some RORIWs in there. Alright, time to run
by fwsgonzo 2y ago
Wow, that's an impressive PR with very well written and succinct code. Macro-fusion too! B-extension support!? I see some RORIWs in there.
Alright, time to run some LuaJIT in my RISC-V emulator.
- fwsgonzo 2y agofunction fib(n, acc, prev) if (n < 1) then return acc else return fib(n - 1, prev + acc, acc) end end print(fib(50, 0, 1)) $ ./rvlinux -P ~/github/LuaRiscvJIT/src/luajit -- test.lua 12586269025 >>> Program exited, exit code = 0 (0x0) Runtime: 0.281ms (Use --accurate for instruction counting) Pages in use: 429 (1716 kB virtual memory, total 2674 kB) It's definitely working!
- xeonmc 2y agoCan this be embedded into a game engine to enable performant Lua scripting?
- extrememacaroni 2y agoThat's literally one of the main uses of luajit.
- _cogg 2y agoYou used to have to be extremely careful to keep the JIT happy, but I think this has been partially solved in LuaJIT 2.1. Calling C functions using the old stack API would cause the JIT to abort. In Garrysmod's case, that includes such simple operations as constructing and performing arithmetic on vectors. So when I was building a high-performance voxel library for Garrysmod, I ended up splitting my hot code into chunks that the JIT compiler would usually be happy with. One fast loop to generate a mesh, then a slow loop to convert that into a mesh structure the engine wants. Very carefully designed methods for bit-packing trees of 12-bit integer voxel data into flat tables of floats.
- mardifoufs 2y agoIt it still true that generating bindings for luajit is easier than with plain Lua? When I used it for a toy project that was the main reason I chose luajit, especially since the project was written in c++.
- _cogg 2y agoWriting bindings isn't something I have a lot of experience with. The main difference I'm aware of is the FFI system, which creates bindings from C headers, and will result in faster calls with good JIT support. I assume it introduces some extra security challenges if you care about that. You'll still probably need to write some wrappers, either C-side or Lua-side if you want a nice API. I know there are other tools for creating bindings, but again, not my area of expertise.
- krapp 2y agoIn my experience it very much is. Most of the LuaJIT code I write is just metatable classes around C libraries like SDL. Just being able to write C structs and lua functions is a dream. Having to manually deal with the stack from C-side is a PITA.
- no_time 2y agoAny video/blogpost of your voxel library in action? Sounds interesting.
- vvanders 2y agoCan? It always has been :). We ran Lua for the entire core of a game in a 400kb preallocated on the PSP about 20 years ago. I know of many places that used it long before us.