Posted on 2 Comments

Antony’s pre-conf challenge: Lua stored procedures

I set Antony Curtis (former MySQL colleague, and he recently moved to Google) a little challenge before the conf, can he make his external stored procedure framework support Lua? This will hinge on whether Lua is truly thread-safe and does not have evil mutexes hiding in its inner depths.

Antony responded that, if indeed it’s thread-safe, it should only be a matter of hours. That’d be cool…. the standard stored proc language, while standard, is really nothing more than basic with a gross hangover. It’s not pretty or flexible, writing longer procedures is like …. I dunno what would compare, but it’s painful. The problem is just finding something threadsafe and small enough to get embedded, otherwise it requires external infrastructure. Lua would be ideal. We’ll see!

Lua is of course also used in MySQL Proxy, and lots of other projects. It’s *the* embedded scripting language of choice, just like if you need to embed a tiny SQL library, you pick SQLite.

Posted on 2 Comments

2 thoughts on “Antony’s pre-conf challenge: Lua stored procedures

  1. Lua is thread-safe and is free of mutexes by default. You can compile in locking to protect multiple threads accessing the same lua_State at the same time, but for this kind of application there is no need to share the state between several connections.

        lua_State *L = luaL_newstate();
        luaL_openlibs(L);
        luaL_loadstring(L, "return 1");
        lua_pcall(L, 0, 1, 0);
        return lua_tointeger(L, -1);
    

    is all you need for a start.

  2. Sounds pretty perfect – thanks!
    I’ve also passed on your msg to Antony.

Comments are closed.