Add lua script option to menu items
This commit is contained in:
parent
e79e84dd76
commit
0ae80564fd
1
bbs.h
1
bbs.h
@ -297,6 +297,7 @@ extern void next_file_sub(struct user_record *user);
|
|||||||
extern void prev_file_sub(struct user_record *user);
|
extern void prev_file_sub(struct user_record *user);
|
||||||
|
|
||||||
extern void lua_push_cfunctions(lua_State *L);
|
extern void lua_push_cfunctions(lua_State *L);
|
||||||
|
extern void do_lua_script(char *script);
|
||||||
|
|
||||||
extern void bwave_create_packet();
|
extern void bwave_create_packet();
|
||||||
extern void bwave_upload_reply();
|
extern void bwave_upload_reply();
|
||||||
|
21
lua_glue.c
21
lua_glue.c
@ -180,3 +180,24 @@ void lua_push_cfunctions(lua_State *L) {
|
|||||||
lua_pushcfunction(L, l_getBBSInfo);
|
lua_pushcfunction(L, l_getBBSInfo);
|
||||||
lua_setglobal(L, "bbs_get_info");
|
lua_setglobal(L, "bbs_get_info");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void do_lua_script(char *script) {
|
||||||
|
lua_State *L;
|
||||||
|
char buffer[PATH_MAX];
|
||||||
|
|
||||||
|
if (script == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (script[0] == '/') {
|
||||||
|
snprintf(buffer, PATH_MAX, "%s.lua", script);
|
||||||
|
} else {
|
||||||
|
snprintf(buffer, PATH_MAX, "%s/%s.lua", conf.script_path, script);
|
||||||
|
}
|
||||||
|
|
||||||
|
L = luaL_newstate();
|
||||||
|
luaL_openlibs(L);
|
||||||
|
lua_push_cfunctions(L);
|
||||||
|
luaL_dofile(L, buffer);
|
||||||
|
lua_close(L);
|
||||||
|
}
|
8
menus.c
8
menus.c
@ -43,6 +43,7 @@
|
|||||||
#define MENU_NEXTFILESUB 34
|
#define MENU_NEXTFILESUB 34
|
||||||
#define MENU_PREVFILESUB 35
|
#define MENU_PREVFILESUB 35
|
||||||
#define MENU_LISTMESSAGES 36
|
#define MENU_LISTMESSAGES 36
|
||||||
|
#define MENU_DOSCRIPT 37
|
||||||
|
|
||||||
extern struct bbs_config conf;
|
extern struct bbs_config conf;
|
||||||
extern struct user_record *gUser;
|
extern struct user_record *gUser;
|
||||||
@ -176,6 +177,8 @@ int menu_system(char *menufile) {
|
|||||||
menu[menu_items-1]->command = MENU_PREVFILESUB;
|
menu[menu_items-1]->command = MENU_PREVFILESUB;
|
||||||
} else if (strncasecmp(&buffer[8], "LISTMESSAGES", 12) == 0) {
|
} else if (strncasecmp(&buffer[8], "LISTMESSAGES", 12) == 0) {
|
||||||
menu[menu_items-1]->command = MENU_LISTMESSAGES;
|
menu[menu_items-1]->command = MENU_LISTMESSAGES;
|
||||||
|
} else if (strncasecmp(&buffer[8], "DOSCRIPT", 8) == 0) {
|
||||||
|
menu[menu_items-1]->command = MENU_DOSCRIPT;
|
||||||
}
|
}
|
||||||
} else if (strncasecmp(buffer, "DATA", 4) == 0) {
|
} else if (strncasecmp(buffer, "DATA", 4) == 0) {
|
||||||
menu[menu_items-1]->data = strdup(&buffer[5]);
|
menu[menu_items-1]->data = strdup(&buffer[5]);
|
||||||
@ -419,7 +422,10 @@ int menu_system(char *menufile) {
|
|||||||
break;
|
break;
|
||||||
case MENU_LISTMESSAGES:
|
case MENU_LISTMESSAGES:
|
||||||
list_messages(gUser);
|
list_messages(gUser);
|
||||||
break;
|
break;
|
||||||
|
case MENU_DOSCRIPT:
|
||||||
|
do_lua_script(menu[i]->data);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user