OSDN Git Service

Initialise $LUA_PATH to locate mingw-get specific scripts.
authorKeith Marshall <keithmarshall@users.sourceforge.net>
Fri, 6 Apr 2012 10:31:14 +0000 (10:31 +0000)
committerKeith Marshall <keithmarshall@users.sourceforge.net>
Fri, 6 Apr 2012 10:31:14 +0000 (10:31 +0000)
ChangeLog
src/pkgexec.cpp

index 85c21bd..690c081 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2012-04-06  Keith Marshall  <keithmarshall@users.sourceforge.net>
+
+       Initialise $LUA_PATH to locate mingw-get specific scripts.
+
+       * src/pkgexec.cpp (lua_path_init): New static inline function.
+       (pkgXmlNode::DispatchScript): Call it on first time invocation, per...
+       [lua_path_setup == false]: ...this static function local variable.
+
 2012-04-01  Keith Marshall  <keithmarshall@users.sourceforge.net>
 
        Support installation of releases other than latest available.
index b0f5b88..52970c0 100644 (file)
@@ -583,6 +583,16 @@ pkgActionItem::~pkgActionItem()
 static const char *action_key = "action";
 static const char *normal_key = "normal";
 
+static inline __attribute__((__always_inline__)) bool init_lua_path()
+{
+  /* A one time initialisation hook, to ensure that the built-in Lua script
+   * interpreter will load scripts from the libexec directory associated with
+   * the running mingw-get.exe instance.
+   */
+  putenv( "LUA_PATH=!\\libexec\\mingw-get\\?.lua;!\\..\\libexec\\mingw-get\\?.lua" );
+  return true;
+}
+
 int pkgXmlNode::DispatchScript
 ( int status, const char *context, const char *priority, pkgXmlNode *action )
 {
@@ -593,6 +603,13 @@ int pkgXmlNode::DispatchScript
    */
   lua_State *interpreter = NULL;
   static const char *priority_key = "precedence";
+  static bool lua_path_setup = false;
+
+  if( ! lua_path_setup )
+    /*
+     * The Lua script path hasn't been initialised yet; do it now!
+     */
+    lua_path_setup = init_lua_path();
 
   while( action != NULL )
   {