Skip to content

Commit 8baa986

Browse files
making working on windows
1 parent 28ceb5f commit 8baa986

File tree

4 files changed

+41
-10
lines changed

4 files changed

+41
-10
lines changed

main.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,8 @@
44
LuaCEmbedNamespace lua_n;
55

66

7-
LuaCEmbedNamespace lua_n;
8-
9-
107
LuaCEmbedResponse * hello(LuaCEmbed *args){
11-
printf("hello world\n");
8+
printf("hello world funcionou");
129
return NULL;
1310
}
1411

@@ -18,7 +15,7 @@ int main(int argc, char *argv[]){
1815
LuaCEmbed * l = lua_n.newLuaEvaluation();
1916
lua_n.add_callback(l,"hello",hello);
2017

21-
lua_n.evaluete_file(l,"tests/target/hello.lua");
18+
lua_n.evaluate(l,"hello()");
2219

2320
if(lua_n.has_errors(l)){
2421
printf("error: %s\n",lua_n.get_error_message(l));

src/LuaCEmbed/evaluation/evaluation.c

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,43 @@
11

2+
3+
#ifdef _WIN32
4+
VOID CALLBACK TimerHandler(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime) {
5+
6+
privateLuaCEmbed_raise_error_not_jumping(global_current_lua_embed_object, PRIVATE_LUA_CEMBED_TIMEOUT_ERROR);
7+
lua_pushstring(global_current_lua_embed_object->state,PRIVVATE_LUA_CEMBED_TIMEOUT_ERROR);
8+
lua_error(global_current_lua_embed_object->state);
9+
}
10+
11+
#else
12+
213
void private_LuaCembed_handle_timeout(int signum) {
314

415
privateLuaCEmbed_raise_error_not_jumping(global_current_lua_embed_object, PRIVATE_LUA_CEMBED_TIMEOUT_ERROR);
516
lua_pushstring(global_current_lua_embed_object->state,PRIVVATE_LUA_CEMBED_TIMEOUT_ERROR);
617
lua_error(global_current_lua_embed_object->state);
718
}
819

20+
#endif
21+
22+
23+
924
int privateLuaCEmbed_start_func_evaluation(lua_State *state){
1025

1126
int evaluation_type = lua_tointeger(state, lua_upvalueindex(1));
1227
char *text_value = (char*)lua_touserdata(state,lua_upvalueindex(2));
1328
LuaCEmbed *self = (LuaCEmbed*)lua_touserdata(state,lua_upvalueindex(3));
1429
global_current_lua_embed_object = self;
15-
if(self->timeout){
16-
signal(SIGALRM, private_LuaCembed_handle_timeout);
17-
alarm(self->timeout);
18-
}
30+
#ifdef _WIN32
31+
if (self->timeout > 0) {
32+
SetTimer(NULL, 0, self->timeout * 1000, TimerHandler);
33+
}
34+
#else
35+
if (self->timeout > 0) {
36+
signal(SIGALRM, private_LuaCembed_handle_timeout);
37+
alarm(self->timeout);
38+
}
39+
#endif
40+
1941
int error = 0;
2042
if(evaluation_type == PRIVATE_LUA_EMBED_FILE_EVALUATION_TYPE){
2143
error =luaL_dofile(self->state,text_value);

src/LuaCEmbed/evaluation/evaluation.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11

22

3-
void private_LuaCembed_handle_timeout(int signum) ;
3+
#ifdef _WIN32
4+
VOID CALLBACK TimerHandler(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime);
5+
#else
6+
7+
void private_LuaCembed_handle_timeout(int signum);
8+
9+
#endif
410

511
int privateLuaCEmbed_start_func_evaluation(lua_State *state);
612

src/declaration.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
#ifdef _WIN32
2+
#include <windows.h>
3+
#else
4+
#include <signal.h>
5+
#include <unistd.h>
6+
#endif
17

28
#include <setjmp.h>
39
#include <signal.h>

0 commit comments

Comments
 (0)