From b5e9e2a7bc2bc9cc5da8d1f7d301bdee3663fba6 Mon Sep 17 00:00:00 2001 From: takase1121 <20792268+takase1121@users.noreply.github.com> Date: Wed, 23 Jun 2021 18:21:36 +0800 Subject: [PATCH] refactor process.c - include api.h instead of individual #includes - moved metatable name to API_TYPE_PROCESS - moved read buffer size to READ_BUF_SIZE --- src/api/api.h | 1 + src/api/process.c | 16 ++++++++-------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/api/api.h b/src/api/api.h index 4b0e14f0..51ebb9a8 100644 --- a/src/api/api.h +++ b/src/api/api.h @@ -7,6 +7,7 @@ #define API_TYPE_FONT "Font" #define API_TYPE_REPLACE "Replace" +#define API_TYPE_PROCESS "Process" void api_load_libs(lua_State *L); diff --git a/src/api/process.c b/src/api/process.c index 57c74d5c..3726bef3 100644 --- a/src/api/process.c +++ b/src/api/process.c @@ -5,12 +5,12 @@ */ #include -#include -#include -#include -#include #include #include +#include +#include "api.h" + +#define READ_BUF_SIZE 4096 typedef struct { reproc_t * process; @@ -29,7 +29,7 @@ static int process_new(lua_State* L) self->process = NULL; self->L = L; - luaL_getmetatable(L, "PROCESS"); + luaL_getmetatable(L, API_TYPE_PROCESS); lua_setmetatable(L, -2); return 1; @@ -53,7 +53,7 @@ static int process_strerror(lua_State* L) static int process_gc(lua_State* L) { - process_t* self = (process_t*) luaL_checkudata(L, 1, "PROCESS"); + process_t* self = (process_t*) luaL_checkudata(L, 1, API_TYPE_PROCESS); if(self->process){ reproc_kill(self->process); @@ -145,7 +145,7 @@ static int process_read(lua_State* L) process_t* self = (process_t*) lua_touserdata(L, 1); if(self->process){ - int read_size = 4096; + int read_size = READ_BUF_SIZE; if (lua_type(L, 2) == LUA_TNUMBER){ read_size = (int) lua_tonumber(L, 2); } @@ -401,7 +401,7 @@ static const struct luaL_Reg process[] = { int luaopen_process(lua_State *L) { - luaL_newmetatable(L, "PROCESS"); + luaL_newmetatable(L, API_TYPE_PROCESS); luaL_setfuncs(L, process_methods, 0); lua_pushvalue(L, -1); lua_setfield(L, -2, "__index");