فهرست منبع

add: 实现rotable可选,使得LUAT_CONF_DISABLE_ROTABLE可用

Wendal Chen 4 سال پیش
والد
کامیت
ae0e4f1c32
39فایلهای تغییر یافته به همراه62 افزوده شده و 38 حذف شده
  1. 1 1
      bsp/win32/include/luat_conf_bsp.h
  2. 1 1
      bsp/win32/port/luat_lib_win32.c
  3. 2 1
      lua/include/lauxlib.h
  4. 1 1
      lua/src/lcorolib.c
  5. 1 1
      lua/src/ldblib.c
  6. 1 1
      lua/src/liolib.c
  7. 1 1
      lua/src/lmathlib.c
  8. 1 1
      lua/src/loslib.c
  9. 1 1
      lua/src/lstrlib.c
  10. 1 1
      luat/modules/luat_lib_adc.c
  11. 1 1
      luat/modules/luat_lib_crypto.c
  12. 1 1
      luat/modules/luat_lib_ctiot.c
  13. 1 1
      luat/modules/luat_lib_dbg.c
  14. 1 1
      luat/modules/luat_lib_fs.c
  15. 1 1
      luat/modules/luat_lib_gpio.c
  16. 1 1
      luat/modules/luat_lib_http.c
  17. 1 1
      luat/modules/luat_lib_i2c.c
  18. 1 1
      luat/modules/luat_lib_libcoap.c
  19. 1 1
      luat/modules/luat_lib_log.c
  20. 1 1
      luat/modules/luat_lib_lpmem.c
  21. 1 1
      luat/modules/luat_lib_mqttcore.c
  22. 1 1
      luat/modules/luat_lib_pack.c
  23. 1 1
      luat/modules/luat_lib_pm.c
  24. 1 1
      luat/modules/luat_lib_pwm.c
  25. 1 1
      luat/modules/luat_lib_rtos.c
  26. 1 1
      luat/modules/luat_lib_sensor.c
  27. 1 1
      luat/modules/luat_lib_socket.c
  28. 1 1
      luat/modules/luat_lib_spi.c
  29. 1 1
      luat/modules/luat_lib_timer.c
  30. 1 1
      luat/modules/luat_lib_uart.c
  31. 1 1
      luat/modules/luat_lib_zbuff.c
  32. 23 0
      luat/modules/luat_main.c
  33. 1 1
      luat/modules/luat_malloc_weak.c
  34. 1 1
      luat/packages/eink/luat_lib_eink.c
  35. 1 1
      luat/packages/fatfs/luat_lib_fatfs.c
  36. 1 1
      luat/packages/lua-cjson/lua_cjson.c
  37. 1 1
      luat/packages/minmea/luat_lib_libgnss.c
  38. 1 1
      luat/rtt/luat_lib_utest.c
  39. 1 1
      luat/rtt/luat_lib_wlan.c

+ 1 - 1
bsp/win32/include/luat_conf_bsp.h

@@ -11,7 +11,7 @@
 
 #define LUA_COMPAT_BITLIB 1
 
-#define LUAT_CONF_DISABLE_ROTABLE
+//#define LUAT_CONF_DISABLE_ROTABLE
 
 #define LUAT_USE_FS_VFS 1
 

+ 1 - 1
bsp/win32/port/luat_lib_win32.c

@@ -32,6 +32,6 @@ static const rotable_Reg reg_win32[] =
 };
 
 LUAMOD_API int luaopen_win32( lua_State *L ) {
-    rotable_newlib(L, reg_win32);
+    luat_newlib(L, reg_win32);
     return 1;
 }

+ 2 - 1
lua/include/lauxlib.h

@@ -262,7 +262,8 @@ void luat_log_log(int level, const char* tag, const char* _fmt, ...); // 4 is ER
 #endif
 /* }============================================================ */
 
-
+#include "rotable.h"
+void luat_newlib(lua_State* L, const rotable_Reg* reg);
 
 #endif
 

+ 1 - 1
lua/src/lcorolib.c

@@ -162,7 +162,7 @@ static const rotable_Reg co_funcs[] = {
 
 
 LUAMOD_API int luaopen_coroutine (lua_State *L) {
-  rotable_newlib(L, co_funcs);
+  luat_newlib(L, co_funcs);
   return 1;
 }
 

+ 1 - 1
lua/src/ldblib.c

@@ -450,7 +450,7 @@ static const rotable_Reg dblib[] = {
 
 
 LUAMOD_API int luaopen_debug (lua_State *L) {
-  rotable_newlib(L, dblib);
+  luat_newlib(L, dblib);
   return 1;
 }
 

+ 1 - 1
lua/src/liolib.c

@@ -875,7 +875,7 @@ static void createmeta (lua_State *L) {
 
 
 LUAMOD_API int luaopen_io (lua_State *L) {
-  rotable_newlib(L, iolib);  /* new module */
+  luat_newlib(L, iolib);  /* new module */
   createmeta(L);
   /* create (and set) default files */
   //createstdfile(L, stdin, IO_INPUT, "stdin");

+ 1 - 1
lua/src/lmathlib.c

@@ -396,7 +396,7 @@ static const rotable_Reg mathlib[] = {
 ** Open math library
 */
 LUAMOD_API int luaopen_math (lua_State *L) {
-  rotable_newlib(L, mathlib);
+  luat_newlib(L, mathlib);
   // lua_pushnumber(L, PI);
   // lua_setfield(L, -2, "pi");
   // lua_pushnumber(L, (lua_Number)HUGE_VAL);

+ 1 - 1
lua/src/loslib.c

@@ -408,7 +408,7 @@ static const rotable_Reg syslib[] = {
 
 
 LUAMOD_API int luaopen_os (lua_State *L) {
-  rotable_newlib(L, syslib);
+  luat_newlib(L, syslib);
   return 1;
 }
 

+ 1 - 1
lua/src/lstrlib.c

@@ -2015,7 +2015,7 @@ static void createmetatable (lua_State *L) {
 ** Open string library
 */
 LUAMOD_API int luaopen_string (lua_State *L) {
-  rotable_newlib(L, strlib);
+  luat_newlib(L, strlib);
   createmetatable(L);
   return 1;
 }

+ 1 - 1
luat/modules/luat_lib_adc.c

@@ -83,6 +83,6 @@ static const rotable_Reg reg_adc[] =
 };
 
 LUAMOD_API int luaopen_adc( lua_State *L ) {
-    rotable_newlib(L, reg_adc);
+    luat_newlib(L, reg_adc);
     return 1;
 }

+ 1 - 1
luat/modules/luat_lib_crypto.c

@@ -359,7 +359,7 @@ static const rotable_Reg reg_crypto[] =
 };
 
 LUAMOD_API int luaopen_crypto( lua_State *L ) {
-    rotable_newlib(L, reg_crypto);
+    luat_newlib(L, reg_crypto);
     return 1;
 }
 

+ 1 - 1
luat/modules/luat_lib_ctiot.c

@@ -448,6 +448,6 @@ static const rotable_Reg reg_ctiot[] =
 };
 
 LUAMOD_API int luaopen_ctiot( lua_State *L ) {
-    rotable_newlib(L, reg_ctiot);
+    luat_newlib(L, reg_ctiot);
     return 1;
 }

+ 1 - 1
luat/modules/luat_lib_dbg.c

@@ -340,7 +340,7 @@ static const rotable_Reg reg_dbg[] =
 };
 
 LUAMOD_API int luaopen_dbg( lua_State *L ) {
-    rotable_newlib(L, reg_dbg);
+    luat_newlib(L, reg_dbg);
     return 1;
 }
 

+ 1 - 1
luat/modules/luat_lib_fs.c

@@ -102,6 +102,6 @@ static const rotable_Reg reg_fs[] =
 };
 
 LUAMOD_API int luaopen_fs( lua_State *L ) {
-    rotable_newlib(L, reg_fs);
+    luat_newlib(L, reg_fs);
     return 1;
 }

+ 1 - 1
luat/modules/luat_lib_gpio.c

@@ -233,7 +233,7 @@ static const rotable_Reg reg_gpio[] =
 };
 
 LUAMOD_API int luaopen_gpio( lua_State *L ) {
-    rotable_newlib(L, reg_gpio);
+    luat_newlib(L, reg_gpio);
     return 1;
 }
 

+ 1 - 1
luat/modules/luat_lib_http.c

@@ -286,7 +286,7 @@ static const rotable_Reg reg_http[] =
 };
 
 LUAMOD_API int luaopen_http( lua_State *L ) {
-    rotable_newlib(L, reg_http);
+    luat_newlib(L, reg_http);
     return 1;
 }
 

+ 1 - 1
luat/modules/luat_lib_i2c.c

@@ -327,6 +327,6 @@ static const rotable_Reg reg_i2c[] =
 };
 
 LUAMOD_API int luaopen_i2c( lua_State *L ) {
-    rotable_newlib(L, reg_i2c);
+    luat_newlib(L, reg_i2c);
     return 1;
 }

+ 1 - 1
luat/modules/luat_lib_libcoap.c

@@ -500,7 +500,7 @@ static const rotable_Reg reg_libcoap[] =
 };
 
 LUAMOD_API int luaopen_libcoap( lua_State *L ) {
-    rotable_newlib(L, reg_libcoap);
+    luat_newlib(L, reg_libcoap);
     createmeta(L);
     return 1;
 }

+ 1 - 1
luat/modules/luat_lib_log.c

@@ -168,6 +168,6 @@ static const rotable_Reg reg_log[] =
 };
 
 LUAMOD_API int luaopen_log( lua_State *L ) {
-    rotable_newlib(L, reg_log);
+    luat_newlib(L, reg_log);
     return 1;
 }

+ 1 - 1
luat/modules/luat_lib_lpmem.c

@@ -84,6 +84,6 @@ static const rotable_Reg reg_lpmem[] =
 };
 
 LUAMOD_API int luaopen_lpmem( lua_State *L ) {
-    rotable_newlib(L, reg_lpmem);
+    luat_newlib(L, reg_lpmem);
     return 1;
 }

+ 1 - 1
luat/modules/luat_lib_mqttcore.c

@@ -509,6 +509,6 @@ static const rotable_Reg reg_mqttcore[] =
 };
 
 LUAMOD_API int luaopen_mqttcore( lua_State *L ) {
-    rotable_newlib(L, reg_mqttcore);
+    luat_newlib(L, reg_mqttcore);
     return 1;
 }

+ 1 - 1
luat/modules/luat_lib_pack.c

@@ -289,6 +289,6 @@ static const rotable_Reg reg_pack[] =
 };
 
 LUAMOD_API int luaopen_pack( lua_State *L ) {
-    rotable_newlib(L, reg_pack);
+    luat_newlib(L, reg_pack);
     return 1;
 }

+ 1 - 1
luat/modules/luat_lib_pm.c

@@ -245,6 +245,6 @@ static const rotable_Reg reg_pm[] =
 };
 
 LUAMOD_API int luaopen_pm( lua_State *L ) {
-    rotable_newlib(L, reg_pm);
+    luat_newlib(L, reg_pm);
     return 1;
 }

+ 1 - 1
luat/modules/luat_lib_pwm.c

@@ -54,6 +54,6 @@ static const rotable_Reg reg_pwm[] =
 };
 
 LUAMOD_API int luaopen_pwm( lua_State *L ) {
-    rotable_newlib(L, reg_pwm);
+    luat_newlib(L, reg_pwm);
     return 1;
 }

+ 1 - 1
luat/modules/luat_lib_rtos.c

@@ -258,7 +258,7 @@ static const rotable_Reg reg_rtos[] =
 };
 
 LUAMOD_API int luaopen_rtos( lua_State *L ) {
-    rotable_newlib(L, reg_rtos);
+    luat_newlib(L, reg_rtos);
     return 1;
 }
 

+ 1 - 1
luat/modules/luat_lib_sensor.c

@@ -332,6 +332,6 @@ static const rotable_Reg reg_sensor[] =
 };
 
 LUAMOD_API int luaopen_sensor( lua_State *L ) {
-    rotable_newlib(L, reg_sensor);
+    luat_newlib(L, reg_sensor);
     return 1;
 }

+ 1 - 1
luat/modules/luat_lib_socket.c

@@ -566,7 +566,7 @@ static const rotable_Reg reg_socket[] =
 };
 
 LUAMOD_API int luaopen_socket( lua_State *L ) {
-    rotable_newlib(L, reg_socket);
+    luat_newlib(L, reg_socket);
     createmeta(L);
     return 1;
 }

+ 1 - 1
luat/modules/luat_lib_spi.c

@@ -145,6 +145,6 @@ static const rotable_Reg reg_spi[] =
 };
 
 LUAMOD_API int luaopen_spi( lua_State *L ) {
-    rotable_newlib(L, reg_spi);
+    luat_newlib(L, reg_spi);
     return 1;
 }

+ 1 - 1
luat/modules/luat_lib_timer.c

@@ -37,6 +37,6 @@ static const rotable_Reg reg_timer[] =
 };
 
 LUAMOD_API int luaopen_timer( lua_State *L ) {
-    rotable_newlib(L, reg_timer);
+    luat_newlib(L, reg_timer);
     return 1;
 }

+ 1 - 1
luat/modules/luat_lib_uart.c

@@ -244,6 +244,6 @@ static const rotable_Reg reg_uart[] =
 
 LUAMOD_API int luaopen_uart(lua_State *L)
 {
-    rotable_newlib(L, reg_uart);
+    luat_newlib(L, reg_uart);
     return 1;
 }

+ 1 - 1
luat/modules/luat_lib_zbuff.c

@@ -632,7 +632,7 @@ static const rotable_Reg reg_zbuff[] =
 
 LUAMOD_API int luaopen_zbuff(lua_State *L)
 {
-    rotable_newlib(L, reg_zbuff);
+    luat_newlib(L, reg_zbuff);
     createmeta(L);
     return 1;
 }

+ 23 - 0
luat/modules/luat_main.c

@@ -239,3 +239,26 @@ _exit:
   // 往下是肯定不会被执行的
   return (result && status == LUA_OK) ? 0 : 2;
 }
+
+#include "rotable.h"
+void luat_newlib(lua_State* l, const rotable_Reg* reg) {
+  #ifdef LUAT_CONF_DISABLE_ROTABLE
+  luaL_newlibtable(l,reg);
+  int i;
+  int nup = 0;
+
+  luaL_checkstack(l, nup, "too many upvalues");
+  for (; reg->name != NULL; reg++) {  /* fill the table with given functions */
+        for (i = 0; i < nup; i++)  /* copy upvalues to the top */
+            lua_pushvalue(l, -nup);
+        if (reg->func)
+            lua_pushcclosure(l, reg->func, nup);  /* closure with those upvalues */
+        else
+            lua_pushinteger(l, reg->value);
+        lua_setfield(l, -(nup + 2), reg->name);
+    }
+    lua_pop(l, nup);  /* remove upvalues */
+  #else
+  rotable_newlib(L, reg);
+  #endif
+}

+ 1 - 1
luat/modules/luat_malloc_weak.c

@@ -39,7 +39,7 @@ LUAT_WEAK void* luat_heap_calloc(size_t count, size_t _size) {
 //------------------------------------------------
 // ---------- 管理 LuaVM所使用的内存----------------
 LUAT_WEAK void* luat_heap_alloc(void *ud, void *ptr, size_t osize, size_t nsize) {
-    if (0) {
+    if (1) {
         if (ptr) {
             if (nsize) {
                 // 缩放内存块

+ 1 - 1
luat/packages/eink/luat_lib_eink.c

@@ -624,6 +624,6 @@ static const rotable_Reg reg_eink[] =
 };
 
 LUAMOD_API int luaopen_eink( lua_State *L ){
-    rotable_newlib(L, reg_eink);
+    luat_newlib(L, reg_eink);
     return 1;
 }

+ 1 - 1
luat/packages/fatfs/luat_lib_fatfs.c

@@ -493,6 +493,6 @@ static const rotable_Reg reg_fatfs[] =
 
 int luaopen_fatfs( lua_State *L )
 {
-  rotable_newlib(L, reg_fatfs);
+  luat_newlib(L, reg_fatfs);
   return 1;
 }

+ 1 - 1
luat/packages/lua-cjson/lua_cjson.c

@@ -1749,7 +1749,7 @@ static int lua_cjson_new(lua_State *l)
     // lua_pushliteral(l, CJSON_VERSION);
     // lua_setfield(l, -2, "_VERSION");
 
-    rotable_newlib(l, reg_json);
+    luat_newlib(l, reg_json);
 
     return 1;
 }

+ 1 - 1
luat/packages/minmea/luat_lib_libgnss.c

@@ -522,6 +522,6 @@ static const rotable_Reg reg_libgnss[] =
 };
 
 LUAMOD_API int luaopen_libgnss( lua_State *L ) {
-    rotable_newlib(L, reg_libgnss);
+    luat_newlib(L, reg_libgnss);
     return 1;
 }

+ 1 - 1
luat/rtt/luat_lib_utest.c

@@ -70,6 +70,6 @@ static const rotable_Reg reg_utest[] =
 };
 
 LUAMOD_API int luaopen_utest( lua_State *L ) {
-    rotable_newlib(L, reg_utest);
+    luat_newlib(L, reg_utest);
     return 1;
 }

+ 1 - 1
luat/rtt/luat_lib_wlan.c

@@ -652,7 +652,7 @@ static const rotable_Reg reg_wlan[] =
 
 LUAMOD_API int luaopen_wlan( lua_State *L ) {
     reg_wlan_callbacks();
-    rotable_newlib(L, reg_wlan);
+    luat_newlib(L, reg_wlan);
     return 1;
 }