Skip to content

Commit

Permalink
2021-02-27 19:45:03 CST W08D6
Browse files Browse the repository at this point in the history
  • Loading branch information
aggresss committed Feb 27, 2021
1 parent cbb131f commit c9178ca
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
29 changes: 29 additions & 0 deletions library/lua_test/src/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Makefile for lua_test
CC = gcc
CXX = g++
CFLAGS = -g
CXXFLAGS = -g -std=c++14
OBJS = $(patsubst %c, %o, $(wildcard *.c))
OBJS += $(patsubst %cpp, %o, $(wildcard *.cpp))
HEADER = $(wildcard ../include/*.h)
BINS = $(OBJS:%.o=%.out)
PATH_LIBLUA = $(shell cd ../lib && pwd)/lua/prefix
CFLAGS += -I$(PATH_LIBLUA)/include
CXXFLAGS += -I$(PATH_LIBLUA)/include
LDFLAGS += -L$(PATH_LIBLUA)/lib -llua

.PHONY: all
all: $(BINS)

.PHONY: clean
clean:
rm -rf $(OBJS) $(DEPS) $(Target)

$(BINS):$(OBJS)
$(CC) -o $@ $< $(LDFLAGS)

%.o:%.cpp $(HEADER)
$(CXX) $(CXXFLAGS) -c $< -o $@

%.o:%.c $(HEADER)
$(CC) $(CFLAGS) -c $< -o $@
22 changes: 22 additions & 0 deletions library/lua_test/src/lua_inter.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include <stdio.h>
#include <string.h>

#include "lauxlib.h"
#include "lua.h"
#include "lualib.h"

int main(void) {
char buff[256];
int error;
lua_State *L = luaL_newstate();
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;
}
6 changes: 6 additions & 0 deletions library/lua_test/src/lua_test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <stdio.h>

int main() {
printf("Hello, World!\n");
return 0;
}

0 comments on commit c9178ca

Please sign in to comment.