luat_msh_rtt.c 839 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #include "luat_base.h"
  2. #include "luat_malloc.h"
  3. #include "luat_msgbus.h"
  4. #include "luat_timer.h"
  5. #include "luat_gpio.h"
  6. #define LUAT_LOG_TAG "luat.msh"
  7. #include "luat_log.h"
  8. #include "rtthread.h"
  9. #include <rtdevice.h>
  10. #ifdef FINSH_USING_MSH
  11. extern lua_State *L;
  12. static int msgbus_handler(lua_State *L, void* ptr) {
  13. int re = luaL_dostring(L, (const char*)ptr);
  14. if (re) {
  15. LLOGE("luaL_dostring return re != 0\n");
  16. LLOGE(lua_tostring(L, -1));
  17. }
  18. luat_heap_free(ptr);
  19. return 0;
  20. }
  21. static void loadstr(int argc, char**argv) {
  22. if (argc < 2)
  23. return;
  24. char* buff = luat_heap_malloc(strlen(argv[1])+1);
  25. strcpy(buff, argv[1]);
  26. rtos_msg_t msg;
  27. msg.handler = msgbus_handler;
  28. msg.ptr = buff;
  29. luat_msgbus_put(&msg, 0);
  30. };
  31. MSH_CMD_EXPORT(loadstr , run lua code);
  32. #endif