$OpenBSD: patch-luaa_c,v 1.1 2013/06/10 12:28:43 dcoppa Exp $

commit 0c62831eea5e651577928ef8b09c947565eaed7d
Author: Uli Schlachter <psychon@znc.in>
Date:   Sat Jun 8 13:21:14 2013 +0200

lua: Print traceback on startup errors

We do some special magic so that we can have tracebacks on errors
messages. However, the code for parsing the rc.lua called it without
this magic and thus errors didn't have tracebacks.

This is bad, because if something goes wrong in e.g. wibox.widget.textbox,
you don't really have any clue where this error is coming from.

Fix this by adding our "print traceback on error"-magic here, too.

Signed-off-by: Uli Schlachter <psychon@znc.in>

--- luaa.c.orig	Mon Apr  1 13:44:46 2013
+++ luaa.c	Mon Jun 10 14:18:32 2013
@@ -666,7 +666,10 @@ luaA_loadrc(const char *confpath, bool run)
             /* Set the conffile right now so it can be used inside the
              * configuration file. */
             conffile = a_strdup(confpath);
-            if(lua_pcall(globalconf.L, 0, LUA_MULTRET, 0))
+            /* Move error handling function before function */
+            lua_pushcfunction(globalconf.L, luaA_dofunction_on_error);
+            lua_insert(globalconf.L, -2);
+            if(lua_pcall(globalconf.L, 0, LUA_MULTRET, -2))
             {
                 const char *err = lua_tostring(globalconf.L, -1);
                 luaA_startup_error(err);
