Просмотр исходного кода

fix: lauxlib读取文件时使用的getc没有映射到luat_fs_getc

导致读取luac文件头时,首个字节返回0,导致判定luac文件不是二进制格式,从而使用文本模式读取luac, 结果肯定是无法读取.
修正后,air302也能使用通用的require方法,不再需要单独实现,实现统一
Wendal Chen 5 лет назад
Родитель
Сommit
6027f64c15
3 измененных файлов с 6 добавлено и 3 удалено
  1. 2 2
      bsp/air302/src/luat_air302_base.c
  2. 2 0
      lua/src/lauxlib.c
  3. 2 1
      lua/src/liolib.c

+ 2 - 2
bsp/air302/src/luat_air302_base.c

@@ -9,8 +9,8 @@ LUAMOD_API int luaopen_fatfs( lua_State *L );
 
 
 static const luaL_Reg loadedlibs[] = {
 static const luaL_Reg loadedlibs[] = {
   {"_G", luaopen_base}, // _G
   {"_G", luaopen_base}, // _G
-  {LUA_LOADLIBNAME, luaopen_package_air302}, // require
-//   {LUA_LOADLIBNAME, luaopen_package}, // require
+  // {LUA_LOADLIBNAME, luaopen_package_air302}, // require
+  {LUA_LOADLIBNAME, luaopen_package}, // require
   {LUA_COLIBNAME, luaopen_coroutine}, // coroutine协程库
   {LUA_COLIBNAME, luaopen_coroutine}, // coroutine协程库
   {LUA_TABLIBNAME, luaopen_table},    // table库,操作table类型的数据结构
   {LUA_TABLIBNAME, luaopen_table},    // table库,操作table类型的数据结构
   {LUA_IOLIBNAME, luaopen_io},        // io库,操作文件
   {LUA_IOLIBNAME, luaopen_io},        // io库,操作文件

+ 2 - 0
lua/src/lauxlib.c

@@ -34,6 +34,7 @@
 #undef fseek
 #undef fseek
 #undef feof
 #undef feof
 #undef ferror
 #undef ferror
+#undef getc
 
 
 #define fopen   luat_fs_fopen
 #define fopen   luat_fs_fopen
 #define fclose  luat_fs_fclose
 #define fclose  luat_fs_fclose
@@ -41,6 +42,7 @@
 #define fseek   luat_fs_fseek
 #define fseek   luat_fs_fseek
 #define ferror  luat_fs_ferror
 #define ferror  luat_fs_ferror
 #define feof    luat_fs_feof
 #define feof    luat_fs_feof
+#define getc    luat_fs_getc
 
 
 
 
 
 

+ 2 - 1
lua/src/liolib.c

@@ -87,7 +87,8 @@ static int l_checkmode (const char *mode) {
 #define l_lockfile(f)		flockfile(f)
 #define l_lockfile(f)		flockfile(f)
 #define l_unlockfile(f)		funlockfile(f)
 #define l_unlockfile(f)		funlockfile(f)
 #else
 #else
-#define l_getc(f)		getc(f)
+char luat_fs_getc(FILE* stream);
+#define l_getc(f)		luat_fs_getc(f)
 #define l_lockfile(f)		((void)0)
 #define l_lockfile(f)		((void)0)
 #define l_unlockfile(f)		((void)0)
 #define l_unlockfile(f)		((void)0)
 #endif
 #endif