diff options
author | Maurus Cuelenaere <mcuelenaere@gmail.com> | 2009-06-28 14:55:16 +0000 |
---|---|---|
committer | Maurus Cuelenaere <mcuelenaere@gmail.com> | 2009-06-28 14:55:16 +0000 |
commit | 681ca21a1e6731d7ce46be2a2419e600e957fae9 (patch) | |
tree | 77f111b10cb3ab26e1b97f9047972bc9004f69ae /apps/plugins/lua/rocklib.c | |
parent | 8e4098bd663c18ea800f47f88e657206d23a76ae (diff) | |
download | rockbox-681ca21a1e6731d7ce46be2a2419e600e957fae9.tar.gz rockbox-681ca21a1e6731d7ce46be2a2419e600e957fae9.zip |
Lua:
* add IO lib (adapted to Rockbox)
* remove old IO wrappers
* rework helloworld.lua to work with the IO lib
* do some stuff in helloworld.lua better (part of FS#10379, by James Callahan)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21541 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins/lua/rocklib.c')
-rw-r--r-- | apps/plugins/lua/rocklib.c | 100 |
1 files changed, 0 insertions, 100 deletions
diff --git a/apps/plugins/lua/rocklib.c b/apps/plugins/lua/rocklib.c index f22bd01b48..6da57d154e 100644 --- a/apps/plugins/lua/rocklib.c +++ b/apps/plugins/lua/rocklib.c | |||
@@ -685,62 +685,6 @@ RB_WRAP(backlight_set_brightness) | |||
685 | } | 685 | } |
686 | #endif | 686 | #endif |
687 | 687 | ||
688 | RB_WRAP(open) | ||
689 | { | ||
690 | const char* pathname = luaL_checkstring(L, 1); | ||
691 | int flags = luaL_checkint(L, 2); | ||
692 | int result = rb->open(pathname, flags); | ||
693 | lua_pushinteger(L, result); | ||
694 | return 1; | ||
695 | } | ||
696 | |||
697 | RB_WRAP(close) | ||
698 | { | ||
699 | int fd = luaL_checkint(L, 1); | ||
700 | int result = rb->close(fd); | ||
701 | lua_pushinteger(L, result); | ||
702 | return 1; | ||
703 | } | ||
704 | |||
705 | RB_WRAP(read) | ||
706 | { | ||
707 | size_t len, n, result = 0; | ||
708 | luaL_Buffer b; | ||
709 | |||
710 | int fd = luaL_checkint(L, 1); | ||
711 | size_t count = luaL_checkint(L, 2); | ||
712 | |||
713 | luaL_buffinit(L, &b); | ||
714 | len = LUAL_BUFFERSIZE; | ||
715 | do | ||
716 | { | ||
717 | char *p = luaL_prepbuffer(&b); | ||
718 | |||
719 | if (len > count) | ||
720 | len = count; | ||
721 | |||
722 | n = rb->read(fd, p, len); | ||
723 | |||
724 | luaL_addsize(&b, n); | ||
725 | count -= n; | ||
726 | result += n; | ||
727 | } while (count > 0 && n == len); | ||
728 | luaL_pushresult(&b); /* close buffer */ | ||
729 | |||
730 | lua_pushinteger(L, result); | ||
731 | return 2; | ||
732 | } | ||
733 | |||
734 | RB_WRAP(lseek) | ||
735 | { | ||
736 | int fd = luaL_checkint(L, 1); | ||
737 | off_t offset = luaL_checkint(L, 2); | ||
738 | int whence = luaL_checkint(L, 3); | ||
739 | off_t result = rb->lseek(fd, offset, whence); | ||
740 | lua_pushinteger(L, result); | ||
741 | return 1; | ||
742 | } | ||
743 | |||
744 | RB_WRAP(creat) | 688 | RB_WRAP(creat) |
745 | { | 689 | { |
746 | const char* pathname = luaL_checkstring(L, 1); | 690 | const char* pathname = luaL_checkstring(L, 1); |
@@ -749,16 +693,6 @@ RB_WRAP(creat) | |||
749 | return 1; | 693 | return 1; |
750 | } | 694 | } |
751 | 695 | ||
752 | RB_WRAP(write) | ||
753 | { | ||
754 | size_t count; | ||
755 | int fd = luaL_checkint(L, 1); | ||
756 | void* buf = (void*)luaL_checklstring(L, 2, &count); | ||
757 | ssize_t result = rb->write(fd, buf, count); | ||
758 | lua_pushinteger(L, result); | ||
759 | return 1; | ||
760 | } | ||
761 | |||
762 | RB_WRAP(remove) | 696 | RB_WRAP(remove) |
763 | { | 697 | { |
764 | const char* pathname = luaL_checkstring(L, 1); | 698 | const char* pathname = luaL_checkstring(L, 1); |
@@ -776,23 +710,6 @@ RB_WRAP(rename) | |||
776 | return 1; | 710 | return 1; |
777 | } | 711 | } |
778 | 712 | ||
779 | RB_WRAP(ftruncate) | ||
780 | { | ||
781 | int fd = luaL_checkint(L, 1); | ||
782 | off_t length = luaL_checkint(L, 2); | ||
783 | int result = rb->ftruncate(fd, length); | ||
784 | lua_pushinteger(L, result); | ||
785 | return 1; | ||
786 | } | ||
787 | |||
788 | RB_WRAP(filesize) | ||
789 | { | ||
790 | int fd = luaL_checkint(L, 1); | ||
791 | off_t result = rb->filesize(fd); | ||
792 | lua_pushinteger(L, result); | ||
793 | return 1; | ||
794 | } | ||
795 | |||
796 | RB_WRAP(file_exists) | 713 | RB_WRAP(file_exists) |
797 | { | 714 | { |
798 | const char* path = luaL_checkstring(L, 1); | 715 | const char* path = luaL_checkstring(L, 1); |
@@ -940,16 +857,9 @@ static const luaL_Reg rocklib[] = | |||
940 | #endif | 857 | #endif |
941 | 858 | ||
942 | /* File handling */ | 859 | /* File handling */ |
943 | R(open), | ||
944 | R(close), | ||
945 | R(read), | ||
946 | R(lseek), | ||
947 | R(creat), | 860 | R(creat), |
948 | R(write), | ||
949 | R(remove), | 861 | R(remove), |
950 | R(rename), | 862 | R(rename), |
951 | R(ftruncate), | ||
952 | R(filesize), | ||
953 | R(file_exists), | 863 | R(file_exists), |
954 | 864 | ||
955 | /* Kernel */ | 865 | /* Kernel */ |
@@ -1008,16 +918,6 @@ LUALIB_API int luaopen_rock(lua_State *L) | |||
1008 | RB_CONSTANT(LCD_WIDTH); | 918 | RB_CONSTANT(LCD_WIDTH); |
1009 | RB_CONSTANT(LCD_HEIGHT); | 919 | RB_CONSTANT(LCD_HEIGHT); |
1010 | 920 | ||
1011 | RB_CONSTANT(O_RDONLY); | ||
1012 | RB_CONSTANT(O_WRONLY); | ||
1013 | RB_CONSTANT(O_RDWR); | ||
1014 | RB_CONSTANT(O_CREAT); | ||
1015 | RB_CONSTANT(O_APPEND); | ||
1016 | RB_CONSTANT(O_TRUNC); | ||
1017 | RB_CONSTANT(SEEK_SET); | ||
1018 | RB_CONSTANT(SEEK_CUR); | ||
1019 | RB_CONSTANT(SEEK_END); | ||
1020 | |||
1021 | RB_CONSTANT(FONT_SYSFIXED); | 921 | RB_CONSTANT(FONT_SYSFIXED); |
1022 | RB_CONSTANT(FONT_UI); | 922 | RB_CONSTANT(FONT_UI); |
1023 | 923 | ||