Skip to content

Commit

Permalink
Add light version of the Lua I/O library
Browse files Browse the repository at this point in the history
Sebastien Bourdeauducq committed Jun 3, 2012
1 parent a8b967b commit 07ab4d2
Showing 7 changed files with 571 additions and 6 deletions.
39 changes: 36 additions & 3 deletions libglue/file.c
Original file line number Diff line number Diff line change
@@ -226,7 +226,7 @@ int fflush(FILE *stream)

char *fgets(char *s, int size, FILE *stream)
{
return NULL;
return NULL; /* TODO */
}

size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream)
@@ -300,12 +300,23 @@ int fputc(int c, FILE *stream)

int ferror(FILE *stream)
{
return 0; /* TODO */
return 0;
}

int feof(FILE *stream)
{
return 0; /* TODO */
int fd;
loff_t position;
loff_t end;

if(is_std_stream(stream))
return 1;

fd = *(int *)stream;
position = yaffs_lseek(fd, 0, SEEK_CUR);
end = yaffs_lseek(fd, 0, SEEK_END);
yaffs_lseek(fd, position, SEEK_SET);
return position == end;
}

FILE *freopen(const char *path, const char *mode, FILE *stream)
@@ -325,3 +336,25 @@ FILE *freopen(const char *path, const char *mode, FILE *stream)
free(newfd);
return stream;
}

int fseek(FILE *stream, long offset, int whence)
{
int fd;

if(is_std_stream(stream))
return -1;
fd = *(int *)stream;
if(yaffs_lseek(fd, offset, whence) < 0)
return -1;
return 0;
}

long ftell(FILE *stream)
{
int fd;

if(is_std_stream(stream))
return -1;
fd = *(int *)stream;
return yaffs_lseek(fd, 0, SEEK_CUR);
}
2 changes: 1 addition & 1 deletion liblfs/Makefile
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@ MISPDIR=..
include $(MISPDIR)/common.mak

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
OBJECTS=lfs.o
OBJECTS=lfs.o liolightlib.o

all: liblfs.a

1 change: 1 addition & 0 deletions liblfs/include/lfs.h
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@
#ifndef __LFS_H
#define __LFS_H

int luaopen_iolight(lua_State *L);
int luaopen_lfs(lua_State *L);

#endif /* __LFS_H */
528 changes: 528 additions & 0 deletions liblfs/liolightlib.c

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion libyaffs2/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
MISPDIR=..
include $(MISPDIR)/common.mak

CFLAGS+=-include $(M2DIR)/software/include/base/errno.h -include $(YAFFSDIR)/direct/yportenv.h -I$(YAFFSDIR)/direct -I$(YAFFSDIR)
CFLAGS+=-include $(M2DIR)/software/include/base/errno.h -include $(M2DIR)/software/include/base/stdio.h
CFLAGS+=-include $(YAFFSDIR)/direct/yportenv.h -I$(YAFFSDIR)/direct -I$(YAFFSDIR)
CFLAGS+=-DCONFIG_YAFFS_DIRECT -DCONFIG_YAFFS_DEFINES_TYPES -DCONFIG_YAFFS_PROVIDE_DEFS -DCONFIG_YAFFSFS_PROVIDE_VALUES

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 changes: 1 addition & 1 deletion luainit.c
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@ static const luaL_Reg loadedlibs[] = {
{LUA_LOADLIBNAME, luaopen_package},
{LUA_COLIBNAME, luaopen_coroutine},
{LUA_TABLIBNAME, luaopen_table},
// TODO {LUA_IOLIBNAME, luaopen_io},
{LUA_IOLIBNAME, luaopen_iolight},
{LUA_STRLIBNAME, luaopen_string},
{LUA_BITLIBNAME, luaopen_bit32},
{LUA_MATHLIBNAME, luaopen_math},
2 changes: 2 additions & 0 deletions main.c
Original file line number Diff line number Diff line change
@@ -15,6 +15,8 @@ static void test_lua(void)
{
lua_State *L;

// /patchpool/nil - Cid and Lucy.fnp

L = luaL_newstate();
luaL_openlibs(L);
luaL_dostring(L, "for i=10,1,-1 do print(i) end\n");

0 comments on commit 07ab4d2

Please sign in to comment.