From c4a9d000cea380ab31df8dbb42fa14d75f8c0dc2 Mon Sep 17 00:00:00 2001 From: Rui Guo Date: Wed, 19 Aug 2009 01:27:58 +0800 Subject: [PATCH] Get rid of some codes that no longer needed. --- src/lua.c | 42 ++++++------------------------------------ 1 file changed, 6 insertions(+), 36 deletions(-) diff --git a/src/lua.c b/src/lua.c index 5538d43..b69f2e3 100644 --- a/src/lua.c +++ b/src/lua.c @@ -1057,18 +1057,11 @@ screen_append_msg(lua_State *L) return 0; } -struct sinput_data -{ - lua_State *L; - lua_handler lh; -}; - void script_input_fn(char *buf, int len, char *priv) { - struct sinput_data *sidata = (struct sinput_data *)priv; - lua_handler lh = sidata->lh; - lua_State *L = sidata->L; + lua_handler lh = (lua_handler)priv; + lua_State *L = lh->L; LuaPushHandler(lh); lua_pushstring(L, buf); @@ -1079,7 +1072,6 @@ script_input_fn(char *buf, int len, char *priv) LuaShowErr(L); } } - free(sidata); LuaFreeHandler(L, &lh); } @@ -1090,7 +1082,6 @@ screen_input(lua_State *L) int n; const char * prompt = NULL, *prefill = NULL; lua_handler lh; - struct sinput_data *sidata; prompt = luaL_checkstring(L, 1); lh = LuaCheckHandler(L, 2, 1); @@ -1101,16 +1092,7 @@ screen_input(lua_State *L) prefill = luaL_checkstring(L, 3); - sidata = (struct sinput_data *)malloc(sizeof(struct sinput_data)); - if (!sidata) - { - LuaFreeHandler(L, &lh); - luaL_error(L, "Out of Memory"); - } - - sidata->L = L; - sidata->lh = lh; - Input((char *)prompt, 100, INP_COOKED, script_input_fn, (char *)sidata, 0); + Input((char *)prompt, 100, INP_COOKED, script_input_fn, (char *)lh, 0); if (!prefill) return 0; @@ -1128,10 +1110,8 @@ screen_input(lua_State *L) static void sev_schedule_fn(struct event *ev, char *data) { - struct sinput_data *si = (struct sinput_data *)data; - lua_handler lh = si->lh; - lua_State *L = si->L; - free(si); + lua_handler lh = (lua_handler)data; + lua_State *L = lh->L; evdeq(ev); Free(ev); @@ -1151,7 +1131,6 @@ screen_schedule(lua_State *L) { int timeout = luaL_checkinteger(L, 1); lua_handler lh = LuaCheckHandler(L, 2, 1); - struct sinput_data *si; struct event *ev; if (timeout <= 0) return 0; @@ -1162,18 +1141,9 @@ screen_schedule(lua_State *L) LuaFreeHandler(L, &lh); luaL_error(L, "Out of Memory"); } - si = (struct sinput_data *) malloc(sizeof(struct sinput_data)); - if (!si) - { - LuaFreeHandler(L, &lh); - Free(ev); - luaL_error(L, "Out of Memory"); - } - si->lh = lh; - si->L = L; ev->type = EV_TIMEOUT; - ev->data = (char *)si; + ev->data = (char *)lh; ev->handler = sev_schedule_fn; evenq(ev); SetTimeout(ev, timeout * 1000); -- 2.11.4.GIT