Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
tg
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
tg
Commits
bc354b96
Commit
bc354b96
authored
Jan 28, 2014
by
vysheng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added mark_read to lua functions
parent
fd4780b8
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
60 additions
and
0 deletions
+60
-0
lua-tg.c
lua-tg.c
+44
-0
tools.c
tools.c
+15
-0
tools.h
tools.h
+1
-0
No files found.
lua-tg.c
View file @
bc354b96
...
...
@@ -365,6 +365,13 @@ void lua_do_all (void) {
do_forward_message
(((
peer_t
*
)
lua_ptr
[
p
])
->
id
,
(
long
)
lua_ptr
[
p
+
1
]);
p
+=
2
;
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:
assert
(
0
);
}
...
...
@@ -384,6 +391,10 @@ static int send_msg_from_lua (lua_State *L) {
return
1
;
}
const
char
*
s
=
lua_tostring
(
L
,
-
2
);
if
(
!
s
)
{
lua_pushboolean
(
L
,
0
);
return
1
;
}
const
char
*
msg
=
lua_tostring
(
L
,
-
1
);
peer_t
*
P
=
get_peer
(
s
);
...
...
@@ -414,6 +425,10 @@ static int fwd_msg_from_lua (lua_State *L) {
}
const
char
*
s
=
lua_tostring
(
L
,
-
2
);
long
long
num
=
atoll
(
lua_tostring
(
L
,
-
1
));
if
(
!
s
)
{
lua_pushboolean
(
L
,
0
);
return
1
;
}
peer_t
*
P
=
get_peer
(
s
);
if
(
!
P
)
{
lua_pushboolean
(
L
,
0
);
...
...
@@ -428,6 +443,34 @@ static int fwd_msg_from_lua (lua_State *L) {
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
)
{
if
(
!
file
)
{
return
;
}
have_file
=
1
;
...
...
@@ -436,6 +479,7 @@ void lua_init (const char *file) {
lua_register
(
luaState
,
"send_msg"
,
send_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
);
if
(
ret
)
{
...
...
tools.c
View file @
bc354b96
...
...
@@ -245,4 +245,19 @@ void tcheck (void) {
}
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
tools.h
View file @
bc354b96
...
...
@@ -39,5 +39,6 @@ int tasprintf (char **res, const char *format, ...) __attribute__ ((format (prin
#ifdef DEBUG
void
tcheck
(
void
);
void
texists
(
void
*
ptr
,
int
size
);
#endif
#endif
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment