Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Add light version of the Lua I/O library

  • Loading branch information...
commit 07ab4d2bd092d0dc5fc6f05f740ee33ea6af84d8 1 parent a8b967b
Sébastien Bourdeauducq authored June 03, 2012
39  libglue/file.c
@@ -226,7 +226,7 @@ int fflush(FILE *stream)
226 226
 
227 227
 char *fgets(char *s, int size, FILE *stream)
228 228
 {
229  
-	return NULL;
  229
+	return NULL; /* TODO */
230 230
 }
231 231
 
232 232
 size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream)
@@ -300,12 +300,23 @@ int fputc(int c, FILE *stream)
300 300
 
301 301
 int ferror(FILE *stream)
302 302
 {
303  
-	return 0; /* TODO */
  303
+	return 0;
304 304
 }
305 305
 
306 306
 int feof(FILE *stream)
307 307
 {
308  
-	return 0; /* TODO */
  308
+	int fd;
  309
+	loff_t position;
  310
+	loff_t end;
  311
+	
  312
+	if(is_std_stream(stream))
  313
+		return 1;
  314
+	
  315
+	fd = *(int *)stream;
  316
+	position = yaffs_lseek(fd, 0, SEEK_CUR);
  317
+	end = yaffs_lseek(fd, 0, SEEK_END);
  318
+	yaffs_lseek(fd, position, SEEK_SET);
  319
+	return position == end;
309 320
 }
310 321
 
311 322
 FILE *freopen(const char *path, const char *mode, FILE *stream)
@@ -325,3 +336,25 @@ FILE *freopen(const char *path, const char *mode, FILE *stream)
325 336
 	free(newfd);
326 337
 	return stream;
327 338
 }
  339
+
  340
+int fseek(FILE *stream, long offset, int whence)
  341
+{
  342
+	int fd;
  343
+	
  344
+	if(is_std_stream(stream))
  345
+		return -1;
  346
+	fd = *(int *)stream;
  347
+	if(yaffs_lseek(fd, offset, whence) < 0)
  348
+		return -1;
  349
+	return 0;
  350
+}
  351
+
  352
+long ftell(FILE *stream)
  353
+{
  354
+	int fd;
  355
+	
  356
+	if(is_std_stream(stream))
  357
+		return -1;
  358
+	fd = *(int *)stream;
  359
+	return yaffs_lseek(fd, 0, SEEK_CUR);
  360
+}
2  liblfs/Makefile
@@ -2,7 +2,7 @@ MISPDIR=..
2 2
 include $(MISPDIR)/common.mak
3 3
 
4 4
 CFLAGS+=-I$(MISPDIR)/liblfs/include -I$(YAFFSDIR)/direct -I$(YAFFSDIR) -DCONFIG_YAFFS_DIRECT -DCONFIG_YAFFS_DEFINES_TYPES -DCONFIG_YAFFS_PROVIDE_DEFS -DCONFIG_YAFFSFS_PROVIDE_VALUES -I$(LUADIR)/src
5  
-OBJECTS=lfs.o
  5
+OBJECTS=lfs.o liolightlib.o
6 6
 
7 7
 all: liblfs.a
8 8
 
1  liblfs/include/lfs.h
@@ -9,6 +9,7 @@
9 9
 #ifndef __LFS_H
10 10
 #define __LFS_H
11 11
 
  12
+int luaopen_iolight(lua_State *L);
12 13
 int luaopen_lfs(lua_State *L);
13 14
 
14 15
 #endif /* __LFS_H */
528  liblfs/liolightlib.c
... ...
@@ -0,0 +1,528 @@
  1
+/*
  2
+** $Id: liolib.c,v 2.108 2011/11/25 12:50:03 roberto Exp $
  3
+** Standard I/O (and system) library
  4
+** See Copyright Notice in lua.h
  5
+** Based on lua-5.2.0
  6
+** Adapted for MISP - Sebastien Bourdeauducq, 2012
  7
+*/
  8
+
  9
+#include <errno.h>
  10
+#include <stdio.h>
  11
+#include <stdlib.h>
  12
+#include <string.h>
  13
+
  14
+#include <lua.h>
  15
+#include <lauxlib.h>
  16
+#include <lualib.h>
  17
+#include <lfs.h>
  18
+
  19
+/* }====================================================== */
  20
+
  21
+
  22
+/*
  23
+** {======================================================
  24
+** lua_fseek/lua_ftell: configuration for longer offsets
  25
+** =======================================================
  26
+*/
  27
+
  28
+#define l_fseek(f,o,w)		fseek(f,o,w)
  29
+#define l_ftell(f)		ftell(f)
  30
+#define l_seeknum		long
  31
+
  32
+/* }====================================================== */
  33
+
  34
+
  35
+#define IO_PREFIX	"_IO_"
  36
+#define IO_INPUT	(IO_PREFIX "input")
  37
+#define IO_OUTPUT	(IO_PREFIX "output")
  38
+
  39
+
  40
+typedef luaL_Stream LStream;
  41
+
  42
+
  43
+#define tolstream(L)	((LStream *)luaL_checkudata(L, 1, LUA_FILEHANDLE))
  44
+
  45
+#define isclosed(p)	((p)->closef == NULL)
  46
+
  47
+
  48
+static int io_type (lua_State *L) {
  49
+  LStream *p;
  50
+  luaL_checkany(L, 1);
  51
+  p = (LStream *)luaL_testudata(L, 1, LUA_FILEHANDLE);
  52
+  if (p == NULL)
  53
+    lua_pushnil(L);  /* not a file */
  54
+  else if (isclosed(p))
  55
+    lua_pushliteral(L, "closed file");
  56
+  else
  57
+    lua_pushliteral(L, "file");
  58
+  return 1;
  59
+}
  60
+
  61
+
  62
+static int f_tostring (lua_State *L) {
  63
+  LStream *p = tolstream(L);
  64
+  if (isclosed(p))
  65
+    lua_pushliteral(L, "file (closed)");
  66
+  else
  67
+    lua_pushfstring(L, "file (%p)", p->f);
  68
+  return 1;
  69
+}
  70
+
  71
+
  72
+static FILE *tofile (lua_State *L) {
  73
+  LStream *p = tolstream(L);
  74
+  if (isclosed(p))
  75
+    luaL_error(L, "attempt to use a closed file");
  76
+  lua_assert(p->f);
  77
+  return p->f;
  78
+}
  79
+
  80
+
  81
+/*
  82
+** When creating file handles, always creates a `closed' file handle
  83
+** before opening the actual file; so, if there is a memory error, the
  84
+** file is not left opened.
  85
+*/
  86
+static LStream *newprefile (lua_State *L) {
  87
+  LStream *p = (LStream *)lua_newuserdata(L, sizeof(LStream));
  88
+  p->closef = NULL;  /* mark file handle as 'closed' */
  89
+  luaL_setmetatable(L, LUA_FILEHANDLE);
  90
+  return p;
  91
+}
  92
+
  93
+
  94
+static int aux_close (lua_State *L) {
  95
+  LStream *p = tolstream(L);
  96
+  lua_CFunction cf = p->closef;
  97
+  p->closef = NULL;  /* mark stream as closed */
  98
+  return (*cf)(L);  /* close it */
  99
+}
  100
+
  101
+
  102
+static int io_close (lua_State *L) {
  103
+  if (lua_isnone(L, 1))  /* no argument? */
  104
+    lua_getfield(L, LUA_REGISTRYINDEX, IO_OUTPUT);  /* use standard output */
  105
+  tofile(L);  /* make sure argument is an open stream */
  106
+  return aux_close(L);
  107
+}
  108
+
  109
+
  110
+static int f_gc (lua_State *L) {
  111
+  LStream *p = tolstream(L);
  112
+  if (!isclosed(p) && p->f != NULL)
  113
+    aux_close(L);  /* ignore closed and incompletely open files */
  114
+  return 0;
  115
+}
  116
+
  117
+
  118
+/*
  119
+** function to close regular files
  120
+*/
  121
+static int io_fclose (lua_State *L) {
  122
+  LStream *p = tolstream(L);
  123
+  int res = fclose(p->f);
  124
+  return luaL_fileresult(L, (res == 0), NULL);
  125
+}
  126
+
  127
+
  128
+static LStream *newfile (lua_State *L) {
  129
+  LStream *p = newprefile(L);
  130
+  p->f = NULL;
  131
+  p->closef = &io_fclose;
  132
+  return p;
  133
+}
  134
+
  135
+
  136
+static void opencheck (lua_State *L, const char *fname, const char *mode) {
  137
+  LStream *p = newfile(L);
  138
+  p->f = fopen(fname, mode);
  139
+  if (p->f == NULL)
  140
+    luaL_error(L, "cannot open file " LUA_QS " (%s)", fname, strerror(errno));
  141
+}
  142
+
  143
+
  144
+static int io_open (lua_State *L) {
  145
+  const char *filename = luaL_checkstring(L, 1);
  146
+  const char *mode = luaL_optstring(L, 2, "r");
  147
+  LStream *p = newfile(L);
  148
+  int i = 0;
  149
+  /* check whether 'mode' matches '[rwa]%+?b?' */
  150
+  if (!(mode[i] != '\0' && strchr("rwa", mode[i++]) != NULL &&
  151
+       (mode[i] != '+' || ++i) &&  /* skip if char is '+' */
  152
+       (mode[i] != 'b' || ++i) &&  /* skip if char is 'b' */
  153
+       (mode[i] == '\0')))
  154
+    return luaL_error(L, "invalid mode " LUA_QS
  155
+                         " (should match " LUA_QL("[rwa]%%+?b?") ")", mode);
  156
+  p->f = fopen(filename, mode);
  157
+  return (p->f == NULL) ? luaL_fileresult(L, 0, filename) : 1;
  158
+}
  159
+
  160
+
  161
+static FILE *getiofile (lua_State *L, const char *findex) {
  162
+  LStream *p;
  163
+  lua_getfield(L, LUA_REGISTRYINDEX, findex);
  164
+  p = (LStream *)lua_touserdata(L, -1);
  165
+  if (isclosed(p))
  166
+    luaL_error(L, "standard %s file is closed", findex + strlen(IO_PREFIX));
  167
+  return p->f;
  168
+}
  169
+
  170
+
  171
+static int g_iofile (lua_State *L, const char *f, const char *mode) {
  172
+  if (!lua_isnoneornil(L, 1)) {
  173
+    const char *filename = lua_tostring(L, 1);
  174
+    if (filename)
  175
+      opencheck(L, filename, mode);
  176
+    else {
  177
+      tofile(L);  /* check that it's a valid file handle */
  178
+      lua_pushvalue(L, 1);
  179
+    }
  180
+    lua_setfield(L, LUA_REGISTRYINDEX, f);
  181
+  }
  182
+  /* return current value */
  183
+  lua_getfield(L, LUA_REGISTRYINDEX, f);
  184
+  return 1;
  185
+}
  186
+
  187
+
  188
+static int io_input (lua_State *L) {
  189
+  return g_iofile(L, IO_INPUT, "r");
  190
+}
  191
+
  192
+
  193
+static int io_output (lua_State *L) {
  194
+  return g_iofile(L, IO_OUTPUT, "w");
  195
+}
  196
+
  197
+
  198
+static int io_readline (lua_State *L);
  199
+
  200
+
  201
+static void aux_lines (lua_State *L, int toclose) {
  202
+  int i;
  203
+  int n = lua_gettop(L) - 1;  /* number of arguments to read */
  204
+  /* ensure that arguments will fit here and into 'io_readline' stack */
  205
+  luaL_argcheck(L, n <= LUA_MINSTACK - 3, LUA_MINSTACK - 3, "too many options");
  206
+  lua_pushvalue(L, 1);  /* file handle */
  207
+  lua_pushinteger(L, n);  /* number of arguments to read */
  208
+  lua_pushboolean(L, toclose);  /* close/not close file when finished */
  209
+  for (i = 1; i <= n; i++) lua_pushvalue(L, i + 1);  /* copy arguments */
  210
+  lua_pushcclosure(L, io_readline, 3 + n);
  211
+}
  212
+
  213
+
  214
+static int f_lines (lua_State *L) {
  215
+  tofile(L);  /* check that it's a valid file handle */
  216
+  aux_lines(L, 0);
  217
+  return 1;
  218
+}
  219
+
  220
+
  221
+static int io_lines (lua_State *L) {
  222
+  int toclose;
  223
+  if (lua_isnone(L, 1)) lua_pushnil(L);  /* at least one argument */
  224
+  if (lua_isnil(L, 1)) {  /* no file name? */
  225
+    lua_getfield(L, LUA_REGISTRYINDEX, IO_INPUT);  /* get default input */
  226
+    lua_replace(L, 1);  /* put it at index 1 */
  227
+    tofile(L);  /* check that it's a valid file handle */
  228
+    toclose = 0;  /* do not close it after iteration */
  229
+  }
  230
+  else {  /* open a new file */
  231
+    const char *filename = luaL_checkstring(L, 1);
  232
+    opencheck(L, filename, "r");
  233
+    lua_replace(L, 1);  /* put file at index 1 */
  234
+    toclose = 1;  /* close it after iteration */
  235
+  }
  236
+  aux_lines(L, toclose);
  237
+  return 1;
  238
+}
  239
+
  240
+
  241
+/*
  242
+** {======================================================
  243
+** READ
  244
+** =======================================================
  245
+*/
  246
+
  247
+static int test_eof (lua_State *L, FILE *f) {
  248
+  lua_pushlstring(L, NULL, 0);
  249
+  return !feof(f);
  250
+}
  251
+
  252
+
  253
+static int read_line (lua_State *L, FILE *f, int chop) {
  254
+  luaL_Buffer b;
  255
+  luaL_buffinit(L, &b);
  256
+  for (;;) {
  257
+    size_t l;
  258
+    char *p = luaL_prepbuffer(&b);
  259
+    if (fgets(p, LUAL_BUFFERSIZE, f) == NULL) {  /* eof? */
  260
+      luaL_pushresult(&b);  /* close buffer */
  261
+      return (lua_rawlen(L, -1) > 0);  /* check whether read something */
  262
+    }
  263
+    l = strlen(p);
  264
+    if (l == 0 || p[l-1] != '\n')
  265
+      luaL_addsize(&b, l);
  266
+    else {
  267
+      luaL_addsize(&b, l - chop);  /* chop 'eol' if needed */
  268
+      luaL_pushresult(&b);  /* close buffer */
  269
+      return 1;  /* read at least an `eol' */
  270
+    }
  271
+  }
  272
+}
  273
+
  274
+
  275
+#define MAX_SIZE_T	(~(size_t)0)
  276
+
  277
+static void read_all (lua_State *L, FILE *f) {
  278
+  size_t rlen = LUAL_BUFFERSIZE;  /* how much to read in each cycle */
  279
+  luaL_Buffer b;
  280
+  luaL_buffinit(L, &b);
  281
+  for (;;) {
  282
+    char *p = luaL_prepbuffsize(&b, rlen);
  283
+    size_t nr = fread(p, sizeof(char), rlen, f);
  284
+    luaL_addsize(&b, nr);
  285
+    if (nr < rlen) break;  /* eof? */
  286
+    else if (rlen <= (MAX_SIZE_T / 4))  /* avoid buffers too large */
  287
+      rlen *= 2;  /* double buffer size at each iteration */
  288
+  }
  289
+  luaL_pushresult(&b);  /* close buffer */
  290
+}
  291
+
  292
+
  293
+static int read_chars (lua_State *L, FILE *f, size_t n) {
  294
+  size_t nr;  /* number of chars actually read */
  295
+  char *p;
  296
+  luaL_Buffer b;
  297
+  luaL_buffinit(L, &b);
  298
+  p = luaL_prepbuffsize(&b, n);  /* prepare buffer to read whole block */
  299
+  nr = fread(p, sizeof(char), n, f);  /* try to read 'n' chars */
  300
+  luaL_addsize(&b, nr);
  301
+  luaL_pushresult(&b);  /* close buffer */
  302
+  return (nr > 0);  /* true iff read something */
  303
+}
  304
+
  305
+
  306
+static int g_read (lua_State *L, FILE *f, int first) {
  307
+  int nargs = lua_gettop(L) - 1;
  308
+  int success;
  309
+  int n;
  310
+
  311
+  if (nargs == 0) {  /* no arguments? */
  312
+    success = read_line(L, f, 1);
  313
+    n = first+1;  /* to return 1 result */
  314
+  }
  315
+  else {  /* ensure stack space for all results and for auxlib's buffer */
  316
+    luaL_checkstack(L, nargs+LUA_MINSTACK, "too many arguments");
  317
+    success = 1;
  318
+    for (n = first; nargs-- && success; n++) {
  319
+      if (lua_type(L, n) == LUA_TNUMBER) {
  320
+        size_t l = (size_t)lua_tointeger(L, n);
  321
+        success = (l == 0) ? test_eof(L, f) : read_chars(L, f, l);
  322
+      }
  323
+      else {
  324
+        const char *p = lua_tostring(L, n);
  325
+        luaL_argcheck(L, p && p[0] == '*', n, "invalid option");
  326
+        switch (p[1]) {
  327
+          case 'l':  /* line */
  328
+            success = read_line(L, f, 1);
  329
+            break;
  330
+          case 'L':  /* line with end-of-line */
  331
+            success = read_line(L, f, 0);
  332
+            break;
  333
+          case 'a':  /* file */
  334
+            read_all(L, f);  /* read entire file */
  335
+            success = 1; /* always success */
  336
+            break;
  337
+          default:
  338
+            return luaL_argerror(L, n, "invalid format");
  339
+        }
  340
+      }
  341
+    }
  342
+  }
  343
+  if (ferror(f))
  344
+    return luaL_fileresult(L, 0, NULL);
  345
+  if (!success) {
  346
+    lua_pop(L, 1);  /* remove last result */
  347
+    lua_pushnil(L);  /* push nil instead */
  348
+  }
  349
+  return n - first;
  350
+}
  351
+
  352
+
  353
+static int io_read (lua_State *L) {
  354
+  return g_read(L, getiofile(L, IO_INPUT), 1);
  355
+}
  356
+
  357
+
  358
+static int f_read (lua_State *L) {
  359
+  return g_read(L, tofile(L), 2);
  360
+}
  361
+
  362
+
  363
+static int io_readline (lua_State *L) {
  364
+  LStream *p = (LStream *)lua_touserdata(L, lua_upvalueindex(1));
  365
+  int i;
  366
+  int n = (int)lua_tointeger(L, lua_upvalueindex(2));
  367
+  if (isclosed(p))  /* file is already closed? */
  368
+    return luaL_error(L, "file is already closed");
  369
+  lua_settop(L , 1);
  370
+  for (i = 1; i <= n; i++)  /* push arguments to 'g_read' */
  371
+    lua_pushvalue(L, lua_upvalueindex(3 + i));
  372
+  n = g_read(L, p->f, 2);  /* 'n' is number of results */
  373
+  lua_assert(n > 0);  /* should return at least a nil */
  374
+  if (!lua_isnil(L, -n))  /* read at least one value? */
  375
+    return n;  /* return them */
  376
+  else {  /* first result is nil: EOF or error */
  377
+    if (n > 1) {  /* is there error information? */
  378
+      /* 2nd result is error message */
  379
+      return luaL_error(L, "%s", lua_tostring(L, -n + 1));
  380
+    }
  381
+    if (lua_toboolean(L, lua_upvalueindex(3))) {  /* generator created file? */
  382
+      lua_settop(L, 0);
  383
+      lua_pushvalue(L, lua_upvalueindex(1));
  384
+      aux_close(L);  /* close it */
  385
+    }
  386
+    return 0;
  387
+  }
  388
+}
  389
+
  390
+/* }====================================================== */
  391
+
  392
+
  393
+static int g_write (lua_State *L, FILE *f, int arg) {
  394
+  int nargs = lua_gettop(L) - arg;
  395
+  int status = 1;
  396
+  for (; nargs--; arg++) {
  397
+    if (lua_type(L, arg) == LUA_TNUMBER) {
  398
+      /* optimization: could be done exactly as for strings */
  399
+      status = status &&
  400
+          fprintf(f, LUA_NUMBER_FMT, lua_tonumber(L, arg)) > 0;
  401
+    }
  402
+    else {
  403
+      size_t l;
  404
+      const char *s = luaL_checklstring(L, arg, &l);
  405
+      status = status && (fwrite(s, sizeof(char), l, f) == l);
  406
+    }
  407
+  }
  408
+  if (status) return 1;  /* file handle already on stack top */
  409
+  else return luaL_fileresult(L, status, NULL);
  410
+}
  411
+
  412
+
  413
+static int io_write (lua_State *L) {
  414
+  return g_write(L, getiofile(L, IO_OUTPUT), 1);
  415
+}
  416
+
  417
+
  418
+static int f_write (lua_State *L) {
  419
+  FILE *f = tofile(L);
  420
+  lua_pushvalue(L, 1);  /* push file at the stack top (to be returned) */
  421
+  return g_write(L, f, 2);
  422
+}
  423
+
  424
+
  425
+static int f_seek (lua_State *L) {
  426
+  static const int mode[] = {SEEK_SET, SEEK_CUR, SEEK_END};
  427
+  static const char *const modenames[] = {"set", "cur", "end", NULL};
  428
+  FILE *f = tofile(L);
  429
+  int op = luaL_checkoption(L, 2, "cur", modenames);
  430
+  lua_Number p3 = luaL_optnumber(L, 3, 0);
  431
+  l_seeknum offset = (l_seeknum)p3;
  432
+  luaL_argcheck(L, (lua_Number)offset == p3, 3,
  433
+                  "not an integer in proper range");
  434
+  op = l_fseek(f, offset, mode[op]);
  435
+  if (op)
  436
+    return luaL_fileresult(L, 0, NULL);  /* error */
  437
+  else {
  438
+    lua_pushnumber(L, (lua_Number)l_ftell(f));
  439
+    return 1;
  440
+  }
  441
+}
  442
+
  443
+static int io_flush (lua_State *L) {
  444
+  return luaL_fileresult(L, fflush(getiofile(L, IO_OUTPUT)) == 0, NULL);
  445
+}
  446
+
  447
+
  448
+static int f_flush (lua_State *L) {
  449
+  return luaL_fileresult(L, fflush(tofile(L)) == 0, NULL);
  450
+}
  451
+
  452
+
  453
+/*
  454
+** functions for 'io' library
  455
+*/
  456
+static const luaL_Reg iolib[] = {
  457
+  {"close", io_close},
  458
+  {"flush", io_flush},
  459
+  {"input", io_input},
  460
+  {"lines", io_lines},
  461
+  {"open", io_open},
  462
+  {"output", io_output},
  463
+  {"read", io_read},
  464
+  {"type", io_type},
  465
+  {"write", io_write},
  466
+  {NULL, NULL}
  467
+};
  468
+
  469
+
  470
+/*
  471
+** methods for file handles
  472
+*/
  473
+static const luaL_Reg flib[] = {
  474
+  {"close", io_close},
  475
+  {"flush", f_flush},
  476
+  {"lines", f_lines},
  477
+  {"read", f_read},
  478
+  {"seek", f_seek},
  479
+  {"write", f_write},
  480
+  {"__gc", f_gc},
  481
+  {"__tostring", f_tostring},
  482
+  {NULL, NULL}
  483
+};
  484
+
  485
+
  486
+static void createmeta (lua_State *L) {
  487
+  luaL_newmetatable(L, LUA_FILEHANDLE);  /* create metatable for file handles */
  488
+  lua_pushvalue(L, -1);  /* push metatable */
  489
+  lua_setfield(L, -2, "__index");  /* metatable.__index = metatable */
  490
+  luaL_setfuncs(L, flib, 0);  /* add file methods to new metatable */
  491
+  lua_pop(L, 1);  /* pop new metatable */
  492
+}
  493
+
  494
+
  495
+/*
  496
+** function to (not) close the standard files stdin, stdout, and stderr
  497
+*/
  498
+static int io_noclose (lua_State *L) {
  499
+  LStream *p = tolstream(L);
  500
+  p->closef = &io_noclose;  /* keep file opened */
  501
+  lua_pushnil(L);
  502
+  lua_pushliteral(L, "cannot close standard file");
  503
+  return 2;
  504
+}
  505
+
  506
+
  507
+static void createstdfile (lua_State *L, FILE *f, const char *k,
  508
+                           const char *fname) {
  509
+  LStream *p = newprefile(L);
  510
+  p->f = f;
  511
+  p->closef = &io_noclose;
  512
+  if (k != NULL) {
  513
+    lua_pushvalue(L, -1);
  514
+    lua_setfield(L, LUA_REGISTRYINDEX, k);  /* add file to registry */
  515
+  }
  516
+  lua_setfield(L, -2, fname);  /* add file to module */
  517
+}
  518
+
  519
+
  520
+LUAMOD_API int luaopen_iolight (lua_State *L) {
  521
+  luaL_newlib(L, iolib);  /* new module */
  522
+  createmeta(L);
  523
+  /* create (and set) default files */
  524
+  createstdfile(L, stdin, IO_INPUT, "stdin");
  525
+  createstdfile(L, stdout, IO_OUTPUT, "stdout");
  526
+  createstdfile(L, stderr, NULL, "stderr");
  527
+  return 1;
  528
+}
3  libyaffs2/Makefile
... ...
@@ -1,7 +1,8 @@
1 1
 MISPDIR=..
2 2
 include $(MISPDIR)/common.mak
3 3
 
4  
-CFLAGS+=-include $(M2DIR)/software/include/base/errno.h -include $(YAFFSDIR)/direct/yportenv.h -I$(YAFFSDIR)/direct -I$(YAFFSDIR)
  4
+CFLAGS+=-include $(M2DIR)/software/include/base/errno.h -include $(M2DIR)/software/include/base/stdio.h
  5
+CFLAGS+=-include $(YAFFSDIR)/direct/yportenv.h -I$(YAFFSDIR)/direct -I$(YAFFSDIR)
5 6
 CFLAGS+=-DCONFIG_YAFFS_DIRECT -DCONFIG_YAFFS_DEFINES_TYPES -DCONFIG_YAFFS_PROVIDE_DEFS -DCONFIG_YAFFSFS_PROVIDE_VALUES
6 7
 
7 8
 OBJECTS=yaffs_ecc.o yaffs_guts.o yaffs_packedtags1.o yaffs_tagscompat.o yaffs_packedtags2.o yaffs_nand.o yaffs_checkptrw.o yaffs_nameval.o yaffs_attribs.o yaffs_allocator.o yaffs_bitmap.o yaffs_yaffs1.o yaffs_yaffs2.o yaffs_verify.o yaffs_summary.o
2  luainit.c
@@ -15,7 +15,7 @@ static const luaL_Reg loadedlibs[] = {
15 15
 	{LUA_LOADLIBNAME, luaopen_package},
16 16
 	{LUA_COLIBNAME, luaopen_coroutine},
17 17
 	{LUA_TABLIBNAME, luaopen_table},
18  
-// TODO	{LUA_IOLIBNAME, luaopen_io},
  18
+	{LUA_IOLIBNAME, luaopen_iolight},
19 19
 	{LUA_STRLIBNAME, luaopen_string},
20 20
 	{LUA_BITLIBNAME, luaopen_bit32},
21 21
 	{LUA_MATHLIBNAME, luaopen_math},
2  main.c
@@ -15,6 +15,8 @@ static void test_lua(void)
15 15
 {
16 16
 	lua_State *L;
17 17
 	
  18
+	// /patchpool/nil - Cid and Lucy.fnp
  19
+	
18 20
 	L = luaL_newstate();
19 21
 	luaL_openlibs(L);
20 22
 	luaL_dostring(L, "for i=10,1,-1 do print(i) end\n");

0 notes on commit 07ab4d2

Please sign in to comment.
Something went wrong with that request. Please try again.