Commit eaa0e26a authored by Sergey Lyubka's avatar Sergey Lyubka

Starting to rebuild chat example on Lua

parent a3a63f7e
CFLAGS = -W -Wall -I.. -pthread -g -pipe $(CFLAGS_EXTRA) CFLAGS = -W -Wall -I.. -pthread -g -pipe $(CFLAGS_EXTRA)
DLL_FLAGS = -DLUA_COMPAT_ALL -I../build DLL_FLAGS = -DLUA_COMPAT_ALL -I../build
RM = rm -rf RM = rm -rf
MSVC = ../../vc6
CL = $(MSVC)/bin/cl
CLFLAGS = /MD /TC /nologo $(CFLAGS_EXTRA) /W3 \
/I$(MSVC)/include /I.. /Dsnprintf=_snprintf
LFLAGS = /link /incremental:no /libpath:$(MSVC)/lib /machine:IX86
LUA_FLAGS = -I/usr/local/include -L/usr/local/lib -llua
ifeq ($(OS),Windows_NT) ifeq ($(OS),Windows_NT)
RM = del /q /f RM = del /q /f
CC = $(MSVC)/bin/cl $(CLFLAGS)
else else
UNAME_S := $(shell uname -s) UNAME_S := $(shell uname -s)
DLL_FLAGS += -shared DLL_FLAGS += -shared
...@@ -27,18 +35,15 @@ all: websocket_html.c ...@@ -27,18 +35,15 @@ all: websocket_html.c
$(CC) auth.c ../mongoose.c -o auth $(CFLAGS) $(CC) auth.c ../mongoose.c -o auth $(CFLAGS)
$(CC) server.c ../mongoose.c -o server $(CFLAGS) $(CC) server.c ../mongoose.c -o server $(CFLAGS)
chat$(EXE_SUFFIX): chat.c
$(CC) chat.c ../mongoose.c -DMONGOOSE_USE_LUA -o $@ $(CFLAGS) $(LUA_FLAGS)
# $(CC) chat.c ../mongoose.c -o chat $(CFLAGS) # $(CC) chat.c ../mongoose.c -o chat $(CFLAGS)
# $(CC) lua_dll.c ../build/lua_5.2.1.c -o $@.so $(CFLAGS) $(DLL_FLAGS) # $(CC) lua_dll.c ../build/lua_5.2.1.c -o $@.so $(CFLAGS) $(DLL_FLAGS)
websocket_html.c: websocket.html websocket_html.c: websocket.html
perl mkdata.pl $< > $@ perl mkdata.pl $< > $@
MSVC = ../../vc6
CL = $(MSVC)/bin/cl
CLFLAGS = /MD /TC /nologo $(DBG) /W3 \
/I$(MSVC)/include /I.. /Dsnprintf=_snprintf
LFLAGS = /link /incremental:no /libpath:$(MSVC)/lib /machine:IX86
windows: websocket_html.c windows: websocket_html.c
$(CL) hello.c ../mongoose.c $(CLFLAGS) $(LFLAGS) $(CL) hello.c ../mongoose.c $(CLFLAGS) $(LFLAGS)
$(CL) websocket.c websocket_html.c ../mongoose.c $(CLFLAGS) $(LFLAGS) $(CL) websocket.c websocket_html.c ../mongoose.c $(CLFLAGS) $(LFLAGS)
......
This diff is collapsed.
...@@ -3290,7 +3290,9 @@ static void prepare_lua_environment(struct mg_connection *ri, lua_State *L) { ...@@ -3290,7 +3290,9 @@ static void prepare_lua_environment(struct mg_connection *ri, lua_State *L) {
luaL_newmetatable(L, "luasocket"); luaL_newmetatable(L, "luasocket");
lua_pushliteral(L, "__index"); lua_pushliteral(L, "__index");
luaL_newlib(L, luasocket_methods); lua_newtable(L);
luaL_register(L, NULL, luasocket_methods);
//luaL_newlib(L, luasocket_methods);
lua_rawset(L, -3); lua_rawset(L, -3);
lua_pop(L, 1); lua_pop(L, 1);
lua_register(L, "connect", lsp_connect); lua_register(L, "connect", lsp_connect);
...@@ -3357,7 +3359,7 @@ static void lsp(struct connection *conn, const char *p, int len, lua_State *L) { ...@@ -3357,7 +3359,7 @@ static void lsp(struct connection *conn, const char *p, int len, lua_State *L) {
for (j = i + 1; j < len ; j++) { for (j = i + 1; j < len ; j++) {
if (p[j] == '?' && p[j + 1] == '>') { if (p[j] == '?' && p[j + 1] == '>') {
mg_write(&conn->mg_conn, p + pos, i - pos); mg_write(&conn->mg_conn, p + pos, i - pos);
if (luaL_loadbuffer(L, p + (i + 2), j - (i + 2), "") == LUA_OK) { if (luaL_loadbuffer(L, p + (i + 2), j - (i + 2), "") == 0) {
lua_pcall(L, 0, LUA_MULTRET, 0); lua_pcall(L, 0, LUA_MULTRET, 0);
} }
pos = j + 2; pos = j + 2;
...@@ -3385,7 +3387,7 @@ static void handle_lsp_request(struct connection *conn, const char *path, ...@@ -3385,7 +3387,7 @@ static void handle_lsp_request(struct connection *conn, const char *path,
// We're not sending HTTP headers here, Lua page must do it. // We're not sending HTTP headers here, Lua page must do it.
prepare_lua_environment(&conn->mg_conn, L); prepare_lua_environment(&conn->mg_conn, L);
lua_pushcclosure(L, &lua_error_handler, 0); lua_pushcclosure(L, &lua_error_handler, 0);
lua_pushglobaltable(L); lua_pushvalue(L, LUA_GLOBALSINDEX);
lsp(conn, p, (int) st->st_size, L); lsp(conn, p, (int) st->st_size, L);
close_local_endpoint(conn); close_local_endpoint(conn);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment