lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Included is a patch that fixes a typo bug in loadlib.c
In addition the patch trims the trailing control characters 
from the error messages returned from FormatMessage().
Win32 only.

--- orig-lua-5.1-work3/src/lib/loadlib.c	Sat Nov 20 01:52:12 2004
+++ lua-5.1-work3/src/lib/loadlib.c	Wed Dec 22 11:43:11 2004
@@ -94,9 +94,14 @@
 {
  int error=GetLastError();
  char buffer[128];
- if (FormatMessage(FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM,
-	0, error, 0, buffer, sizeof(buffer), 0))
+ int l;
+ if ((l=FormatMessage(FORMAT_MESSAGE_IGNORE_INSERTS |
FORMAT_MESSAGE_FROM_SYSTEM,
+	0, error, 0, buffer, sizeof(buffer), 0)) != 0) {
+  /* remove trailing junk */
+  while (l > 0 && iscntrl(buffer[l-1]) || isspace(buffer[l-1])) l--;
+  if (l>=0) buffer[l] = '\0';
   lua_pushstring(L,buffer);
+ }
  else
   lua_pushfstring(L,"system error %d\n",error);
 }
@@ -111,7 +116,7 @@
   {
    registerlib(L, lib);
    lua_pushcfunction(L,f);
-   return 1;
+   return 0;
   }
  }
  pusherror(L);
@@ -123,7 +128,6 @@
 }
 
 
-
 /* Native Mac OS X / Darwin Implementation */
 #elif defined(USE_DYLD)