Commit bc354b96 authored by vysheng's avatar vysheng

Added mark_read to lua functions

parent fd4780b8
...@@ -365,6 +365,13 @@ void lua_do_all (void) { ...@@ -365,6 +365,13 @@ void lua_do_all (void) {
do_forward_message (((peer_t *)lua_ptr[p])->id, (long)lua_ptr[p + 1]); do_forward_message (((peer_t *)lua_ptr[p])->id, (long)lua_ptr[p + 1]);
p += 2; p += 2;
break; break;
case 2:
#ifdef DEBUG
texists (lua_ptr[p], sizeof (peer_t));
#endif
do_mark_read (((peer_t *)lua_ptr[p])->id);
p += 1;
break;
default: default:
assert (0); assert (0);
} }
...@@ -384,6 +391,10 @@ static int send_msg_from_lua (lua_State *L) { ...@@ -384,6 +391,10 @@ static int send_msg_from_lua (lua_State *L) {
return 1; return 1;
} }
const char *s = lua_tostring (L, -2); const char *s = lua_tostring (L, -2);
if (!s) {
lua_pushboolean (L, 0);
return 1;
}
const char *msg = lua_tostring (L, -1); const char *msg = lua_tostring (L, -1);
peer_t *P = get_peer (s); peer_t *P = get_peer (s);
...@@ -414,6 +425,10 @@ static int fwd_msg_from_lua (lua_State *L) { ...@@ -414,6 +425,10 @@ static int fwd_msg_from_lua (lua_State *L) {
} }
const char *s = lua_tostring (L, -2); const char *s = lua_tostring (L, -2);
long long num = atoll (lua_tostring (L, -1)); long long num = atoll (lua_tostring (L, -1));
if (!s) {
lua_pushboolean (L, 0);
return 1;
}
peer_t *P = get_peer (s); peer_t *P = get_peer (s);
if (!P) { if (!P) {
lua_pushboolean (L, 0); lua_pushboolean (L, 0);
...@@ -428,6 +443,34 @@ static int fwd_msg_from_lua (lua_State *L) { ...@@ -428,6 +443,34 @@ static int fwd_msg_from_lua (lua_State *L) {
return 1; return 1;
} }
static int mark_read_from_lua (lua_State *L) {
if (MAX_LUA_COMMANDS - pos < 4) {
lua_pushboolean (L, 0);
return 1;
}
int n = lua_gettop (L);
if (n != 1) {
lua_pushboolean (L, 0);
return 1;
}
const char *s = lua_tostring (L, -1);
if (!s) {
lua_pushboolean (L, 0);
return 1;
}
peer_t *P = get_peer (s);
if (!P) {
lua_pushboolean (L, 0);
return 1;
}
lua_ptr[pos ++] = (void *)1l;
lua_ptr[pos ++] = (void *)2l;
lua_ptr[pos ++] = P;
lua_pushboolean (L, 1);
return 1;
}
void lua_init (const char *file) { void lua_init (const char *file) {
if (!file) { return; } if (!file) { return; }
have_file = 1; have_file = 1;
...@@ -436,6 +479,7 @@ void lua_init (const char *file) { ...@@ -436,6 +479,7 @@ void lua_init (const char *file) {
lua_register (luaState, "send_msg", send_msg_from_lua); lua_register (luaState, "send_msg", send_msg_from_lua);
lua_register (luaState, "fwd_msg", fwd_msg_from_lua); lua_register (luaState, "fwd_msg", fwd_msg_from_lua);
lua_register (luaState, "mark_read", mark_read_from_lua);
int ret = luaL_dofile (luaState, file); int ret = luaL_dofile (luaState, file);
if (ret) { if (ret) {
......
...@@ -245,4 +245,19 @@ void tcheck (void) { ...@@ -245,4 +245,19 @@ void tcheck (void) {
} }
logprintf ("ok. Used_blocks = %d. Free blocks = %d\n", used_blocks, free_blocks_cnt); logprintf ("ok. Used_blocks = %d. Free blocks = %d\n", used_blocks, free_blocks_cnt);
} }
void texists (void *ptr, int size) {
ptr -= RES_PRE;
if (size != (int)((*(int *)ptr) ^ 0xbedabeda)) {
logprintf ("size = %d, ptr = %d\n", size, (*(int *)ptr) ^ 0xbedabeda);
}
assert (*(int *)ptr == (int)((size) ^ 0xbedabeda));
assert (*(int *)(ptr + RES_PRE + size) == (int)((size) ^ 0x7bed7bed));
assert (*(int *)(ptr + 4) == size);
int block_num = *(int *)(ptr + 4 + RES_PRE + size);
if (block_num >= used_blocks) {
logprintf ("block_num = %d, used = %d\n", block_num, used_blocks);
}
assert (block_num < used_blocks);
}
#endif #endif
...@@ -39,5 +39,6 @@ int tasprintf (char **res, const char *format, ...) __attribute__ ((format (prin ...@@ -39,5 +39,6 @@ int tasprintf (char **res, const char *format, ...) __attribute__ ((format (prin
#ifdef DEBUG #ifdef DEBUG
void tcheck (void); void tcheck (void);
void texists (void *ptr, int size);
#endif #endif
#endif #endif
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