The attached patch allows support for Lua frameworks such as Orbit,
which return tables instead of functions when loaded.

Applications that return functions still work as before. If an app
returns something other than a table with a function called 'run', or a
function directly, a more detailed error message is given before
failing.


The other problem I reported previously - first page load works, all
others fail - turned out not to be uWSGI's fault. Orbit is returning
values outside Lua's WSAPI spec :)


After diving into the code, I am nothing but impressed with uWSGI. The
engineering is excellent.

-- 
Aaron B. <[email protected]>
--- uwsgi-1.2.5/plugins/lua/lua_plugin.c	2012-08-14 02:17:52.000000000 -0400
+++ uwsgi-1.2.5-patched/plugins/lua/lua_plugin.c	2012-08-29 17:51:03.000000000 -0400
@@ -374,12 +374,26 @@
 				uwsgi_log("unable to load file %s: %s\n", ulua.filename, lua_tostring(ulua.L[i], -1));
 				exit(1);
 			}
+			
 			// use a pcall
 			//lua_call(ulua.L[i], 0, 1);
 			if (lua_pcall(ulua.L[i], 0, 1, 0) != 0) {
 				uwsgi_log("%s\n", lua_tostring(ulua.L[i], -1));
 				exit(1);
 			}
+			
+			// if the loaded lua app returns as a table, fetch the
+			// run function.
+			if (lua_istable(ulua.L[i], 2)) {
+				lua_pushstring(ulua.L[i], "run" );
+				lua_gettable(ulua.L[i], 2);
+				lua_replace(ulua.L[i], 2);
+			}
+					
+			if (! lua_isfunction(ulua.L[i], 2))	{
+				uwsgi_log("Can't find WSAPI entry point (no function, nor a table with function'run').\n");
+				exit(1);
+			}
 		}
 
 	}
_______________________________________________
uWSGI mailing list
[email protected]
http://lists.unbit.it/cgi-bin/mailman/listinfo/uwsgi

Reply via email to