lua-users home
lua-l archive

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


"Erik Hougaard" <erik@hougaard.com> writes:

> > Yes, I always intended that at #! header in a byte code file be
> > completely optional, only to used by people creating standalone
> > programs on Unix, just as it is for source files.  I am surprised this
> > suggestion generated so much controversy.  Perhaps people thought I
> > was suggesting all byte code files include the header.  If so, I
> > apologize for the confusion.
>
> Properly because you said "Please change the Lua interpreter so ....."
...
> As long as the modification is done in the lua.c I dont care. Optional -
> even better :-)

Aw, it's not a big deal.  On SPARC Solaris, using gcc in the bloaty -fpic
mode, it adds all of 112 bytes to the text segment.  Just a mod to
ldo.c:parse_file().  IMO this is the right place for # special-casing: in
file handling, not in the definition of chunk.

Jay

--- ldo.c~ Mon Oct 30 07:38:50 2000
+++ ldo.c Thu Aug  2 10:37:15 2001
@@ -266,6 +266,21 @@
   if (f == NULL) return LUA_ERRFILE;  /* unable to open file */
   c = fgetc(f);
   ungetc(c, f);
+
+  if (c == '#') {
+    /* Eat until EOL */
+    while (1) {
+      c = fgetc(f);
+      if (c == EOF || c == '\n') {
+        break;
+      }
+    }
+    if (c != EOF) {
+      c = fgetc(f);
+      ungetc(c, f);
+    }
+  }
+
   bin = (c == ID_CHUNK);
   if (bin && f != stdin) {
     f = freopen(filename, "rb", f);  /* set binary mode */