From 2da61079deea2fb809f1875a5b3ee93e89888b0b Mon Sep 17 00:00:00 2001 From: Howland Owl Date: Tue, 25 Apr 2017 23:45:13 +0300 Subject: [PATCH] some debug for lua that got me to where I don't think I need lua. - thanks to debugging and seeing variables internally --- color.lua | 4 ++-- st.c | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/color.lua b/color.lua index 9a6bf33..fe0be67 100644 --- a/color.lua +++ b/color.lua @@ -1,9 +1,9 @@ -- Lua test file function ithecolors( c ) - a = 5 - b = 7 io.write("some shit from lua\n") +-- io.write(c) + io.write("\n") end ithecolors() diff --git a/st.c b/st.c index 63ba573..e7592af 100644 --- a/st.c +++ b/st.c @@ -589,6 +589,11 @@ int dothatLua(void) { luaL_openlibs(L); /* Load Lua libraries */ if (luaL_loadfile(L, "color.lua")) /* Load but don't run the Lua script */ bail(L, "luaL_loadfile() failed"); /* Error out if file can't be read */ + + // for (int i = 0; i < sizeof(colorname); ++i) { + // lua_pushstring(L,colorname[i]); + // } + printf("In C, calling Lua\n"); if (lua_pcall(L, 0, 0, 0)) /* Run the loaded Lua script */ bail(L, "lua_pcall() failed"); /* Error out if Lua file has an error */ @@ -597,6 +602,24 @@ int dothatLua(void) { return 0; } +int luaInterpreter(void) { + char buff[256]; + int error; + lua_State *L = luaL_newstate(); /* opens Lua */ + luaL_openlibs(L); /* opens the standard libraries */ + + while (fgets(buff, sizeof(buff), stdin) != NULL) { + error = luaL_loadstring(L, buff) || lua_pcall(L, 0, 0, 0); + if (error) { + fprintf(stderr, "%s\n", lua_tostring(L, -1)); + lua_pop(L, 1); /* pop error message from the stack */ + } + } + + lua_close(L); + return 0; +} + ssize_t xwrite(int fd, const char *s, size_t len) @@ -4529,6 +4552,7 @@ run: opt_title = basename(xstrdup(argv[0])); } dothatLua(); +// luaInterpreter(); setlocale(LC_CTYPE, ""); XSetLocaleModifiers(""); tnew(MAX(cols, 1), MAX(rows, 1));