diff options
| author | ruki <[email protected]> | 2024-04-03 23:50:20 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2024-04-03 23:50:20 +0800 |
| commit | 70748de03539eec10aafb9cb78178c275d6e9b47 (patch) | |
| tree | 38d732ed34f3cef05616f270e427400b7247ebee /core/src/xmake/package | |
| parent | d08d95ac8fc9e1f316ff180aaedd61e21c384e24 (diff) | |
improve loadxmi
Diffstat (limited to 'core/src/xmake/package')
| -rw-r--r-- | core/src/xmake/package/loadxmi.c | 72 | ||||
| -rw-r--r-- | core/src/xmake/package/prefix.h | 32 |
2 files changed, 104 insertions, 0 deletions
diff --git a/core/src/xmake/package/loadxmi.c b/core/src/xmake/package/loadxmi.c new file mode 100644 index 000000000..fcbecf72b --- /dev/null +++ b/core/src/xmake/package/loadxmi.c @@ -0,0 +1,72 @@ +/*!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 obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Copyright (C) 2015-present, TBOOX Open Source Group. + * + * @author ruki + * @file loadxmi.c + * + */ + +/* ////////////////////////////////////////////////////////////////////////////////////// + * trace + */ +#define TB_TRACE_MODULE_NAME "loadxmi" +#define TB_TRACE_MODULE_DEBUG (0) + +/* ////////////////////////////////////////////////////////////////////////////////////// + * includes + */ +#include "prefix.h" + +/* ////////////////////////////////////////////////////////////////////////////////////// + * types + */ +typedef int (*xm_open_func_t)(lua_State* lua); + +/* ////////////////////////////////////////////////////////////////////////////////////// + * implementation + */ +tb_int_t xm_package_loadxmi(lua_State* lua) +{ + // check + tb_assert_and_check_return_val(lua, 0); + + tb_char_t const* path = luaL_checkstring(lua, 1); + tb_check_return_val(path, 0); + + tb_char_t const* name = luaL_checkstring(lua, 2); + tb_check_return_val(name, 0); + + // load module library + tb_dynamic_ref_t lib = tb_dynamic_init(path); + if (!lib) + { + lua_pushnil(lua); + lua_pushfstring(lua, "load %s failed", path); + return 2; + } + + // get xmiopen_xxx function + xm_open_func_t func = (xm_open_func_t)tb_dynamic_func(path, name); + if (!func) + { + lua_pushnil(lua); + lua_pushfstring(lua, "cannot get symbol %s failed", name); + return 2; + } + + // load module + return func(lua); +} diff --git a/core/src/xmake/package/prefix.h b/core/src/xmake/package/prefix.h new file mode 100644 index 000000000..e710e526c --- /dev/null +++ b/core/src/xmake/package/prefix.h @@ -0,0 +1,32 @@ +/*!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 obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Copyright (C) 2015-present, TBOOX Open Source Group. + * + * @author ruki + * @file prefix.h + * + */ +#ifndef XM_PACKAGE_PREFIX_H +#define XM_PACKAGE_PREFIX_H + +/* ////////////////////////////////////////////////////////////////////////////////////// + * includes + */ +#include "../prefix.h" + + +#endif + + |
