diff options
| author | ruki <[email protected]> | 2019-08-17 00:49:06 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2019-08-16 22:54:38 +0800 |
| commit | 1de49ce846981a065ce3bea73591b797718ae993 (patch) | |
| tree | 30f6332a3b94e112f7e8ef7e0c9d38e72e5dde81 /core/src/xmake/process/prefix.h | |
| parent | 3edf63549fd45db761e09452b9b1af2ce23ee751 (diff) | |
add subprocess
Diffstat (limited to 'core/src/xmake/process/prefix.h')
| -rw-r--r-- | core/src/xmake/process/prefix.h | 80 |
1 files changed, 78 insertions, 2 deletions
diff --git a/core/src/xmake/process/prefix.h b/core/src/xmake/process/prefix.h index becbb93e6..2b0fec706 100644 --- a/core/src/xmake/process/prefix.h +++ b/core/src/xmake/process/prefix.h @@ -1,7 +1,7 @@ /*!A cross-platform build utility based on Lua * * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. + * you may not use this subprocess except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 @@ -15,7 +15,7 @@ * Copyright (C) 2015 - 2019, TBOOX Open Source Group. * * @author ruki - * @file prefix.h + * @subprocess prefix.h * */ #ifndef XM_PROCESS_PREFIX_H @@ -26,6 +26,82 @@ */ #include "../prefix.h" +/* ////////////////////////////////////////////////////////////////////////////////////// + * macross + */ + +// the subprocess udata type +#define xm_subprocess_udata "process._subprocess*" + +// return lock success +#define xm_subprocess_return_success() do { return 1; } while (0) + +// return lock error with reason +#define xm_subprocess_return_error(lua, subprocess, reason) \ + do \ + { \ + lua_pushnil(lua); \ + lua_pushfstring(lua, "error: %s (%s)", reason, subprocess->name); \ + return 2; \ + } while (0) + +// return closed error +#define xm_subprocess_return_error_closed(lua) \ + do \ + { \ + lua_pushnil(lua); \ + lua_pushliteral(lua, "error: subprocess has been closed"); \ + return 2; \ + } while (0) + +/* ////////////////////////////////////////////////////////////////////////////////////// + * types + */ + +// the subprocess type +typedef struct __xm_subprocess_t +{ + // the process reference + tb_process_ref_t process; + + // is opened? + tb_bool_t is_opened; + + // the process name + tb_char_t name[32]; + +} xm_subprocess_t; + +/* ////////////////////////////////////////////////////////////////////////////////////// + * interfaces + */ +static __tb_inline__ xm_subprocess_t* xm_subprocess_new(lua_State* lua) +{ + // check + tb_assert_and_check_return_val(lua, tb_null); + + // new subprocess + xm_subprocess_t* subprocess = (xm_subprocess_t*)lua_newuserdata(lua, sizeof(xm_subprocess_t)); + tb_assert_and_check_return_val(subprocess, tb_null); + + // init subprocess + luaL_getmetatable(lua, xm_subprocess_udata); + lua_setmetatable(lua, -2); + tb_memset(subprocess, 0, sizeof(xm_subprocess_t)); + return subprocess; +} + +static __tb_inline__ xm_subprocess_t* xm_subprocess_get(lua_State* lua) +{ + // check + tb_assert_and_check_return_val(lua, tb_null); + + // get subprocess + xm_subprocess_t* subprocess = (xm_subprocess_t*)luaL_checkudata(lua, 1, xm_subprocess_udata); + tb_assert(subprocess); + return subprocess; +} + #endif |
