Commit db463be5 authored by Vincent Castellano's avatar Vincent Castellano

Missing changes to python-tg.c

parent b290af88
...@@ -47,1421 +47,1420 @@ extern int verbosity; ...@@ -47,1421 +47,1420 @@ extern int verbosity;
extern struct tgl_state *TLS; extern struct tgl_state *TLS;
static int have_file; static int have_file;
//
#define my_lua_checkstack(L,x) assert (lua_checkstack (L, x)) //void push_user (tgl_peer_t *P);
void push_user (tgl_peer_t *P); //void push_peer (tgl_peer_id_t id, tgl_peer_t *P);
void push_peer (tgl_peer_id_t id, tgl_peer_t *P); //
//void lua_add_string_field (const char *name, const char *value) {
void lua_add_string_field (const char *name, const char *value) { // assert (name && strlen (name));
assert (name && strlen (name)); // if (!value || !strlen (value)) { return; }
if (!value || !strlen (value)) { return; } // my_lua_checkstack (luaState, 3);
my_lua_checkstack (luaState, 3); // lua_pushstring (luaState, name);
lua_pushstring (luaState, name); // lua_pushstring (luaState, value);
lua_pushstring (luaState, value); // lua_settable (luaState, -3);
lua_settable (luaState, -3); //}
} //
//void lua_add_string_field_arr (int num, const char *value) {
void lua_add_string_field_arr (int num, const char *value) { // if (!value || !strlen (value)) { return; }
if (!value || !strlen (value)) { return; } // my_lua_checkstack (luaState, 3);
my_lua_checkstack (luaState, 3); // lua_pushnumber (luaState, num);
lua_pushnumber (luaState, num); // lua_pushstring (luaState, value);
lua_pushstring (luaState, value); // lua_settable (luaState, -3);
lua_settable (luaState, -3); //}
} //
//void lua_add_num_field (const char *name, double value) {
void lua_add_num_field (const char *name, double value) { // assert (name && strlen (name));
assert (name && strlen (name)); // my_lua_checkstack (luaState, 3);
my_lua_checkstack (luaState, 3); // lua_pushstring (luaState, name);
lua_pushstring (luaState, name); // lua_pushnumber (luaState, value);
lua_pushnumber (luaState, value); // lua_settable (luaState, -3);
lua_settable (luaState, -3); //}
} //
//void push_tgl_peer_type (int x) {
void push_tgl_peer_type (int x) { // switch (x) {
switch (x) { // case TGL_PEER_USER:
case TGL_PEER_USER: // lua_pushstring (luaState, "user");
lua_pushstring (luaState, "user"); // break;
break; // case TGL_PEER_CHAT:
case TGL_PEER_CHAT: // lua_pushstring (luaState, "chat");
lua_pushstring (luaState, "chat"); // break;
break; // case TGL_PEER_ENCR_CHAT:
case TGL_PEER_ENCR_CHAT: // lua_pushstring (luaState, "encr_chat");
lua_pushstring (luaState, "encr_chat"); // break;
break; // default:
default: // assert (0);
assert (0); // }
} //}
} //
//void push_user (tgl_peer_t *P) {
void push_user (tgl_peer_t *P) { // my_lua_checkstack (luaState, 4);
my_lua_checkstack (luaState, 4); // lua_add_string_field ("first_name", P->user.first_name);
lua_add_string_field ("first_name", P->user.first_name); // lua_add_string_field ("last_name", P->user.last_name);
lua_add_string_field ("last_name", P->user.last_name); // lua_add_string_field ("real_first_name", P->user.real_first_name);
lua_add_string_field ("real_first_name", P->user.real_first_name); // lua_add_string_field ("real_last_name", P->user.real_last_name);
lua_add_string_field ("real_last_name", P->user.real_last_name); // lua_add_string_field ("phone", P->user.phone);
lua_add_string_field ("phone", P->user.phone); // if (P->user.access_hash) {
if (P->user.access_hash) { // lua_add_num_field ("access_hash", 1);
lua_add_num_field ("access_hash", 1); // }
} //}
} //
//void push_chat (tgl_peer_t *P) {
void push_chat (tgl_peer_t *P) { // my_lua_checkstack (luaState, 4);
my_lua_checkstack (luaState, 4); // assert (P->chat.title);
assert (P->chat.title); // lua_add_string_field ("title", P->chat.title);
lua_add_string_field ("title", P->chat.title); // lua_add_num_field ("members_num", P->chat.users_num);
lua_add_num_field ("members_num", P->chat.users_num); // if (P->chat.user_list) {
if (P->chat.user_list) { // lua_pushstring (luaState, "members");
lua_pushstring (luaState, "members"); // lua_newtable (luaState);
lua_newtable (luaState); // int i;
int i; // for (i = 0; i < P->chat.users_num; i++) {
for (i = 0; i < P->chat.users_num; i++) { // lua_pushnumber (luaState, i);
lua_pushnumber (luaState, i); // tgl_peer_id_t id = TGL_MK_USER (P->chat.user_list[i].user_id);
tgl_peer_id_t id = TGL_MK_USER (P->chat.user_list[i].user_id); // push_peer (id, tgl_peer_get (TLS, id));
push_peer (id, tgl_peer_get (TLS, id)); // lua_settable (luaState, -3);
lua_settable (luaState, -3); // }
} // lua_settable (luaState, -3);
lua_settable (luaState, -3); // }
} //}
} //
//void push_encr_chat (tgl_peer_t *P) {
void push_encr_chat (tgl_peer_t *P) { // my_lua_checkstack (luaState, 4);
my_lua_checkstack (luaState, 4); // lua_pushstring (luaState, "user");
lua_pushstring (luaState, "user"); // push_peer (TGL_MK_USER (P->encr_chat.user_id), tgl_peer_get (TLS, TGL_MK_USER (P->encr_chat.user_id)));
push_peer (TGL_MK_USER (P->encr_chat.user_id), tgl_peer_get (TLS, TGL_MK_USER (P->encr_chat.user_id))); // lua_settable (luaState, -3);
lua_settable (luaState, -3); //}
} //
//void push_update_types (unsigned flags) {
void push_update_types (unsigned flags) { // my_lua_checkstack (luaState, 4);
my_lua_checkstack (luaState, 4); // lua_newtable (luaState);
lua_newtable (luaState); // int cc = 0;
int cc = 0; //
//
// if (flags & TGL_UPDATE_CREATED) {
if (flags & TGL_UPDATE_CREATED) { // lua_add_string_field_arr (cc++, "created");
lua_add_string_field_arr (cc++, "created"); // }
} // if (flags & TGL_UPDATE_DELETED) {
if (flags & TGL_UPDATE_DELETED) { // lua_add_string_field_arr (cc++, "deleted");
lua_add_string_field_arr (cc++, "deleted"); // }
} // if (flags & TGL_UPDATE_PHONE) {
if (flags & TGL_UPDATE_PHONE) { // lua_add_string_field_arr (cc++, "phone");
lua_add_string_field_arr (cc++, "phone"); // }
} // if (flags & TGL_UPDATE_CONTACT) {
if (flags & TGL_UPDATE_CONTACT) { // lua_add_string_field_arr (cc++, "contact");
lua_add_string_field_arr (cc++, "contact"); // }
} // if (flags & TGL_UPDATE_PHOTO) {
if (flags & TGL_UPDATE_PHOTO) { // lua_add_string_field_arr (cc++, "photo");
lua_add_string_field_arr (cc++, "photo"); // }
} // if (flags & TGL_UPDATE_BLOCKED) {
if (flags & TGL_UPDATE_BLOCKED) { // lua_add_string_field_arr (cc++, "blocked");
lua_add_string_field_arr (cc++, "blocked"); // }
} // if (flags & TGL_UPDATE_REAL_NAME) {
if (flags & TGL_UPDATE_REAL_NAME) { // lua_add_string_field_arr (cc++, "real_name");
lua_add_string_field_arr (cc++, "real_name"); // }
} // if (flags & TGL_UPDATE_NAME) {
if (flags & TGL_UPDATE_NAME) { // lua_add_string_field_arr (cc++, "name");
lua_add_string_field_arr (cc++, "name"); // }
} // if (flags & TGL_UPDATE_REQUESTED) {
if (flags & TGL_UPDATE_REQUESTED) { // lua_add_string_field_arr (cc++, "requested");
lua_add_string_field_arr (cc++, "requested"); // }
} // if (flags & TGL_UPDATE_WORKING) {
if (flags & TGL_UPDATE_WORKING) { // lua_add_string_field_arr (cc++, "working");
lua_add_string_field_arr (cc++, "working"); // }
} // if (flags & TGL_UPDATE_FLAGS) {
if (flags & TGL_UPDATE_FLAGS) { // lua_add_string_field_arr (cc++, "flags");
lua_add_string_field_arr (cc++, "flags"); // }
} // if (flags & TGL_UPDATE_TITLE) {
if (flags & TGL_UPDATE_TITLE) { // lua_add_string_field_arr (cc++, "title");
lua_add_string_field_arr (cc++, "title"); // }
} // if (flags & TGL_UPDATE_ADMIN) {
if (flags & TGL_UPDATE_ADMIN) { // lua_add_string_field_arr (cc++, "admin");
lua_add_string_field_arr (cc++, "admin"); // }
} // if (flags & TGL_UPDATE_MEMBERS) {
if (flags & TGL_UPDATE_MEMBERS) { // lua_add_string_field_arr (cc++, "members");
lua_add_string_field_arr (cc++, "members"); // }
} // if (flags & TGL_UPDATE_ACCESS_HASH) {
if (flags & TGL_UPDATE_ACCESS_HASH) { // lua_add_string_field_arr (cc++, "access_hash");
lua_add_string_field_arr (cc++, "access_hash"); // }
} // if (flags & TGL_UPDATE_USERNAME) {
if (flags & TGL_UPDATE_USERNAME) { // lua_add_string_field_arr (cc++, "username");
lua_add_string_field_arr (cc++, "username"); // }
} //
//}
} //
//void push_peer (tgl_peer_id_t id, tgl_peer_t *P) {
void push_peer (tgl_peer_id_t id, tgl_peer_t *P) { // lua_newtable (luaState);
lua_newtable (luaState); //
// lua_add_num_field ("id", tgl_get_peer_id (id));
lua_add_num_field ("id", tgl_get_peer_id (id)); // lua_pushstring (luaState, "type");
lua_pushstring (luaState, "type"); // push_tgl_peer_type (tgl_get_peer_type (id));
push_tgl_peer_type (tgl_get_peer_type (id)); // lua_settable (luaState, -3);
lua_settable (luaState, -3); //
//
// if (!P || !(P->flags & FLAG_CREATED)) {
if (!P || !(P->flags & FLAG_CREATED)) { // lua_pushstring (luaState, "print_name");
lua_pushstring (luaState, "print_name"); // static char s[100];
static char s[100]; // switch (tgl_get_peer_type (id)) {
switch (tgl_get_peer_type (id)) { // case TGL_PEER_USER:
case TGL_PEER_USER: // sprintf (s, "user#%d", tgl_get_peer_id (id));
sprintf (s, "user#%d", tgl_get_peer_id (id)); // break;
break; // case TGL_PEER_CHAT:
case TGL_PEER_CHAT: // sprintf (s, "chat#%d", tgl_get_peer_id (id));
sprintf (s, "chat#%d", tgl_get_peer_id (id)); // break;
break; // case TGL_PEER_ENCR_CHAT:
case TGL_PEER_ENCR_CHAT: // sprintf (s, "encr_chat#%d", tgl_get_peer_id (id));
sprintf (s, "encr_chat#%d", tgl_get_peer_id (id)); // break;
break; // default:
default: // assert (0);
assert (0); // }
} // lua_pushstring (luaState, s);
lua_pushstring (luaState, s); // lua_settable (luaState, -3); // flags
lua_settable (luaState, -3); // flags //
// return;
return; // }
} //
// lua_add_string_field ("print_name", P->print_name);
lua_add_string_field ("print_name", P->print_name); // lua_add_num_field ("flags", P->flags);
lua_add_num_field ("flags", P->flags); //
// switch (tgl_get_peer_type (id)) {
switch (tgl_get_peer_type (id)) { // case TGL_PEER_USER:
case TGL_PEER_USER: // push_user (P);
push_user (P); // break;
break; // case TGL_PEER_CHAT:
case TGL_PEER_CHAT: // push_chat (P);
push_chat (P); // break;
break; // case TGL_PEER_ENCR_CHAT:
case TGL_PEER_ENCR_CHAT: // push_encr_chat (P);
push_encr_chat (P); // break;
break; // default:
default: // assert (0);
assert (0); // }
} //}
} //
//void push_media (struct tgl_message_media *M) {
void push_media (struct tgl_message_media *M) { // my_lua_checkstack (luaState, 4);
my_lua_checkstack (luaState, 4); //
// switch (M->type) {
switch (M->type) { // case tgl_message_media_photo:
case tgl_message_media_photo: // case tgl_message_media_photo_encr:
case tgl_message_media_photo_encr: // lua_newtable (luaState);
lua_newtable (luaState); // lua_add_string_field ("type", "photo");
lua_add_string_field ("type", "photo"); // break;
break; // /*case tgl_message_media_video:
/*case tgl_message_media_video: // case tgl_message_media_video_encr:
case tgl_message_media_video_encr: // lua_newtable (luaState);
lua_newtable (luaState); // lua_add_string_field ("type", "video");
lua_add_string_field ("type", "video"); // break;
break; // case tgl_message_media_audio:
case tgl_message_media_audio: // case tgl_message_media_audio_encr:
case tgl_message_media_audio_encr: // lua_newtable (luaState);
lua_newtable (luaState); // lua_add_string_field ("type", "audio");
lua_add_string_field ("type", "audio"); // break;*/
break;*/ // case tgl_message_media_document:
case tgl_message_media_document: // case tgl_message_media_document_encr:
case tgl_message_media_document_encr: // lua_newtable (luaState);
lua_newtable (luaState); // lua_add_string_field ("type", "document");
lua_add_string_field ("type", "document"); // break;
break; // case tgl_message_media_unsupported:
case tgl_message_media_unsupported: // lua_newtable (luaState);
lua_newtable (luaState); // lua_add_string_field ("type", "unsupported");
lua_add_string_field ("type", "unsupported"); // break;
break; // case tgl_message_media_geo:
case tgl_message_media_geo: // lua_newtable (luaState);
lua_newtable (luaState); // lua_add_string_field ("type", "geo");
lua_add_string_field ("type", "geo"); // lua_add_num_field ("longitude", M->geo.longitude);
lua_add_num_field ("longitude", M->geo.longitude); // lua_add_num_field ("latitude", M->geo.latitude);
lua_add_num_field ("latitude", M->geo.latitude); // break;
break; // case tgl_message_media_contact:
case tgl_message_media_contact: // lua_newtable (luaState);
lua_newtable (luaState); // lua_add_string_field ("type", "contact");
lua_add_string_field ("type", "contact"); // lua_add_string_field ("phone", M->phone);
lua_add_string_field ("phone", M->phone); // lua_add_string_field ("first_name", M->first_name);
lua_add_string_field ("first_name", M->first_name); // lua_add_string_field ("last_name", M->last_name);
lua_add_string_field ("last_name", M->last_name); // lua_add_num_field ("user_id", M->user_id);
lua_add_num_field ("user_id", M->user_id); // break;
break; // default:
default: // lua_pushstring (luaState, "???");
lua_pushstring (luaState, "???"); // }
} //}
} //
//void push_message (struct tgl_message *M) {
void push_message (struct tgl_message *M) { // assert (M);
assert (M); // my_lua_checkstack (luaState, 10);
my_lua_checkstack (luaState, 10); // lua_newtable (luaState);
lua_newtable (luaState); //
// static char s[30];
static char s[30]; // snprintf (s, 30, "%lld", M->id);
snprintf (s, 30, "%lld", M->id); // lua_add_string_field ("id", s);
lua_add_string_field ("id", s); // if (!(M->flags & FLAG_CREATED)) { return; }
if (!(M->flags & FLAG_CREATED)) { return; } // lua_add_num_field ("flags", M->flags);
lua_add_num_field ("flags", M->flags); //
// if (tgl_get_peer_type (M->fwd_from_id)) {
if (tgl_get_peer_type (M->fwd_from_id)) { // lua_pushstring (luaState, "fwd_from");
lua_pushstring (luaState, "fwd_from"); // push_peer (M->fwd_from_id, tgl_peer_get (TLS, M->fwd_from_id));
push_peer (M->fwd_from_id, tgl_peer_get (TLS, M->fwd_from_id)); // lua_settable (luaState, -3); // fwd_from
lua_settable (luaState, -3); // fwd_from //
// lua_add_num_field ("fwd_date", M->fwd_date);
lua_add_num_field ("fwd_date", M->fwd_date); // }
} //
// lua_pushstring (luaState, "from");
lua_pushstring (luaState, "from"); // push_peer (M->from_id, tgl_peer_get (TLS, M->from_id));
push_peer (M->from_id, tgl_peer_get (TLS, M->from_id)); // lua_settable (luaState, -3);
lua_settable (luaState, -3); //
// lua_pushstring (luaState, "to");
lua_pushstring (luaState, "to"); // push_peer (M->to_id, tgl_peer_get (TLS, M->to_id));
push_peer (M->to_id, tgl_peer_get (TLS, M->to_id)); // lua_settable (luaState, -3);
lua_settable (luaState, -3); //
// lua_pushstring (luaState, "out");
lua_pushstring (luaState, "out"); // lua_pushboolean (luaState, M->out);
lua_pushboolean (luaState, M->out); // lua_settable (luaState, -3);
lua_settable (luaState, -3); //
// lua_pushstring (luaState, "unread");
lua_pushstring (luaState, "unread"); // lua_pushboolean (luaState, M->unread);
lua_pushboolean (luaState, M->unread); // lua_settable (luaState, -3);
lua_settable (luaState, -3); //
// lua_pushstring (luaState, "date");
lua_pushstring (luaState, "date"); // lua_pushnumber (luaState, M->date);
lua_pushnumber (luaState, M->date); // lua_settable (luaState, -3);
lua_settable (luaState, -3); //
// lua_pushstring (luaState, "service");
lua_pushstring (luaState, "service"); // lua_pushboolean (luaState, M->service);
lua_pushboolean (luaState, M->service); // lua_settable (luaState, -3);
lua_settable (luaState, -3); //
// if (!M->service) {
if (!M->service) { // if (M->message_len && M->message) {
if (M->message_len && M->message) { // lua_pushstring (luaState, "text");
lua_pushstring (luaState, "text"); // lua_pushlstring (luaState, M->message, M->message_len);
lua_pushlstring (luaState, M->message, M->message_len); // lua_settable (luaState, -3);
lua_settable (luaState, -3); // }
} // if (M->media.type && M->media.type != tgl_message_media_none) {
if (M->media.type && M->media.type != tgl_message_media_none) { // lua_pushstring (luaState, "media");
lua_pushstring (luaState, "media"); // push_media (&M->media);
push_media (&M->media); // lua_settable (luaState, -3);
lua_settable (luaState, -3); // }
} // }
} //}
//
//void lua_binlog_end (void) {
// if (!have_file) { return; }
// lua_settop (luaState, 0);
// //lua_checkstack (luaState, 20);
// my_lua_checkstack (luaState, 20);
// lua_getglobal (luaState, "on_binlog_replay_end");
// assert (lua_gettop (luaState) == 1);
//
// int r = lua_pcall (luaState, 0, 0, 0);
// if (r) {
// logprintf ("lua: %s\n", lua_tostring (luaState, -1));
// }
//}
//
//void lua_diff_end (void) {
// if (!have_file) { return; }
// lua_settop (luaState, 0);
// //lua_checkstack (luaState, 20);
// my_lua_checkstack (luaState, 20);
// lua_getglobal (luaState, "on_get_difference_end");
// assert (lua_gettop (luaState) == 1);
//
// int r = lua_pcall (luaState, 0, 0, 0);
// if (r) {
// logprintf ("lua: %s\n", lua_tostring (luaState, -1));
// }
//}
//
void py_our_id (int id) {
// if (!have_file) { return; }
// lua_settop (luaState, 0);
// //lua_checkstack (luaState, 20);
// my_lua_checkstack (luaState, 20);
// lua_getglobal (luaState, "on_our_id");
// lua_pushnumber (luaState, id);
// assert (lua_gettop (luaState) == 2);
//
// int r = lua_pcall (luaState, 1, 0, 0);
// if (r) {
// logprintf ("lua: %s\n", lua_tostring (luaState, -1));
// }
} }
void lua_binlog_end (void) { void py_new_msg (struct tgl_message *M) {
if (!have_file) { return; } // if (!have_file) { return; }
lua_settop (luaState, 0); // lua_settop (luaState, 0);
//lua_checkstack (luaState, 20); // //lua_checkstack (luaState, 20);
my_lua_checkstack (luaState, 20); // my_lua_checkstack (luaState, 20);
lua_getglobal (luaState, "on_binlog_replay_end"); // lua_getglobal (luaState, "on_msg_receive");
assert (lua_gettop (luaState) == 1); // push_message (M);
// assert (lua_gettop (luaState) == 2);
int r = lua_pcall (luaState, 0, 0, 0); //
if (r) { // int r = lua_pcall (luaState, 1, 0, 0);
logprintf ("lua: %s\n", lua_tostring (luaState, -1)); // if (r) {
} // logprintf ("lua: %s\n", lua_tostring (luaState, -1));
} // }
void lua_diff_end (void) {
if (!have_file) { return; }
lua_settop (luaState, 0);
//lua_checkstack (luaState, 20);
my_lua_checkstack (luaState, 20);
lua_getglobal (luaState, "on_get_difference_end");
assert (lua_gettop (luaState) == 1);
int r = lua_pcall (luaState, 0, 0, 0);
if (r) {
logprintf ("lua: %s\n", lua_tostring (luaState, -1));
}
}
void lua_our_id (int id) {
if (!have_file) { return; }
lua_settop (luaState, 0);
//lua_checkstack (luaState, 20);
my_lua_checkstack (luaState, 20);
lua_getglobal (luaState, "on_our_id");
lua_pushnumber (luaState, id);
assert (lua_gettop (luaState) == 2);
int r = lua_pcall (luaState, 1, 0, 0);
if (r) {
logprintf ("lua: %s\n", lua_tostring (luaState, -1));
}
} }
void lua_new_msg (struct tgl_message *M) { void py_secret_chat_update (struct tgl_secret_chat *C, unsigned flags) {
if (!have_file) { return; } // if (!have_file) { return; }
lua_settop (luaState, 0); // lua_settop (luaState, 0);
//lua_checkstack (luaState, 20); // //lua_checkstack (luaState, 20);
my_lua_checkstack (luaState, 20); // my_lua_checkstack (luaState, 20);
lua_getglobal (luaState, "on_msg_receive"); // lua_getglobal (luaState, "on_secret_chat_update");
push_message (M); // push_peer (C->id, (void *)C);
assert (lua_gettop (luaState) == 2); // push_update_types (flags);
// assert (lua_gettop (luaState) == 3);
int r = lua_pcall (luaState, 1, 0, 0); //
if (r) { // int r = lua_pcall (luaState, 2, 0, 0);
logprintf ("lua: %s\n", lua_tostring (luaState, -1)); // if (r) {
} // logprintf ("lua: %s\n", lua_tostring (luaState, -1));
// }
} }
void lua_secret_chat_update (struct tgl_secret_chat *C, unsigned flags) { void py_user_update (struct tgl_user *U, unsigned flags) {
if (!have_file) { return; } // if (!have_file) { return; }
lua_settop (luaState, 0); // lua_settop (luaState, 0);
//lua_checkstack (luaState, 20); // //lua_checkstack (luaState, 20);
my_lua_checkstack (luaState, 20); // my_lua_checkstack (luaState, 20);
lua_getglobal (luaState, "on_secret_chat_update"); // lua_getglobal (luaState, "on_user_update");
push_peer (C->id, (void *)C); // push_peer (U->id, (void *)U);
push_update_types (flags); // push_update_types (flags);
assert (lua_gettop (luaState) == 3); // assert (lua_gettop (luaState) == 3);
//
int r = lua_pcall (luaState, 2, 0, 0); // int r = lua_pcall (luaState, 2, 0, 0);
if (r) { // if (r) {
logprintf ("lua: %s\n", lua_tostring (luaState, -1)); // logprintf ("lua: %s\n", lua_tostring (luaState, -1));
} // }
} }
void lua_user_update (struct tgl_user *U, unsigned flags) { void py_chat_update (struct tgl_chat *C, unsigned flags) {
if (!have_file) { return; } // if (!have_file) { return; }
lua_settop (luaState, 0); // lua_settop (luaState, 0);
//lua_checkstack (luaState, 20); // //lua_checkstack (luaState, 20);
my_lua_checkstack (luaState, 20); // my_lua_checkstack (luaState, 20);
lua_getglobal (luaState, "on_user_update"); // lua_getglobal (luaState, "on_chat_update");
push_peer (U->id, (void *)U); // push_peer (C->id, (void *)C);
push_update_types (flags); // push_update_types (flags);
assert (lua_gettop (luaState) == 3); // assert (lua_gettop (luaState) == 3);
//
int r = lua_pcall (luaState, 2, 0, 0); // int r = lua_pcall (luaState, 2, 0, 0);
if (r) { // if (r) {
logprintf ("lua: %s\n", lua_tostring (luaState, -1)); // logprintf ("lua: %s\n", lua_tostring (luaState, -1));
} // }
} }
//
void lua_chat_update (struct tgl_chat *C, unsigned flags) { ////extern tgl_peer_t *Peers[];
if (!have_file) { return; } ////extern int peer_num;
lua_settop (luaState, 0); //
//lua_checkstack (luaState, 20); //#define MAX_LUA_COMMANDS 1000
my_lua_checkstack (luaState, 20); //void *lua_ptr[MAX_LUA_COMMANDS];
lua_getglobal (luaState, "on_chat_update"); //static int pos;
push_peer (C->id, (void *)C); //
push_update_types (flags); //static inline tgl_peer_t *get_peer (const char *s) {
assert (lua_gettop (luaState) == 3); // return tgl_peer_get_by_name (TLS, s);
//}
int r = lua_pcall (luaState, 2, 0, 0); //
if (r) { //enum lua_query_type {
logprintf ("lua: %s\n", lua_tostring (luaState, -1)); // lq_contact_list,
} // lq_dialog_list,
} // lq_msg,
// lq_send_typing,
//extern tgl_peer_t *Peers[]; // lq_send_typing_abort,
//extern int peer_num; // lq_rename_chat,
// lq_send_photo,
#define MAX_LUA_COMMANDS 1000 // lq_chat_set_photo,
void *lua_ptr[MAX_LUA_COMMANDS]; // lq_set_profile_photo,
static int pos; // lq_set_profile_name,
// lq_send_video,
static inline tgl_peer_t *get_peer (const char *s) { // lq_send_text,
return tgl_peer_get_by_name (TLS, s); // lq_fwd,
} // lq_fwd_media,
// lq_load_photo,
enum lua_query_type { // lq_load_video_thumb,
lq_contact_list, // lq_load_video,
lq_dialog_list, // lq_chat_info,
lq_msg, // lq_user_info,
lq_send_typing, // lq_history,
lq_send_typing_abort, // lq_chat_add_user,
lq_rename_chat, // lq_chat_del_user,
lq_send_photo, // lq_add_contact,
lq_chat_set_photo, // lq_del_contact,
lq_set_profile_photo, // lq_rename_contact,
lq_set_profile_name, // lq_search,
lq_send_video, // lq_global_search,
lq_send_text, // lq_mark_read,
lq_fwd, // lq_create_secret_chat,
lq_fwd_media, // lq_create_group_chat,
lq_load_photo, // lq_send_audio,
lq_load_video_thumb, // lq_send_document,
lq_load_video, // lq_send_file,
lq_chat_info, // lq_load_audio,
lq_user_info, // lq_load_document,
lq_history, // lq_load_document_thumb,
lq_chat_add_user, // lq_delete_msg,
lq_chat_del_user, // lq_restore_msg,
lq_add_contact, // lq_accept_secret_chat,
lq_del_contact, // lq_send_contact,
lq_rename_contact, // lq_status_online,
lq_search, // lq_status_offline,
lq_global_search, // lq_send_location,
lq_mark_read, // lq_extf
lq_create_secret_chat, //};
lq_create_group_chat, //
lq_send_audio, //struct lua_query_extra {
lq_send_document, // int func;
lq_send_file, // int param;
lq_load_audio, //};
lq_load_document, //
lq_load_document_thumb, //void lua_empty_cb (struct tgl_state *TLSR, void *cb_extra, int success) {
lq_delete_msg, // assert (TLSR == TLS);
lq_restore_msg, // struct lua_query_extra *cb = cb_extra;
lq_accept_secret_chat, // lua_settop (luaState, 0);
lq_send_contact, // //lua_checkstack (luaState, 20);
lq_status_online, // my_lua_checkstack (luaState, 20);
lq_status_offline, //
lq_send_location, // lua_rawgeti (luaState, LUA_REGISTRYINDEX, cb->func);
lq_extf // lua_rawgeti (luaState, LUA_REGISTRYINDEX, cb->param);
}; //
// lua_pushnumber (luaState, success);
struct lua_query_extra { //
int func; // assert (lua_gettop (luaState) == 3);
int param; //
}; // int r = lua_pcall (luaState, 2, 0, 0);
//
void lua_empty_cb (struct tgl_state *TLSR, void *cb_extra, int success) { // luaL_unref (luaState, LUA_REGISTRYINDEX, cb->func);
assert (TLSR == TLS); // luaL_unref (luaState, LUA_REGISTRYINDEX, cb->param);
struct lua_query_extra *cb = cb_extra; //
lua_settop (luaState, 0); // if (r) {
//lua_checkstack (luaState, 20); // logprintf ("lua: %s\n", lua_tostring (luaState, -1));
my_lua_checkstack (luaState, 20); // }
//
lua_rawgeti (luaState, LUA_REGISTRYINDEX, cb->func); // free (cb);
lua_rawgeti (luaState, LUA_REGISTRYINDEX, cb->param); //}
//
lua_pushnumber (luaState, success); //void lua_contact_list_cb (struct tgl_state *TLSR, void *cb_extra, int success, int num, struct tgl_user **UL) {
// assert (TLSR == TLS);
assert (lua_gettop (luaState) == 3); // struct lua_query_extra *cb = cb_extra;
// lua_settop (luaState, 0);
int r = lua_pcall (luaState, 2, 0, 0); // //lua_checkstack (luaState, 20);
// my_lua_checkstack (luaState, 20);
luaL_unref (luaState, LUA_REGISTRYINDEX, cb->func); //
luaL_unref (luaState, LUA_REGISTRYINDEX, cb->param); // lua_rawgeti (luaState, LUA_REGISTRYINDEX, cb->func);
// lua_rawgeti (luaState, LUA_REGISTRYINDEX, cb->param);
if (r) { //
logprintf ("lua: %s\n", lua_tostring (luaState, -1)); // lua_pushnumber (luaState, success);
} //
// if (success) {
free (cb); // lua_newtable (luaState);
} // int i;
// for (i = 0; i < num; i++) {
void lua_contact_list_cb (struct tgl_state *TLSR, void *cb_extra, int success, int num, struct tgl_user **UL) { // lua_pushnumber (luaState, i);
assert (TLSR == TLS); // push_peer (UL[i]->id, (void *)UL[i]);
struct lua_query_extra *cb = cb_extra; // lua_settable (luaState, -3);
lua_settop (luaState, 0); // }
//lua_checkstack (luaState, 20); // } else {
my_lua_checkstack (luaState, 20); // lua_pushboolean (luaState, 0);
// }
lua_rawgeti (luaState, LUA_REGISTRYINDEX, cb->func); //
lua_rawgeti (luaState, LUA_REGISTRYINDEX, cb->param); // assert (lua_gettop (luaState) == 4);
//
lua_pushnumber (luaState, success); // int r = lua_pcall (luaState, 3, 0, 0);
//
if (success) { // luaL_unref (luaState, LUA_REGISTRYINDEX, cb->func);
lua_newtable (luaState); // luaL_unref (luaState, LUA_REGISTRYINDEX, cb->param);
int i; //
for (i = 0; i < num; i++) { // if (r) {
lua_pushnumber (luaState, i); // logprintf ("lua: %s\n", lua_tostring (luaState, -1));
push_peer (UL[i]->id, (void *)UL[i]); // }
lua_settable (luaState, -3); //
} // free (cb);
} else { //}
lua_pushboolean (luaState, 0); //
} //void lua_dialog_list_cb (struct tgl_state *TLSR, void *cb_extra, int success, int num, tgl_peer_id_t peers[], int msgs[], int unread[]) {
// assert (TLSR == TLS);
assert (lua_gettop (luaState) == 4); // struct lua_query_extra *cb = cb_extra;
// lua_settop (luaState, 0);
int r = lua_pcall (luaState, 3, 0, 0); // //lua_checkstack (luaState, 20);
// my_lua_checkstack (luaState, 20);
luaL_unref (luaState, LUA_REGISTRYINDEX, cb->func); //
luaL_unref (luaState, LUA_REGISTRYINDEX, cb->param); // lua_rawgeti (luaState, LUA_REGISTRYINDEX, cb->func);
// lua_rawgeti (luaState, LUA_REGISTRYINDEX, cb->param);
if (r) { //
logprintf ("lua: %s\n", lua_tostring (luaState, -1)); // lua_pushnumber (luaState, success);
} // if (success) {
// lua_newtable (luaState);
free (cb); // int i;
} // for (i = 0; i < num; i++) {
// lua_pushnumber (luaState, i);
void lua_dialog_list_cb (struct tgl_state *TLSR, void *cb_extra, int success, int num, tgl_peer_id_t peers[], int msgs[], int unread[]) { //
assert (TLSR == TLS); // lua_newtable (luaState);
struct lua_query_extra *cb = cb_extra; //
lua_settop (luaState, 0); // lua_pushstring (luaState, "peer");
//lua_checkstack (luaState, 20); // push_peer (peers[i], tgl_peer_get (TLS, peers[i]));
my_lua_checkstack (luaState, 20); // lua_settable (luaState, -3);
//
lua_rawgeti (luaState, LUA_REGISTRYINDEX, cb->func); // struct tgl_message *M = tgl_message_get (TLS, msgs[i]);
lua_rawgeti (luaState, LUA_REGISTRYINDEX, cb->param); // if (M && (M->flags & FLAG_CREATED)) {
// lua_pushstring (luaState, "message");
lua_pushnumber (luaState, success); // push_message (M);
if (success) { // lua_settable (luaState, -3);
lua_newtable (luaState); // }
int i; //
for (i = 0; i < num; i++) { // lua_pushstring (luaState, "unread");
lua_pushnumber (luaState, i); // lua_pushnumber (luaState, unread[i]);
// lua_settable (luaState, -3);
lua_newtable (luaState); //
// lua_settable (luaState, -3);
lua_pushstring (luaState, "peer"); // }
push_peer (peers[i], tgl_peer_get (TLS, peers[i])); // } else {
lua_settable (luaState, -3); // lua_pushboolean (luaState, 0);
// }
struct tgl_message *M = tgl_message_get (TLS, msgs[i]); // assert (lua_gettop (luaState) == 4);
if (M && (M->flags & FLAG_CREATED)) { //
lua_pushstring (luaState, "message"); //
push_message (M); // int r = lua_pcall (luaState, 3, 0, 0);
lua_settable (luaState, -3); //
} // luaL_unref (luaState, LUA_REGISTRYINDEX, cb->func);
// luaL_unref (luaState, LUA_REGISTRYINDEX, cb->param);
lua_pushstring (luaState, "unread"); //
lua_pushnumber (luaState, unread[i]); // if (r) {
lua_settable (luaState, -3); // logprintf ("lua: %s\n", lua_tostring (luaState, -1));
// }
lua_settable (luaState, -3); //
} // free (cb);
} else { //}
lua_pushboolean (luaState, 0); //
} //void lua_msg_cb (struct tgl_state *TLSR, void *cb_extra, int success, struct tgl_message *M) {
assert (lua_gettop (luaState) == 4); // assert (TLSR == TLS);
// struct lua_query_extra *cb = cb_extra;
// lua_settop (luaState, 0);
int r = lua_pcall (luaState, 3, 0, 0); // //lua_checkstack (luaState, 20);
// my_lua_checkstack (luaState, 20);
luaL_unref (luaState, LUA_REGISTRYINDEX, cb->func); //
luaL_unref (luaState, LUA_REGISTRYINDEX, cb->param); // lua_rawgeti (luaState, LUA_REGISTRYINDEX, cb->func);
// lua_rawgeti (luaState, LUA_REGISTRYINDEX, cb->param);
if (r) { //
logprintf ("lua: %s\n", lua_tostring (luaState, -1)); // lua_pushnumber (luaState, success);
} //
// if (success) {
free (cb); // push_message (M);
} // } else {
// lua_pushboolean (luaState, 0);
void lua_msg_cb (struct tgl_state *TLSR, void *cb_extra, int success, struct tgl_message *M) { // }
assert (TLSR == TLS); //
struct lua_query_extra *cb = cb_extra; // assert (lua_gettop (luaState) == 4);
lua_settop (luaState, 0); //
//lua_checkstack (luaState, 20); // int r = lua_pcall (luaState, 3, 0, 0);
my_lua_checkstack (luaState, 20); //
// luaL_unref (luaState, LUA_REGISTRYINDEX, cb->func);
lua_rawgeti (luaState, LUA_REGISTRYINDEX, cb->func); // luaL_unref (luaState, LUA_REGISTRYINDEX, cb->param);
lua_rawgeti (luaState, LUA_REGISTRYINDEX, cb->param); //
// if (r) {
lua_pushnumber (luaState, success); // logprintf ("lua: %s\n", lua_tostring (luaState, -1));
// }
if (success) { //
push_message (M); // free (cb);
} else { //}
lua_pushboolean (luaState, 0); //
} //void lua_msg_list_cb (struct tgl_state *TLSR, void *cb_extra, int success, int num, struct tgl_message *M[]) {
// assert (TLSR == TLS);
assert (lua_gettop (luaState) == 4); // struct lua_query_extra *cb = cb_extra;
// lua_settop (luaState, 0);
int r = lua_pcall (luaState, 3, 0, 0); // //lua_checkstack (luaState, 20);
// my_lua_checkstack (luaState, 20);
luaL_unref (luaState, LUA_REGISTRYINDEX, cb->func); //
luaL_unref (luaState, LUA_REGISTRYINDEX, cb->param); // lua_rawgeti (luaState, LUA_REGISTRYINDEX, cb->func);
// lua_rawgeti (luaState, LUA_REGISTRYINDEX, cb->param);
if (r) { //
logprintf ("lua: %s\n", lua_tostring (luaState, -1)); // lua_pushnumber (luaState, success);
} //
// if (success) {
free (cb); // lua_newtable (luaState);
} // int i;
// for (i = 0; i < num; i++) {
void lua_msg_list_cb (struct tgl_state *TLSR, void *cb_extra, int success, int num, struct tgl_message *M[]) { // lua_pushnumber (luaState, i);
assert (TLSR == TLS); // push_message (M[i]);
struct lua_query_extra *cb = cb_extra; // lua_settable (luaState, -3);
lua_settop (luaState, 0); // }
//lua_checkstack (luaState, 20); // } else {
my_lua_checkstack (luaState, 20); // lua_pushboolean (luaState, 0);
// }
lua_rawgeti (luaState, LUA_REGISTRYINDEX, cb->func); //
lua_rawgeti (luaState, LUA_REGISTRYINDEX, cb->param); // assert (lua_gettop (luaState) == 4);
//
lua_pushnumber (luaState, success); // int r = lua_pcall (luaState, 3, 0, 0);
//
if (success) { // luaL_unref (luaState, LUA_REGISTRYINDEX, cb->func);
lua_newtable (luaState); // luaL_unref (luaState, LUA_REGISTRYINDEX, cb->param);
int i; //
for (i = 0; i < num; i++) { // if (r) {
lua_pushnumber (luaState, i); // logprintf ("lua: %s\n", lua_tostring (luaState, -1));
push_message (M[i]); // }
lua_settable (luaState, -3); //
} // free (cb);
} else { //}
lua_pushboolean (luaState, 0); //
} //void lua_file_cb (struct tgl_state *TLSR, void *cb_extra, int success, char *file_name) {
// assert (TLSR == TLS);
assert (lua_gettop (luaState) == 4); // struct lua_query_extra *cb = cb_extra;
// lua_settop (luaState, 0);
int r = lua_pcall (luaState, 3, 0, 0); // //lua_checkstack (luaState, 20);
// my_lua_checkstack (luaState, 20);
luaL_unref (luaState, LUA_REGISTRYINDEX, cb->func); //
luaL_unref (luaState, LUA_REGISTRYINDEX, cb->param); // lua_rawgeti (luaState, LUA_REGISTRYINDEX, cb->func);
// lua_rawgeti (luaState, LUA_REGISTRYINDEX, cb->param);
if (r) { //
logprintf ("lua: %s\n", lua_tostring (luaState, -1)); // lua_pushnumber (luaState, success);
} //
// if (success) {
free (cb); // lua_pushstring (luaState, file_name);
} // } else {
// lua_pushboolean (luaState, 0);
void lua_file_cb (struct tgl_state *TLSR, void *cb_extra, int success, char *file_name) { // }
assert (TLSR == TLS); //
struct lua_query_extra *cb = cb_extra; // assert (lua_gettop (luaState) == 4);
lua_settop (luaState, 0); //
//lua_checkstack (luaState, 20); // int r = lua_pcall (luaState, 3, 0, 0);
my_lua_checkstack (luaState, 20); //
// luaL_unref (luaState, LUA_REGISTRYINDEX, cb->func);
lua_rawgeti (luaState, LUA_REGISTRYINDEX, cb->func); // luaL_unref (luaState, LUA_REGISTRYINDEX, cb->param);
lua_rawgeti (luaState, LUA_REGISTRYINDEX, cb->param); //
// if (r) {
lua_pushnumber (luaState, success); // logprintf ("lua: %s\n", lua_tostring (luaState, -1));
// }
if (success) { //
lua_pushstring (luaState, file_name); // free (cb);
} else { //}
lua_pushboolean (luaState, 0); //
} //void lua_chat_cb (struct tgl_state *TLSR, void *cb_extra, int success, struct tgl_chat *C) {
// assert (TLSR == TLS);
assert (lua_gettop (luaState) == 4); // struct lua_query_extra *cb = cb_extra;
// lua_settop (luaState, 0);
int r = lua_pcall (luaState, 3, 0, 0); // //lua_checkstack (luaState, 20);
// my_lua_checkstack (luaState, 20);
luaL_unref (luaState, LUA_REGISTRYINDEX, cb->func); //
luaL_unref (luaState, LUA_REGISTRYINDEX, cb->param); // lua_rawgeti (luaState, LUA_REGISTRYINDEX, cb->func);
// lua_rawgeti (luaState, LUA_REGISTRYINDEX, cb->param);
if (r) { //
logprintf ("lua: %s\n", lua_tostring (luaState, -1)); // lua_pushnumber (luaState, success);
} //
// if (success) {
free (cb); // push_peer (C->id, (void *)C);
} // } else {
// lua_pushboolean (luaState, 0);
void lua_chat_cb (struct tgl_state *TLSR, void *cb_extra, int success, struct tgl_chat *C) { // }
assert (TLSR == TLS); //
struct lua_query_extra *cb = cb_extra; // assert (lua_gettop (luaState) == 4);
lua_settop (luaState, 0); //
//lua_checkstack (luaState, 20); // int r = lua_pcall (luaState, 3, 0, 0);
my_lua_checkstack (luaState, 20); //
// luaL_unref (luaState, LUA_REGISTRYINDEX, cb->func);
lua_rawgeti (luaState, LUA_REGISTRYINDEX, cb->func); // luaL_unref (luaState, LUA_REGISTRYINDEX, cb->param);
lua_rawgeti (luaState, LUA_REGISTRYINDEX, cb->param); //
// if (r) {
lua_pushnumber (luaState, success); // logprintf ("lua: %s\n", lua_tostring (luaState, -1));
// }
if (success) { //
push_peer (C->id, (void *)C); // free (cb);
} else { //}
lua_pushboolean (luaState, 0); //
} //void lua_secret_chat_cb (struct tgl_state *TLSR, void *cb_extra, int success, struct tgl_secret_chat *C) {
// assert (TLSR == TLS);
assert (lua_gettop (luaState) == 4); // struct lua_query_extra *cb = cb_extra;
// lua_settop (luaState, 0);
int r = lua_pcall (luaState, 3, 0, 0); // //lua_checkstack (luaState, 20);
// my_lua_checkstack (luaState, 20);
luaL_unref (luaState, LUA_REGISTRYINDEX, cb->func); //
luaL_unref (luaState, LUA_REGISTRYINDEX, cb->param); // lua_rawgeti (luaState, LUA_REGISTRYINDEX, cb->func);
// lua_rawgeti (luaState, LUA_REGISTRYINDEX, cb->param);
if (r) { //
logprintf ("lua: %s\n", lua_tostring (luaState, -1)); // lua_pushnumber (luaState, success);
} //
// if (success) {
free (cb); // push_peer (C->id, (void *)C);
} // } else {
// lua_pushboolean (luaState, 0);
void lua_secret_chat_cb (struct tgl_state *TLSR, void *cb_extra, int success, struct tgl_secret_chat *C) { // }
assert (TLSR == TLS); //
struct lua_query_extra *cb = cb_extra; // assert (lua_gettop (luaState) == 4);
lua_settop (luaState, 0); //
//lua_checkstack (luaState, 20); // int r = lua_pcall (luaState, 3, 0, 0);
my_lua_checkstack (luaState, 20); //
// luaL_unref (luaState, LUA_REGISTRYINDEX, cb->func);
lua_rawgeti (luaState, LUA_REGISTRYINDEX, cb->func); // luaL_unref (luaState, LUA_REGISTRYINDEX, cb->param);
lua_rawgeti (luaState, LUA_REGISTRYINDEX, cb->param); //
// if (r) {
lua_pushnumber (luaState, success); // logprintf ("lua: %s\n", lua_tostring (luaState, -1));
// }
if (success) { //
push_peer (C->id, (void *)C); // free (cb);
} else { //}
lua_pushboolean (luaState, 0); //
} //void lua_user_cb (struct tgl_state *TLSR, void *cb_extra, int success, struct tgl_user *C) {
// assert (TLSR == TLS);
assert (lua_gettop (luaState) == 4); // struct lua_query_extra *cb = cb_extra;
// lua_settop (luaState, 0);
int r = lua_pcall (luaState, 3, 0, 0); // //lua_checkstack (luaState, 20);
// my_lua_checkstack (luaState, 20);
luaL_unref (luaState, LUA_REGISTRYINDEX, cb->func); //
luaL_unref (luaState, LUA_REGISTRYINDEX, cb->param); // lua_rawgeti (luaState, LUA_REGISTRYINDEX, cb->func);
// lua_rawgeti (luaState, LUA_REGISTRYINDEX, cb->param);
if (r) { //
logprintf ("lua: %s\n", lua_tostring (luaState, -1)); // lua_pushnumber (luaState, success);
} //
// if (success) {
free (cb); // push_peer (C->id, (void *)C);
} // } else {
// lua_pushboolean (luaState, 0);
void lua_user_cb (struct tgl_state *TLSR, void *cb_extra, int success, struct tgl_user *C) { // }
assert (TLSR == TLS); //
struct lua_query_extra *cb = cb_extra; // assert (lua_gettop (luaState) == 4);
lua_settop (luaState, 0); //
//lua_checkstack (luaState, 20); // int r = lua_pcall (luaState, 3, 0, 0);
my_lua_checkstack (luaState, 20); //
// luaL_unref (luaState, LUA_REGISTRYINDEX, cb->func);
lua_rawgeti (luaState, LUA_REGISTRYINDEX, cb->func); // luaL_unref (luaState, LUA_REGISTRYINDEX, cb->param);
lua_rawgeti (luaState, LUA_REGISTRYINDEX, cb->param); //
// if (r) {
lua_pushnumber (luaState, success); // logprintf ("lua: %s\n", lua_tostring (luaState, -1));
// }
if (success) { //
push_peer (C->id, (void *)C); // free (cb);
} else { //}
lua_pushboolean (luaState, 0); //
} //void lua_str_cb (struct tgl_state *TLSR, void *cb_extra, int success, char *data) {
// assert (TLSR == TLS);
assert (lua_gettop (luaState) == 4); // struct lua_query_extra *cb = cb_extra;
// lua_settop (luaState, 0);
int r = lua_pcall (luaState, 3, 0, 0); // //lua_checkstack (luaState, 20);
// my_lua_checkstack (luaState, 20);
luaL_unref (luaState, LUA_REGISTRYINDEX, cb->func); //
luaL_unref (luaState, LUA_REGISTRYINDEX, cb->param); // lua_rawgeti (luaState, LUA_REGISTRYINDEX, cb->func);
// lua_rawgeti (luaState, LUA_REGISTRYINDEX, cb->param);
if (r) { //
logprintf ("lua: %s\n", lua_tostring (luaState, -1)); // lua_pushnumber (luaState, success);
} //
// if (success) {
free (cb); // lua_pushstring (luaState, data);
} // } else {
// lua_pushboolean (luaState, 0);
void lua_str_cb (struct tgl_state *TLSR, void *cb_extra, int success, char *data) { // }
assert (TLSR == TLS); //
struct lua_query_extra *cb = cb_extra; // assert (lua_gettop (luaState) == 4);
lua_settop (luaState, 0); //
//lua_checkstack (luaState, 20); // int r = lua_pcall (luaState, 3, 0, 0);
my_lua_checkstack (luaState, 20); //
// luaL_unref (luaState, LUA_REGISTRYINDEX, cb->func);
lua_rawgeti (luaState, LUA_REGISTRYINDEX, cb->func); // luaL_unref (luaState, LUA_REGISTRYINDEX, cb->param);
lua_rawgeti (luaState, LUA_REGISTRYINDEX, cb->param); //
// if (r) {
lua_pushnumber (luaState, success); // logprintf ("lua: %s\n", lua_tostring (luaState, -1));
// }
if (success) { //
lua_pushstring (luaState, data); // free (cb);
} else { //}
lua_pushboolean (luaState, 0); //
} //void lua_do_all (void) {
// int p = 0;
assert (lua_gettop (luaState) == 4); // while (p < pos) {
// int l = (long)lua_ptr[p ++];
int r = lua_pcall (luaState, 3, 0, 0); // assert (p + l + 1 <= pos);
// enum lua_query_type f = (long)lua_ptr[p ++];
luaL_unref (luaState, LUA_REGISTRYINDEX, cb->func); // struct tgl_message *M;
luaL_unref (luaState, LUA_REGISTRYINDEX, cb->param); // char *s, *s1, *s2, *s3;
// switch (f) {
if (r) { // case lq_contact_list:
logprintf ("lua: %s\n", lua_tostring (luaState, -1)); // tgl_do_update_contact_list (TLS, lua_contact_list_cb, lua_ptr[p ++]);
} // break;
// case lq_dialog_list:
free (cb); // tgl_do_get_dialog_list (TLS, lua_dialog_list_cb, lua_ptr[p ++]);
} // break;
// case lq_msg:
void lua_do_all (void) { // tgl_do_send_message (TLS, ((tgl_peer_t *)lua_ptr[p + 1])->id, lua_ptr[p + 2], strlen (lua_ptr[p + 2]), lua_msg_cb, lua_ptr[p]);
int p = 0; // free (lua_ptr[p + 2]);
while (p < pos) { // p += 3;
int l = (long)lua_ptr[p ++]; // break;
assert (p + l + 1 <= pos); // case lq_send_typing:
enum lua_query_type f = (long)lua_ptr[p ++]; // tgl_do_send_typing (TLS, ((tgl_peer_t *)lua_ptr[p + 1])->id, tgl_typing_typing, lua_empty_cb, lua_ptr[p]);
struct tgl_message *M; // p += 2;
char *s, *s1, *s2, *s3; // break;
switch (f) { // case lq_send_typing_abort:
case lq_contact_list: // tgl_do_send_typing (TLS, ((tgl_peer_t *)lua_ptr[p + 1])->id, tgl_typing_cancel, lua_empty_cb, lua_ptr[p]);
tgl_do_update_contact_list (TLS, lua_contact_list_cb, lua_ptr[p ++]); // p += 2;
break; // break;
case lq_dialog_list: // case lq_rename_chat:
tgl_do_get_dialog_list (TLS, lua_dialog_list_cb, lua_ptr[p ++]); // tgl_do_rename_chat (TLS, ((tgl_peer_t *)lua_ptr[p + 1])->id, lua_ptr[p + 2], lua_msg_cb, lua_ptr[p]);
break; // free (lua_ptr[p + 2]);
case lq_msg: // p += 3;
tgl_do_send_message (TLS, ((tgl_peer_t *)lua_ptr[p + 1])->id, lua_ptr[p + 2], strlen (lua_ptr[p + 2]), lua_msg_cb, lua_ptr[p]); // break;
free (lua_ptr[p + 2]); // case lq_send_photo:
p += 3; // tgl_do_send_document (TLS, -1, ((tgl_peer_t *)lua_ptr[p + 1])->id, lua_ptr[p + 2], lua_msg_cb, lua_ptr[p]);
break; // free (lua_ptr[p + 2]);
case lq_send_typing: // p += 3;
tgl_do_send_typing (TLS, ((tgl_peer_t *)lua_ptr[p + 1])->id, tgl_typing_typing, lua_empty_cb, lua_ptr[p]); // break;
p += 2; // case lq_send_video:
break; // tgl_do_send_document (TLS, FLAG_DOCUMENT_VIDEO, ((tgl_peer_t *)lua_ptr[p + 1])->id, lua_ptr[p + 2], lua_msg_cb, lua_ptr[p]);
case lq_send_typing_abort: // free (lua_ptr[p + 2]);
tgl_do_send_typing (TLS, ((tgl_peer_t *)lua_ptr[p + 1])->id, tgl_typing_cancel, lua_empty_cb, lua_ptr[p]); // p += 3;
p += 2; // break;
break; // case lq_send_audio:
case lq_rename_chat: // tgl_do_send_document (TLS, FLAG_DOCUMENT_AUDIO, ((tgl_peer_t *)lua_ptr[p + 1])->id, lua_ptr[p + 2], lua_msg_cb, lua_ptr[p]);
tgl_do_rename_chat (TLS, ((tgl_peer_t *)lua_ptr[p + 1])->id, lua_ptr[p + 2], lua_msg_cb, lua_ptr[p]); // free (lua_ptr[p + 2]);
free (lua_ptr[p + 2]); // p += 3;
p += 3; // break;
break; // case lq_send_document:
case lq_send_photo: // tgl_do_send_document (TLS, 0, ((tgl_peer_t *)lua_ptr[p + 1])->id, lua_ptr[p + 2], lua_msg_cb, lua_ptr[p]);
tgl_do_send_document (TLS, -1, ((tgl_peer_t *)lua_ptr[p + 1])->id, lua_ptr[p + 2], lua_msg_cb, lua_ptr[p]); // free (lua_ptr[p + 2]);
free (lua_ptr[p + 2]); // p += 3;
p += 3; // break;
break; // case lq_send_file:
case lq_send_video: // tgl_do_send_document (TLS, -2, ((tgl_peer_t *)lua_ptr[p + 1])->id, lua_ptr[p + 2], lua_msg_cb, lua_ptr[p]);
tgl_do_send_document (TLS, FLAG_DOCUMENT_VIDEO, ((tgl_peer_t *)lua_ptr[p + 1])->id, lua_ptr[p + 2], lua_msg_cb, lua_ptr[p]); // free (lua_ptr[p + 2]);
free (lua_ptr[p + 2]); // p += 3;
p += 3; // break;
break; // case lq_send_text:
case lq_send_audio: // tgl_do_send_text (TLS, ((tgl_peer_t *)lua_ptr[p + 1])->id, lua_ptr[p + 2], lua_msg_cb, lua_ptr[p]);
tgl_do_send_document (TLS, FLAG_DOCUMENT_AUDIO, ((tgl_peer_t *)lua_ptr[p + 1])->id, lua_ptr[p + 2], lua_msg_cb, lua_ptr[p]); // free (lua_ptr[p + 2]);
free (lua_ptr[p + 2]); // p += 3;
p += 3; // break;
break; // case lq_chat_set_photo:
case lq_send_document: // tgl_do_set_chat_photo (TLS, ((tgl_peer_t *)lua_ptr[p + 1])->id, lua_ptr[p + 2], lua_msg_cb, lua_ptr[p]);
tgl_do_send_document (TLS, 0, ((tgl_peer_t *)lua_ptr[p + 1])->id, lua_ptr[p + 2], lua_msg_cb, lua_ptr[p]); // free (lua_ptr[p + 2]);
free (lua_ptr[p + 2]); // p += 3;
p += 3; // break;
break; // case lq_load_photo:
case lq_send_file: // case lq_load_video:
tgl_do_send_document (TLS, -2, ((tgl_peer_t *)lua_ptr[p + 1])->id, lua_ptr[p + 2], lua_msg_cb, lua_ptr[p]); // case lq_load_audio:
free (lua_ptr[p + 2]); // case lq_load_document:
p += 3; // M = lua_ptr[p + 1];
break; // if (!M || (M->media.type != tgl_message_media_photo && M->media.type != tgl_message_media_photo_encr && M->media.type != tgl_message_media_document && M->media.type != tgl_message_media_document_encr)) {
case lq_send_text: // lua_file_cb (TLS, lua_ptr[p], 0, 0);
tgl_do_send_text (TLS, ((tgl_peer_t *)lua_ptr[p + 1])->id, lua_ptr[p + 2], lua_msg_cb, lua_ptr[p]); // } else {
free (lua_ptr[p + 2]); // if (M->media.type == tgl_message_media_photo) {
p += 3; // tgl_do_load_photo (TLS, &M->media.photo, lua_file_cb, lua_ptr[p]);
break; // } else if (M->media.type == tgl_message_media_document) {
case lq_chat_set_photo: // tgl_do_load_document (TLS, &M->media.document, lua_file_cb, lua_ptr[p]);
tgl_do_set_chat_photo (TLS, ((tgl_peer_t *)lua_ptr[p + 1])->id, lua_ptr[p + 2], lua_msg_cb, lua_ptr[p]); // } else {
free (lua_ptr[p + 2]); // tgl_do_load_encr_document (TLS, &M->media.encr_document, lua_file_cb, lua_ptr[p]);
p += 3; // }
break; // }
case lq_load_photo: // p += 2;
case lq_load_video: // break;
case lq_load_audio: // case lq_load_video_thumb:
case lq_load_document: // case lq_load_document_thumb:
M = lua_ptr[p + 1]; // M = lua_ptr[p + 1];
if (!M || (M->media.type != tgl_message_media_photo && M->media.type != tgl_message_media_photo_encr && M->media.type != tgl_message_media_document && M->media.type != tgl_message_media_document_encr)) { // if (!M || (M->media.type != tgl_message_media_document)) {
lua_file_cb (TLS, lua_ptr[p], 0, 0); // lua_file_cb (TLS, lua_ptr[p], 0, 0);
} else { // } else {
if (M->media.type == tgl_message_media_photo) { // tgl_do_load_document_thumb (TLS, &M->media.document, lua_file_cb, lua_ptr[p]);
tgl_do_load_photo (TLS, &M->media.photo, lua_file_cb, lua_ptr[p]); // }
} else if (M->media.type == tgl_message_media_document) { // p += 2;
tgl_do_load_document (TLS, &M->media.document, lua_file_cb, lua_ptr[p]); // break;
} else { // case lq_fwd:
tgl_do_load_encr_document (TLS, &M->media.encr_document, lua_file_cb, lua_ptr[p]); // tgl_do_forward_message (TLS, ((tgl_peer_t *)lua_ptr[p + 1])->id, ((struct tgl_message *)lua_ptr[p + 2])->id, lua_msg_cb, lua_ptr[p]);
} // p += 3;
} // break;
p += 2; // case lq_fwd_media:
break; // tgl_do_forward_media (TLS, ((tgl_peer_t *)lua_ptr[p + 1])->id, ((struct tgl_message *)lua_ptr[p + 2])->id, lua_msg_cb, lua_ptr[p]);
case lq_load_video_thumb: // p += 3;
case lq_load_document_thumb: // break;
M = lua_ptr[p + 1]; // case lq_chat_info:
if (!M || (M->media.type != tgl_message_media_document)) { // tgl_do_get_chat_info (TLS, ((tgl_peer_t *)lua_ptr[p + 1])->id, 0, lua_chat_cb, lua_ptr[p]);
lua_file_cb (TLS, lua_ptr[p], 0, 0); // p += 2;
} else { // break;
tgl_do_load_document_thumb (TLS, &M->media.document, lua_file_cb, lua_ptr[p]); // case lq_user_info:
} // tgl_do_get_user_info (TLS, ((tgl_peer_t *)lua_ptr[p + 1])->id, 0, lua_user_cb, lua_ptr[p]);
p += 2; // p += 2;
break; // break;
case lq_fwd: // case lq_history:
tgl_do_forward_message (TLS, ((tgl_peer_t *)lua_ptr[p + 1])->id, ((struct tgl_message *)lua_ptr[p + 2])->id, lua_msg_cb, lua_ptr[p]); // tgl_do_get_history (TLS, ((tgl_peer_t *)lua_ptr[p + 1])->id, (long)lua_ptr[p + 2], 0, lua_msg_list_cb, lua_ptr[p]);
p += 3; // p += 3;
break; // break;
case lq_fwd_media: // case lq_chat_add_user:
tgl_do_forward_media (TLS, ((tgl_peer_t *)lua_ptr[p + 1])->id, ((struct tgl_message *)lua_ptr[p + 2])->id, lua_msg_cb, lua_ptr[p]); // tgl_do_add_user_to_chat (TLS, ((tgl_peer_t *)lua_ptr[p + 1])->id, ((tgl_peer_t *)lua_ptr[p + 2])->id, 10, lua_msg_cb, lua_ptr[p]);
p += 3; // p += 3;
break; // break;
case lq_chat_info: // case lq_chat_del_user:
tgl_do_get_chat_info (TLS, ((tgl_peer_t *)lua_ptr[p + 1])->id, 0, lua_chat_cb, lua_ptr[p]); // tgl_do_del_user_from_chat (TLS, ((tgl_peer_t *)lua_ptr[p + 1])->id, ((tgl_peer_t *)lua_ptr[p + 2])->id, lua_msg_cb, lua_ptr[p]);
p += 2; // p += 3;
break; // break;
case lq_user_info: // case lq_add_contact:
tgl_do_get_user_info (TLS, ((tgl_peer_t *)lua_ptr[p + 1])->id, 0, lua_user_cb, lua_ptr[p]); // s1 = lua_ptr[p + 1];
p += 2; // s2 = lua_ptr[p + 2];
break; // s3 = lua_ptr[p + 3];
case lq_history: // tgl_do_add_contact (TLS, s1, strlen (s1), s2, strlen (s2), s3, strlen (s3), 0, lua_contact_list_cb, lua_ptr[p]);
tgl_do_get_history (TLS, ((tgl_peer_t *)lua_ptr[p + 1])->id, (long)lua_ptr[p + 2], 0, lua_msg_list_cb, lua_ptr[p]); // free (s1);
p += 3; // free (s2);
break; // free (s3);
case lq_chat_add_user: // p += 4;
tgl_do_add_user_to_chat (TLS, ((tgl_peer_t *)lua_ptr[p + 1])->id, ((tgl_peer_t *)lua_ptr[p + 2])->id, 10, lua_msg_cb, lua_ptr[p]); // break;
p += 3; // case lq_del_contact:
break; // tgl_do_del_contact (TLS, ((tgl_peer_t *)lua_ptr[p + 1])->id, lua_empty_cb, lua_ptr[p]);
case lq_chat_del_user: // p += 2;
tgl_do_del_user_from_chat (TLS, ((tgl_peer_t *)lua_ptr[p + 1])->id, ((tgl_peer_t *)lua_ptr[p + 2])->id, lua_msg_cb, lua_ptr[p]); // break;
p += 3; // case lq_rename_contact:
break; // s1 = lua_ptr[p + 1];
case lq_add_contact: // s2 = lua_ptr[p + 2];
s1 = lua_ptr[p + 1]; // s3 = lua_ptr[p + 3];
s2 = lua_ptr[p + 2]; // tgl_do_add_contact (TLS, s1, strlen (s1), s2, strlen (s2), s3, strlen (s3), 1, lua_contact_list_cb, lua_ptr[p]);
s3 = lua_ptr[p + 3]; // free (s1);
tgl_do_add_contact (TLS, s1, strlen (s1), s2, strlen (s2), s3, strlen (s3), 0, lua_contact_list_cb, lua_ptr[p]); // free (s2);
free (s1); // free (s3);
free (s2); // p += 4;
free (s3); // break;
p += 4; // case lq_search:
break; // s = lua_ptr[p + 2];
case lq_del_contact: // tgl_do_msg_search (TLS, ((tgl_peer_t *)lua_ptr[p + 1])->id, 0, 0, 40, 0, s, lua_msg_list_cb, lua_ptr[p]);
tgl_do_del_contact (TLS, ((tgl_peer_t *)lua_ptr[p + 1])->id, lua_empty_cb, lua_ptr[p]); // free (s);
p += 2; // p += 3;
break; // break;
case lq_rename_contact: // case lq_global_search:
s1 = lua_ptr[p + 1]; // s = lua_ptr[p + 1];
s2 = lua_ptr[p + 2]; // tgl_do_msg_search (TLS, tgl_set_peer_id (TGL_PEER_UNKNOWN, 0), 0, 0, 40, 0, s, lua_msg_list_cb, lua_ptr[p]);
s3 = lua_ptr[p + 3]; // free (s);
tgl_do_add_contact (TLS, s1, strlen (s1), s2, strlen (s2), s3, strlen (s3), 1, lua_contact_list_cb, lua_ptr[p]); // p += 2;
free (s1); // break;
free (s2); // case lq_mark_read:
free (s3); // tgl_do_mark_read (TLS, ((tgl_peer_t *)lua_ptr[p + 1])->id, lua_empty_cb, lua_ptr[p]);
p += 4; // p += 2;
break; // break;
case lq_search: // case lq_set_profile_photo:
s = lua_ptr[p + 2]; // s = lua_ptr[p + 1];
tgl_do_msg_search (TLS, ((tgl_peer_t *)lua_ptr[p + 1])->id, 0, 0, 40, 0, s, lua_msg_list_cb, lua_ptr[p]); // tgl_do_set_profile_photo (TLS, s, lua_empty_cb, lua_ptr[p]);
free (s); // free (s);
p += 3; // p += 2;
break; // break;
case lq_global_search: // case lq_set_profile_name:
s = lua_ptr[p + 1]; // s1 = lua_ptr[p + 1];
tgl_do_msg_search (TLS, tgl_set_peer_id (TGL_PEER_UNKNOWN, 0), 0, 0, 40, 0, s, lua_msg_list_cb, lua_ptr[p]); // s2 = lua_ptr[p + 1];
free (s); // tgl_do_set_profile_name (TLS, s1, s2, lua_user_cb, lua_ptr[p]);
p += 2; // free (s1);
break; // free (s2);
case lq_mark_read: // p += 3;
tgl_do_mark_read (TLS, ((tgl_peer_t *)lua_ptr[p + 1])->id, lua_empty_cb, lua_ptr[p]); // break;
p += 2; // case lq_create_secret_chat:
break; // tgl_do_create_secret_chat (TLS, ((tgl_peer_t *)lua_ptr[p + 1])->id, lua_secret_chat_cb, lua_ptr[p]);
case lq_set_profile_photo: // p += 2;
s = lua_ptr[p + 1]; // break;
tgl_do_set_profile_photo (TLS, s, lua_empty_cb, lua_ptr[p]); // case lq_create_group_chat:
free (s); // s = lua_ptr[p + 2];
p += 2; // tgl_do_create_group_chat (TLS, ((tgl_peer_t *)lua_ptr[p + 1])->id, s, lua_msg_cb, lua_ptr[p]);
break; // free (s);
case lq_set_profile_name: // p += 3;
s1 = lua_ptr[p + 1]; // break;
s2 = lua_ptr[p + 1]; // case lq_delete_msg:
tgl_do_set_profile_name (TLS, s1, s2, lua_user_cb, lua_ptr[p]); // tgl_do_delete_msg (TLS, ((struct tgl_message *)lua_ptr[p + 1])->id, lua_empty_cb, lua_ptr[p]);
free (s1); // p += 2;
free (s2); // break;
p += 3; // case lq_restore_msg:
break; // tgl_do_delete_msg (TLS, (long)lua_ptr[p + 1], lua_empty_cb, lua_ptr[p]);
case lq_create_secret_chat: // p += 2;
tgl_do_create_secret_chat (TLS, ((tgl_peer_t *)lua_ptr[p + 1])->id, lua_secret_chat_cb, lua_ptr[p]); // break;
p += 2; // case lq_accept_secret_chat:
break; // tgl_do_accept_encr_chat_request (TLS, lua_ptr[p + 1], lua_secret_chat_cb, lua_ptr[p]);
case lq_create_group_chat: // p += 2;
s = lua_ptr[p + 2]; // break;
tgl_do_create_group_chat (TLS, ((tgl_peer_t *)lua_ptr[p + 1])->id, s, lua_msg_cb, lua_ptr[p]); // case lq_send_contact:
free (s); // s1 = lua_ptr[p + 2];
p += 3; // s2 = lua_ptr[p + 3];
break; // s3 = lua_ptr[p + 4];
case lq_delete_msg: // tgl_do_send_contact (TLS, ((tgl_peer_t *)lua_ptr[p + 1])->id, s1, strlen (s1), s2, strlen (s2), s3, strlen (s3), lua_msg_cb, lua_ptr[p]);
tgl_do_delete_msg (TLS, ((struct tgl_message *)lua_ptr[p + 1])->id, lua_empty_cb, lua_ptr[p]); // free (s1);
p += 2; // free (s2);
break; // free (s3);
case lq_restore_msg: // p += 5;
tgl_do_delete_msg (TLS, (long)lua_ptr[p + 1], lua_empty_cb, lua_ptr[p]); // break;
p += 2; // case lq_status_online:
break; // tgl_do_update_status (TLS, 1, lua_empty_cb, lua_ptr[p]);
case lq_accept_secret_chat: // p ++;
tgl_do_accept_encr_chat_request (TLS, lua_ptr[p + 1], lua_secret_chat_cb, lua_ptr[p]); // break;
p += 2; // case lq_status_offline:
break; // tgl_do_update_status (TLS, 0, lua_empty_cb, lua_ptr[p]);
case lq_send_contact: // p ++;
s1 = lua_ptr[p + 2]; // break;
s2 = lua_ptr[p + 3]; // case lq_extf:
s3 = lua_ptr[p + 4]; // s = lua_ptr[p + 1];
tgl_do_send_contact (TLS, ((tgl_peer_t *)lua_ptr[p + 1])->id, s1, strlen (s1), s2, strlen (s2), s3, strlen (s3), lua_msg_cb, lua_ptr[p]); // tgl_do_send_extf (TLS, s, strlen (s), lua_str_cb, lua_ptr[p]);
free (s1); // free (s);
free (s2); // p += 2;
free (s3); // break;
p += 5; // case lq_send_location:
break; // if (sizeof (void *) == 4) {
case lq_status_online: // tgl_do_send_location (TLS, ((tgl_peer_t *)lua_ptr[p + 1])->id , *(float *)(lua_ptr + p + 2), *(float *)(lua_ptr + p + 3), lua_msg_cb, lua_ptr[p]);
tgl_do_update_status (TLS, 1, lua_empty_cb, lua_ptr[p]); // } else {
p ++; // tgl_do_send_location (TLS, ((tgl_peer_t *)lua_ptr[p + 1])->id , *(double *)(lua_ptr + p + 2), *(double *)(lua_ptr + p + 3), lua_msg_cb, lua_ptr[p]);
break; // }
case lq_status_offline: // p += 4;
tgl_do_update_status (TLS, 0, lua_empty_cb, lua_ptr[p]); // break;
p ++; // /*
break; // lq_delete_msg,
case lq_extf: // lq_restore_msg,
s = lua_ptr[p + 1]; // case 0:
tgl_do_send_extf (TLS, s, strlen (s), lua_str_cb, lua_ptr[p]); // tgl_do_send_message (((tgl_peer_t *)lua_ptr[p])->id, lua_ptr[p + 1], strlen (lua_ptr[p + 1]), 0, 0);
free (s); // free (lua_ptr[p + 1]);
p += 2; // p += 2;
break; // break;
case lq_send_location: // case 1:
if (sizeof (void *) == 4) { // tgl_do_forward_message (((tgl_peer_t *)lua_ptr[p])->id, (long)lua_ptr[p + 1], 0, 0);
tgl_do_send_location (TLS, ((tgl_peer_t *)lua_ptr[p + 1])->id , *(float *)(lua_ptr + p + 2), *(float *)(lua_ptr + p + 3), lua_msg_cb, lua_ptr[p]); // p += 2;
} else { // break;
tgl_do_send_location (TLS, ((tgl_peer_t *)lua_ptr[p + 1])->id , *(double *)(lua_ptr + p + 2), *(double *)(lua_ptr + p + 3), lua_msg_cb, lua_ptr[p]); // case 2:
} // tgl_do_mark_read (((tgl_peer_t *)lua_ptr[p])->id, 0, 0);
p += 4; // p += 1;
break; // break;*/
/* // default:
lq_delete_msg, // assert (0);
lq_restore_msg, // }
case 0: // }
tgl_do_send_message (((tgl_peer_t *)lua_ptr[p])->id, lua_ptr[p + 1], strlen (lua_ptr[p + 1]), 0, 0); // pos = 0;
free (lua_ptr[p + 1]); //}
p += 2; //
break; //
case 1: //enum lua_function_param {
tgl_do_forward_message (((tgl_peer_t *)lua_ptr[p])->id, (long)lua_ptr[p + 1], 0, 0); // lfp_none,
p += 2; // lfp_peer,
break; // lfp_chat,
case 2: // lfp_user,
tgl_do_mark_read (((tgl_peer_t *)lua_ptr[p])->id, 0, 0); // lfp_secret_chat,
p += 1; // lfp_string,
break;*/ // lfp_number,
default: // lfp_positive_number,
assert (0); // lfp_nonnegative_number,
} // lfp_msg,
} // lfp_double
pos = 0; //};
} //
//struct lua_function {
// char *name;
enum lua_function_param { // enum lua_query_type type;
lfp_none, // enum lua_function_param params[10];
lfp_peer, //};
lfp_chat, //
lfp_user, //struct lua_function functions[] = {
lfp_secret_chat, // {"get_contact_list", lq_contact_list, { lfp_none }},
lfp_string, // {"get_dialog_list", lq_dialog_list, { lfp_none }},
lfp_number, // {"rename_chat", lq_rename_chat, { lfp_chat, lfp_string, lfp_none }},
lfp_positive_number, // {"send_msg", lq_msg, { lfp_peer, lfp_string, lfp_none }},
lfp_nonnegative_number, // {"send_typing", lq_send_typing, { lfp_peer, lfp_none }},
lfp_msg, // {"send_typing_abort", lq_send_typing_abort, { lfp_peer, lfp_none }},
lfp_double // {"send_photo", lq_send_photo, { lfp_peer, lfp_string, lfp_none }},
}; // {"send_video", lq_send_video, { lfp_peer, lfp_string, lfp_none }},
// {"send_audio", lq_send_audio, { lfp_peer, lfp_string, lfp_none }},
struct lua_function { // {"send_document", lq_send_document, { lfp_peer, lfp_string, lfp_none }},
char *name; // {"send_file", lq_send_file, { lfp_peer, lfp_string, lfp_none }},
enum lua_query_type type; // {"send_text", lq_send_text, { lfp_peer, lfp_string, lfp_none }},
enum lua_function_param params[10]; // {"chat_set_photo", lq_chat_set_photo, { lfp_chat, lfp_string, lfp_none }},
}; // {"load_photo", lq_load_photo, { lfp_msg, lfp_none }},
// {"load_video", lq_load_video, { lfp_msg, lfp_none }},
struct lua_function functions[] = { // {"load_video_thumb", lq_load_video_thumb, { lfp_msg, lfp_none }},
{"get_contact_list", lq_contact_list, { lfp_none }}, // {"load_audio", lq_load_audio, { lfp_msg, lfp_none }},
{"get_dialog_list", lq_dialog_list, { lfp_none }}, // {"load_document", lq_load_document, { lfp_msg, lfp_none }},
{"rename_chat", lq_rename_chat, { lfp_chat, lfp_string, lfp_none }}, // {"load_document_thumb", lq_load_document_thumb, { lfp_msg, lfp_none }},
{"send_msg", lq_msg, { lfp_peer, lfp_string, lfp_none }}, // {"fwd_msg", lq_fwd, { lfp_peer, lfp_msg, lfp_none }},
{"send_typing", lq_send_typing, { lfp_peer, lfp_none }}, // {"fwd_media", lq_fwd_media, { lfp_peer, lfp_msg, lfp_none }},
{"send_typing_abort", lq_send_typing_abort, { lfp_peer, lfp_none }}, // {"chat_info", lq_chat_info, { lfp_chat, lfp_none }},
{"send_photo", lq_send_photo, { lfp_peer, lfp_string, lfp_none }}, // {"user_info", lq_user_info, { lfp_user, lfp_none }},
{"send_video", lq_send_video, { lfp_peer, lfp_string, lfp_none }}, // {"get_history", lq_history, { lfp_peer, lfp_nonnegative_number, lfp_none }},
{"send_audio", lq_send_audio, { lfp_peer, lfp_string, lfp_none }}, // {"chat_add_user", lq_chat_add_user, { lfp_chat, lfp_user, lfp_none }},
{"send_document", lq_send_document, { lfp_peer, lfp_string, lfp_none }}, // {"chat_del_user", lq_chat_del_user, { lfp_chat, lfp_user, lfp_none }},
{"send_file", lq_send_file, { lfp_peer, lfp_string, lfp_none }}, // {"add_contact", lq_add_contact, { lfp_string, lfp_string, lfp_string, lfp_none }},
{"send_text", lq_send_text, { lfp_peer, lfp_string, lfp_none }}, // {"del_contact", lq_del_contact, { lfp_user, lfp_none }},
{"chat_set_photo", lq_chat_set_photo, { lfp_chat, lfp_string, lfp_none }}, // {"rename_contact", lq_rename_contact, { lfp_string, lfp_string, lfp_string, lfp_none }},
{"load_photo", lq_load_photo, { lfp_msg, lfp_none }}, // {"msg_search", lq_search, { lfp_peer, lfp_string, lfp_none }},
{"load_video", lq_load_video, { lfp_msg, lfp_none }}, // {"msg_global_search", lq_global_search, { lfp_string, lfp_none }},
{"load_video_thumb", lq_load_video_thumb, { lfp_msg, lfp_none }}, // {"mark_read", lq_mark_read, { lfp_peer, lfp_none }},
{"load_audio", lq_load_audio, { lfp_msg, lfp_none }}, // {"set_profile_photo", lq_set_profile_photo, { lfp_string, lfp_none }},
{"load_document", lq_load_document, { lfp_msg, lfp_none }}, // {"set_profile_name", lq_set_profile_name, { lfp_string, lfp_none }},
{"load_document_thumb", lq_load_document_thumb, { lfp_msg, lfp_none }}, // {"create_secret_chat", lq_create_secret_chat, { lfp_user, lfp_none }},
{"fwd_msg", lq_fwd, { lfp_peer, lfp_msg, lfp_none }}, // {"create_group_chat", lq_create_group_chat, { lfp_user, lfp_string, lfp_none }},
{"fwd_media", lq_fwd_media, { lfp_peer, lfp_msg, lfp_none }}, // {"delete_msg", lq_delete_msg, { lfp_msg, lfp_none }},
{"chat_info", lq_chat_info, { lfp_chat, lfp_none }}, // {"restore_msg", lq_restore_msg, { lfp_positive_number, lfp_none }},
{"user_info", lq_user_info, { lfp_user, lfp_none }}, // {"accept_secret_chat", lq_accept_secret_chat, { lfp_secret_chat, lfp_none }},
{"get_history", lq_history, { lfp_peer, lfp_nonnegative_number, lfp_none }}, // {"send_contact", lq_send_contact, { lfp_peer, lfp_string, lfp_string, lfp_string, lfp_none }},
{"chat_add_user", lq_chat_add_user, { lfp_chat, lfp_user, lfp_none }}, // {"status_online", lq_status_online, { lfp_none }},
{"chat_del_user", lq_chat_del_user, { lfp_chat, lfp_user, lfp_none }}, // {"status_offline", lq_status_offline, { lfp_none }},
{"add_contact", lq_add_contact, { lfp_string, lfp_string, lfp_string, lfp_none }}, // {"send_location", lq_send_location, { lfp_peer, lfp_double, lfp_double, lfp_none }},
{"del_contact", lq_del_contact, { lfp_user, lfp_none }}, // {"ext_function", lq_extf, { lfp_string, lfp_none }},
{"rename_contact", lq_rename_contact, { lfp_string, lfp_string, lfp_string, lfp_none }}, // { 0, 0, { lfp_none}}
{"msg_search", lq_search, { lfp_peer, lfp_string, lfp_none }}, //};
{"msg_global_search", lq_global_search, { lfp_string, lfp_none }}, //
{"mark_read", lq_mark_read, { lfp_peer, lfp_none }}, //static int parse_lua_function (lua_State *L, struct lua_function *F) {
{"set_profile_photo", lq_set_profile_photo, { lfp_string, lfp_none }}, // int p = 0;
{"set_profile_name", lq_set_profile_name, { lfp_string, lfp_none }}, // while (F->params[p] != lfp_none) { p ++; }
{"create_secret_chat", lq_create_secret_chat, { lfp_user, lfp_none }}, // if (lua_gettop (L) != p + 2) {
{"create_group_chat", lq_create_group_chat, { lfp_user, lfp_string, lfp_none }}, // lua_pushboolean (L, 0);
{"delete_msg", lq_delete_msg, { lfp_msg, lfp_none }}, // return 1;
{"restore_msg", lq_restore_msg, { lfp_positive_number, lfp_none }}, // }
{"accept_secret_chat", lq_accept_secret_chat, { lfp_secret_chat, lfp_none }}, //
{"send_contact", lq_send_contact, { lfp_peer, lfp_string, lfp_string, lfp_string, lfp_none }}, // int a1 = luaL_ref (L, LUA_REGISTRYINDEX);
{"status_online", lq_status_online, { lfp_none }}, // int a2 = luaL_ref (L, LUA_REGISTRYINDEX);
{"status_offline", lq_status_offline, { lfp_none }}, //
{"send_location", lq_send_location, { lfp_peer, lfp_double, lfp_double, lfp_none }}, // struct lua_query_extra *e = malloc (sizeof (*e));
{"ext_function", lq_extf, { lfp_string, lfp_none }}, // assert (e);
{ 0, 0, { lfp_none}} // e->func = a2;
}; // e->param = a1;
//
static int parse_lua_function (lua_State *L, struct lua_function *F) { // assert (pos + 3 + p < MAX_LUA_COMMANDS);
int p = 0; //
while (F->params[p] != lfp_none) { p ++; } // lua_ptr[pos ++] = (void *)(long)(p + 1);
if (lua_gettop (L) != p + 2) { // lua_ptr[pos ++] = (void *)(long)F->type;
lua_pushboolean (L, 0); // lua_ptr[pos ++] = e;
return 1; //
} // int sp = p;
// int ok = 1;
int a1 = luaL_ref (L, LUA_REGISTRYINDEX); // int cc = 0;
int a2 = luaL_ref (L, LUA_REGISTRYINDEX); // while (p > 0) {
// p --;
struct lua_query_extra *e = malloc (sizeof (*e)); // cc ++;
assert (e); // const char *s;
e->func = a2; // tgl_peer_t *P;
e->param = a1; // long long num;
// double dval;
assert (pos + 3 + p < MAX_LUA_COMMANDS); // struct tgl_message *M;
// switch (F->params[p]) {
lua_ptr[pos ++] = (void *)(long)(p + 1); // case lfp_none:
lua_ptr[pos ++] = (void *)(long)F->type; // assert (0);
lua_ptr[pos ++] = e; // break;
// case lfp_peer:
int sp = p; // case lfp_user:
int ok = 1; // case lfp_chat:
int cc = 0; // case lfp_secret_chat:
while (p > 0) { // s = lua_tostring (L, -cc);
p --; // if (!s) {
cc ++; // ok = 0;
const char *s; // break;
tgl_peer_t *P; // }
long long num; // if (sscanf (s, "user#id%lld", &num) == 1 && num > 0) {
double dval; // tgl_insert_empty_user (TLS, num);
struct tgl_message *M; // P = tgl_peer_get (TLS, TGL_MK_USER (num));
switch (F->params[p]) { // } else if (sscanf (s, "chat#id%lld", &num) == 1 && num > 0) {
case lfp_none: // tgl_insert_empty_chat (TLS, num);
assert (0); // P = tgl_peer_get (TLS, TGL_MK_CHAT (num));
break; // } else {
case lfp_peer: // P = get_peer (s);
case lfp_user: // }
case lfp_chat: // if (!P/* || !(P->flags & FLAG_CREATED)*/) {
case lfp_secret_chat: // ok = 0;
s = lua_tostring (L, -cc); // break;
if (!s) { // }
ok = 0; // if (F->params[p] != lfp_peer) {
break; // if ((tgl_get_peer_type (P->id) == TGL_PEER_USER && F->params[p] != lfp_user) ||
} // (tgl_get_peer_type (P->id) == TGL_PEER_CHAT && F->params[p] != lfp_chat) ||
if (sscanf (s, "user#id%lld", &num) == 1 && num > 0) { // (tgl_get_peer_type (P->id) == TGL_PEER_ENCR_CHAT && F->params[p] != lfp_secret_chat)) {
tgl_insert_empty_user (TLS, num); // ok = 0;
P = tgl_peer_get (TLS, TGL_MK_USER (num)); // break;
} else if (sscanf (s, "chat#id%lld", &num) == 1 && num > 0) { // }
tgl_insert_empty_chat (TLS, num); // }
P = tgl_peer_get (TLS, TGL_MK_CHAT (num)); // lua_ptr[pos + p] = P;
} else { // break;
P = get_peer (s); //
} // case lfp_string:
if (!P/* || !(P->flags & FLAG_CREATED)*/) { // s = lua_tostring (L, -cc);
ok = 0; // if (!s) {
break; // ok = 0;
} // break;
if (F->params[p] != lfp_peer) { // }
if ((tgl_get_peer_type (P->id) == TGL_PEER_USER && F->params[p] != lfp_user) || // lua_ptr[pos + p] = (void *)s;
(tgl_get_peer_type (P->id) == TGL_PEER_CHAT && F->params[p] != lfp_chat) || // break;
(tgl_get_peer_type (P->id) == TGL_PEER_ENCR_CHAT && F->params[p] != lfp_secret_chat)) { //
ok = 0; // case lfp_number:
break; // num = lua_tonumber (L, -cc);
} //
} // lua_ptr[pos + p] = (void *)(long)num;
lua_ptr[pos + p] = P; // break;
break; //
// case lfp_double:
case lfp_string: // dval = lua_tonumber (L, -cc);
s = lua_tostring (L, -cc); //
if (!s) { // if (sizeof (void *) == 4) {
ok = 0; // *(float *)(lua_ptr + pos + p) = dval;
break; // } else {
} // assert (sizeof (void *) >= 8);
lua_ptr[pos + p] = (void *)s; // *(double *)(lua_ptr + pos + p) = dval;
break; // }
// break;
case lfp_number: //
num = lua_tonumber (L, -cc); // case lfp_positive_number:
// num = lua_tonumber (L, -cc);
lua_ptr[pos + p] = (void *)(long)num; // if (num <= 0) {
break; // ok = 0;
// break;
case lfp_double: // }
dval = lua_tonumber (L, -cc); //
// lua_ptr[pos + p] = (void *)(long)num;
if (sizeof (void *) == 4) { // break;
*(float *)(lua_ptr + pos + p) = dval; //
} else { // case lfp_nonnegative_number:
assert (sizeof (void *) >= 8); // num = lua_tonumber (L, -cc);
*(double *)(lua_ptr + pos + p) = dval; // if (num < 0) {
} // ok = 0;
break; // break;
// }
case lfp_positive_number: //
num = lua_tonumber (L, -cc); // lua_ptr[pos + p] = (void *)(long)num;
if (num <= 0) { // break;
ok = 0; //
break; // case lfp_msg:
} // s = lua_tostring (L, -cc);
// if (!s || !strlen (s)) {
lua_ptr[pos + p] = (void *)(long)num; // ok = 0;
break; // break;
// }
case lfp_nonnegative_number: //
num = lua_tonumber (L, -cc); // num = atoll (s);
if (num < 0) { //
ok = 0; // M = tgl_message_get (TLS, num);
break; //
} // if (!M || !(M->flags & FLAG_CREATED)) {
// ok = 0;
lua_ptr[pos + p] = (void *)(long)num; // break;
break; // }
//
case lfp_msg: // lua_ptr[pos + p] = M;
s = lua_tostring (L, -cc); // break;
if (!s || !strlen (s)) { //
ok = 0; // default:
break; // assert (0);
} // }
// }
num = atoll (s); // if (!ok) {
// luaL_unref (luaState, LUA_REGISTRYINDEX, a1);
M = tgl_message_get (TLS, num); // luaL_unref (luaState, LUA_REGISTRYINDEX, a2);
// free (e);
if (!M || !(M->flags & FLAG_CREATED)) { // pos -= 3;
ok = 0; // lua_pushboolean (L, 0);
break; // return 1;
} // }
//
lua_ptr[pos + p] = M; // for (p = 0; p < sp; p++) {
break; // if (F->params[p] == lfp_string) {
// lua_ptr[pos + p] = strdup (lua_ptr[pos + p]);
default: // }
assert (0); // }
} // pos += p;
} //
if (!ok) { // lua_pushboolean (L, 1);
luaL_unref (luaState, LUA_REGISTRYINDEX, a1); // return 1;
luaL_unref (luaState, LUA_REGISTRYINDEX, a2); //}
free (e); //
pos -= 3; //
lua_pushboolean (L, 0); //static void lua_postpone_alarm (evutil_socket_t fd, short what, void *arg) {
return 1; // int *t = arg;
} //
// lua_settop (luaState, 0);
for (p = 0; p < sp; p++) { // //lua_checkstack (luaState, 20);
if (F->params[p] == lfp_string) { // my_lua_checkstack (luaState, 20);
lua_ptr[pos + p] = strdup (lua_ptr[pos + p]); //
} // lua_rawgeti (luaState, LUA_REGISTRYINDEX, t[1]);
} // lua_rawgeti (luaState, LUA_REGISTRYINDEX, t[0]);
pos += p; // assert (lua_gettop (luaState) == 2);
//
lua_pushboolean (L, 1); // int r = lua_pcall (luaState, 1, 0, 0);
return 1; //
} // luaL_unref (luaState, LUA_REGISTRYINDEX, t[0]);
// luaL_unref (luaState, LUA_REGISTRYINDEX, t[1]);
//
static void lua_postpone_alarm (evutil_socket_t fd, short what, void *arg) { // if (r) {
int *t = arg; // logprintf ("lua: %s\n", lua_tostring (luaState, -1));
// }
lua_settop (luaState, 0); //
//lua_checkstack (luaState, 20); //}
my_lua_checkstack (luaState, 20); //
//static int postpone_from_lua (lua_State *L) {
lua_rawgeti (luaState, LUA_REGISTRYINDEX, t[1]); // int n = lua_gettop (L);
lua_rawgeti (luaState, LUA_REGISTRYINDEX, t[0]); // if (n != 3) {
assert (lua_gettop (luaState) == 2); // lua_pushboolean (L, 0);
// return 1;
int r = lua_pcall (luaState, 1, 0, 0); // }
//
luaL_unref (luaState, LUA_REGISTRYINDEX, t[0]); // double timeout = lua_tonumber (L, -1);
luaL_unref (luaState, LUA_REGISTRYINDEX, t[1]); // if (timeout < 0) {
// lua_pushboolean (L, 0);
if (r) { // return 1;
logprintf ("lua: %s\n", lua_tostring (luaState, -1)); // }
} //
// lua_pop (L, 1);
} // int a1 = luaL_ref (L, LUA_REGISTRYINDEX);
// int a2 = luaL_ref (L, LUA_REGISTRYINDEX);
static int postpone_from_lua (lua_State *L) { //
int n = lua_gettop (L); //
if (n != 3) { // int *t = malloc (16);
lua_pushboolean (L, 0); // assert (t);
return 1; // struct event *ev = evtimer_new (TLS->ev_base, lua_postpone_alarm, t);
} // t[0] = a1;
// t[1] = a2;
double timeout = lua_tonumber (L, -1); // *(void **)(t + 2) = ev;
if (timeout < 0) { //
lua_pushboolean (L, 0); // struct timeval ts= {
return 1; // .tv_sec = (long)timeout,
} // .tv_usec = (timeout - ((long)timeout)) * 1000000
// };
lua_pop (L, 1); // event_add (ev, &ts);
int a1 = luaL_ref (L, LUA_REGISTRYINDEX); //
int a2 = luaL_ref (L, LUA_REGISTRYINDEX); // lua_pushboolean (L, 1);
// return 1;
//}
int *t = malloc (16); //
assert (t); //extern int safe_quit;
struct event *ev = evtimer_new (TLS->ev_base, lua_postpone_alarm, t); //static int safe_quit_from_lua (lua_State *L) {
t[0] = a1; // int n = lua_gettop (L);
t[1] = a2; // if (n != 0) {
*(void **)(t + 2) = ev; // lua_pushboolean (L, 0);
// return 1;
struct timeval ts= { // }
.tv_sec = (long)timeout, // safe_quit = 1;
.tv_usec = (timeout - ((long)timeout)) * 1000000 //
}; // lua_pushboolean (L, 1);
event_add (ev, &ts); // return 1;
//}
lua_pushboolean (L, 1); //
return 1; //static int universal_from_lua (lua_State *L) {
} // const char *s = lua_tostring(L, lua_upvalueindex(1));
// if (!s) {
extern int safe_quit; // lua_pushboolean (L, 0);
static int safe_quit_from_lua (lua_State *L) { // return 1;
int n = lua_gettop (L); // }
if (n != 0) { // int i = 0;
lua_pushboolean (L, 0); // while (functions[i].name) {
return 1; // if (!strcmp (functions[i].name, s)) {
} // return parse_lua_function (L, &functions[i]);
safe_quit = 1; // }
// i ++;
lua_pushboolean (L, 1); // }
return 1; // lua_pushboolean (L, 0);
} // return 1;
//}
static int universal_from_lua (lua_State *L) { //
const char *s = lua_tostring(L, lua_upvalueindex(1)); //
if (!s) { //static void my_python_register (const char *name, lua_CFunction f) {
lua_pushboolean (L, 0); // lua_pushstring(L, name);
return 1; // lua_pushcclosure(L, f, 1);
} // lua_setglobal(L, name);
int i = 0; //}
while (functions[i].name) { //
if (!strcmp (functions[i].name, s)) { //
return parse_lua_function (L, &functions[i]);
}
i ++;
}
lua_pushboolean (L, 0);
return 1;
}
static void my_python_register (const char *name, lua_CFunction f) {
lua_pushstring(L, name);
lua_pushcclosure(L, f, 1);
lua_setglobal(L, name);
}
void py_init (const char *file) { void py_init (const char *file) {
if (!file) { return; } if (!file) { return; }
have_file = 1; have_file = 1;
PyObject *pName, *pModule; // PyObject *pName;//, *pModule;
Py_Initialize() Py_Initialize();
pName = PyFile_FromFile(file, "telegram.py", 'r', null); // pName = PyFile_FromFile(file, "telegram.py", 'r', null);
err = PyErr_Occurred(); // PyObject* err = PyErr_Occurred();
if (err != NULL) { // if (err != NULL) {
logprintf("python error occurred"); // TODO: implement the backtrace // logprintf("python error occurred"); // TODO: implement the backtrace
exit(1); // exit(1);
} // }
int i = 0; // int i = 0;
while (functions[i].name) { // while (functions[i].name) {
my_lua_register (luaState, functions[i].name, universal_from_lua); // my_lua_register (luaState, functions[i].name, universal_from_lua);
i ++; // i ++;
} // }
//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); //lua_register (luaState, "mark_read", mark_read_from_lua);
lua_register (luaState, "postpone", postpone_from_lua); // lua_register (luaState, "postpone", postpone_from_lua);
lua_register (luaState, "safe_quit", safe_quit_from_lua); // lua_register (luaState, "safe_quit", safe_quit_from_lua);
//lua_register (luaState, "get_contact_list", get_contacts_from_lua); //lua_register (luaState, "get_contact_list", get_contacts_from_lua);
/*lua_register (luaState, "get_dialog_list", get_dialog_list_from_lua); /*lua_register (luaState, "get_dialog_list", get_dialog_list_from_lua);
lua_register (luaState, "send_msg", send_msg_from_lua); lua_register (luaState, "send_msg", send_msg_from_lua);
...@@ -1487,11 +1486,6 @@ void py_init (const char *file) { ...@@ -1487,11 +1486,6 @@ void py_init (const char *file) {
lua_register (luaState, "add_contact", add_contact_from_lua); lua_register (luaState, "add_contact", add_contact_from_lua);
lua_register (luaState, "rename_contact", rename_contact_from_lua);*/ lua_register (luaState, "rename_contact", rename_contact_from_lua);*/
int ret = luaL_dofile (luaState, file);
if (ret) {
logprintf ("lua: %s\n", lua_tostring (luaState, -1));
exit (1);
}
} }
#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