Lua on Compiler Explorer

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Lua on Compiler Explorer

JeanHeyd Meneide
Dear Ya'll,

     Just wanted to chime in with a little fun tidbit!

     Compiler Explorer (the "Godbolt It" website for compiling all
manner of C, C++, and other kinds of programming language code) now
supports linking libraries, and that means you can run Lua 5.3.5 or
Lua 5.4.0 code on it. This includes using the C API to have fun:

     https://godbolt.org/z/nqeYY8

     (It also has sol2, my library, there as well :D !)

     This can make it easier to give examples and tiny snippets of
working Lua C API code to folks!

Best Wishes,
ThePhD
Reply | Threaded
Open this post in threaded view
|

Re: Lua on Compiler Explorer

Joseph C. Sible
On Sat, Jul 18, 2020 at 11:43 AM JeanHeyd Meneide
<[hidden email]> wrote:

>
> Dear Ya'll,
>
>      Just wanted to chime in with a little fun tidbit!
>
>      Compiler Explorer (the "Godbolt It" website for compiling all
> manner of C, C++, and other kinds of programming language code) now
> supports linking libraries, and that means you can run Lua 5.3.5 or
> Lua 5.4.0 code on it. This includes using the C API to have fun:
>
>      https://godbolt.org/z/nqeYY8
>
>      (It also has sol2, my library, there as well :D !)
>
>      This can make it easier to give examples and tiny snippets of
> working Lua C API code to folks!
>
> Best Wishes,
> ThePhD

I stumbled upon a minor missed optimization in luaL_dostring by
playing with that. It's expanded as a macro to "(luaL_loadstring(L, s)
|| lua_pcall(L, 0, LUA_MULTRET, 0))". The missed optimization is that
GCC optimizes for the failure path of luaL_loadstring for some reason,
so the conditional forward branch is taken when it succeeds. It should
instead optimize for the success path, setting up the conditional
forward branch to be taken when it fails instead. (On x86 and x64 at
least, conditional forward branches are more efficient when the
not-taken path is the common one.) If we wanted to, we could give a
hint to GCC with macros like the Linux kernel's "likely" and
"unlikely", so that luaL_dostring would instead expand to
"(__builtin_expect(luaL_loadstring(L, s), 0) || lua_pcall(L, 0,
LUA_MULTRET, 0))".

Joseph C. Sible