lua_action.c 606 B

1234567891011121314151617181920212223242526272829
  1. #include <lub/string.h>
  2. #include "private.h"
  3. CLISH_PLUGIN_SYM(clish_plugin_lua_action)
  4. {
  5. clish_context_t *context = (clish_context_t *) clish_context;
  6. lua_State *L = clish_shell__get_udata(context->shell, LUA_UDATA);
  7. int res = 0, result = -1;
  8. if (!script) /* Nothing to do */
  9. return (0);
  10. if (out)
  11. *out = NULL; /* Does not work for now */
  12. if ((res = luaL_loadstring(L, script))) {
  13. l_print_error(L, __func__, "load", res);
  14. } else if ((res = lua_pcall(L, 0, 0, 0))) {
  15. l_print_error(L, __func__, "exec", res);
  16. } else {
  17. result = 0;
  18. }
  19. lua_gc(L, LUA_GCCOLLECT, 0);
  20. return (result);
  21. }