Compare commits

...
Sign in to create a new pull request.

5 commits

Author SHA1 Message Date
Howland Owl
2da61079de some debug for lua that got me to where I don't think I need lua.
- thanks to debugging and seeing variables internally
2017-04-25 23:45:13 +03:00
Howland Owl
f164ada948 call the lua stuff. 2017-04-25 22:51:32 +03:00
Howland Owl
ca58921e2e a simple test lua file. doesn't do anything useful yet. 2017-04-25 22:51:22 +03:00
Howland Owl
e09862023e lua chunks. mainly from troubleshooters.com
- and for now is just test shit.
2017-04-25 22:41:26 +03:00
Howland Owl
405178f89e add lua for linking; compile with clang
- works with gcc but fuck gcc
2017-04-25 22:41:05 +03:00
3 changed files with 1953 additions and 1888 deletions

9
color.lua Normal file
View file

@ -0,0 +1,9 @@
-- Lua test file
function ithecolors( c )
io.write("some shit from lua\n")
-- io.write(c)
io.write("\n")
end
ithecolors()

View file

@ -14,7 +14,7 @@ X11LIB = /usr/X11R6/lib
INCS = -I. -I/usr/include -I${X11INC} \
`pkg-config --cflags fontconfig` \
`pkg-config --cflags freetype2`
LIBS = -L/usr/lib -lc -L${X11LIB} -lm -lrt -lX11 -lutil -lXext -lXft -lXrender\
LIBS = -L/usr/lib -lc -L${X11LIB} -lm -lrt -lX11 -lutil -lXext -lXft -lXrender -llua\
`pkg-config --libs fontconfig` \
`pkg-config --libs freetype2`
@ -26,3 +26,4 @@ LDFLAGS += -g ${LIBS}
# compiler and linker
# CC = cc
CC=clang

91
st.c
View file

@ -31,6 +31,11 @@
#include <fontconfig/fontconfig.h>
#include <wchar.h>
// lua stuff
#include <lua.h>
#include <lauxlib.h>
#include <lualib.h>
#include "arg.h"
char *argv0;
@ -337,9 +342,9 @@ static void selpaste(const Arg *);
static void xzoom(const Arg *);
static void xzoomabs(const Arg *);
static void xzoomreset(const Arg *);
static void printsel(const Arg *);
static void printscreen(const Arg *) ;
static void toggleprinter(const Arg *);
/* static void printsel(const Arg *); */
/* static void printscreen(const Arg *) ; */
/* static void toggleprinter(const Arg *); */
static void sendbreak(const Arg *);
/* Config.h for applying patches and the configuration. */
@ -568,6 +573,54 @@ typedef struct {
static Fontcache frc[16];
static int frclen = 0;
/* I think code starts here. Well, I'm starting mine here.
*/
void bail(lua_State *L, char *msg){
fprintf(stderr, "\nFATAL ERROR:\n %s: %s\n\n",
msg, lua_tostring(L, -1));
exit(1);
}
int dothatLua(void) {
lua_State *L;
L = luaL_newstate(); /* Create Lua state variable */
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 */
printf("Back in C again\n");
lua_close(L); /* Clean up, free the Lua state var */
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)
{
@ -2611,23 +2664,23 @@ tprinter(char *s, size_t len)
}
}
void
toggleprinter(const Arg *arg)
{
term.mode ^= MODE_PRINT;
}
/* void */
/* toggleprinter(const Arg *arg) */
/* { */
/* term.mode ^= MODE_PRINT; */
/* } */
void
printscreen(const Arg *arg)
{
tdump();
}
/* void */
/* printscreen(const Arg *arg) */
/* { */
/* tdump(); */
/* } */
void
printsel(const Arg *arg)
{
tdumpsel();
}
/* void */
/* printsel(const Arg *arg) */
/* { */
/* tdumpsel(); */
/* } */
void
tdumpsel(void)
@ -4498,6 +4551,8 @@ run:
if (!opt_title && !opt_line)
opt_title = basename(xstrdup(argv[0]));
}
dothatLua();
// luaInterpreter();
setlocale(LC_CTYPE, "");
XSetLocaleModifiers("");
tnew(MAX(cols, 1), MAX(rows, 1));