diff options
Diffstat (limited to 'xmake')
| -rw-r--r-- | xmake/core/sandbox/modules/import/core/sandbox/module.lua | 21 | ||||
| -rw-r--r-- | xmake/rules/module/xmake.lua | 6 | ||||
| -rw-r--r-- | xmake/scripts/module/luawrap/lauxlib.h | 31 | ||||
| -rw-r--r-- | xmake/scripts/module/luawrap/lua.h | 31 | ||||
| -rw-r--r-- | xmake/scripts/module/luawrap/luaconf.h | 790 | ||||
| -rw-r--r-- | xmake/scripts/module/xmi.h | 672 | ||||
| -rw-r--r-- | xmake/templates/c++/module.shared/project/modules/shared/foo/src/foo.cpp | 28 | ||||
| -rw-r--r-- | xmake/templates/c++/module.shared/project/modules/shared/foo/xmake.lua | 3 | ||||
| -rw-r--r-- | xmake/templates/c/module.shared/project/modules/shared/foo/src/foo.c | 20 | ||||
| -rw-r--r-- | xmake/templates/c/module.shared/project/modules/shared/foo/xmake.lua | 3 |
10 files changed, 1562 insertions, 43 deletions
diff --git a/xmake/core/sandbox/modules/import/core/sandbox/module.lua b/xmake/core/sandbox/modules/import/core/sandbox/module.lua index b1fc0084e..bddfb1524 100644 --- a/xmake/core/sandbox/modules/import/core/sandbox/module.lua +++ b/xmake/core/sandbox/modules/import/core/sandbox/module.lua @@ -305,21 +305,26 @@ function core_sandbox_module._load_from_shared(module_fullpath, opt) end libraryfiles = {} end - local script local module if #libraryfiles == 0 then libraryfiles = os.files(path.join(moduleinfo.buildir, "*module_*")) end if #libraryfiles > 0 then - local errors + local script, errors1, errors2 for _, libraryfile in ipairs(libraryfiles) do local modulename = path.basename(libraryfile):match("module_(.+)") - script, errors = package.loadlib(libraryfile, "luaopen_" .. modulename) - if not script then - return nil, errors - end - module = script() - if module then + if modulename then + if package.loadxmi then + script, errors1 = package.loadxmi(libraryfile, "xmiopen_" .. modulename) + end + if not script then + script, errors2 = package.loadlib(libraryfile, "luaopen_" .. modulename) + end + if script then + module = script() + else + return nil, errors1 or errors2 or string.format("xmiopen_%s and luaopen_%s not found!", modulename, modulename) + end break end end diff --git a/xmake/rules/module/xmake.lua b/xmake/rules/module/xmake.lua index f70c71d7e..0515bd842 100644 --- a/xmake/rules/module/xmake.lua +++ b/xmake/rules/module/xmake.lua @@ -29,11 +29,15 @@ rule("module.binary") rule("module.shared") add_deps("utils.symbols.export_all") on_load(function (target) - assert(not xmake.luajit(), "rule(module.shared) only support for lua54 runtime!") import("core.project.config") target:set("kind", "shared") target:set("basename", "module_" .. target:name()) target:set("targetdir", config.buildir()) target:set("strip", "none") + target:add("includedirs", path.join(os.programdir(), "scripts", "module")) + target:add("includedirs", path.join(os.programdir(), "scripts", "module", "luawrap")) + if xmake.luajit() then + target:add("defines", "XMI_USE_LUAJIT") + end end) diff --git a/xmake/scripts/module/luawrap/lauxlib.h b/xmake/scripts/module/luawrap/lauxlib.h new file mode 100644 index 000000000..58f7c8b40 --- /dev/null +++ b/xmake/scripts/module/luawrap/lauxlib.h @@ -0,0 +1,31 @@ +/*!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 luaxlib.h + * + */ +#ifndef XMI_LUAXLIB_H +#define XMI_LUAXLIB_H + +/* ////////////////////////////////////////////////////////////////////////////////////// + * includes + */ +#include "xmi.h" + +#endif + + diff --git a/xmake/scripts/module/luawrap/lua.h b/xmake/scripts/module/luawrap/lua.h new file mode 100644 index 000000000..92d799d57 --- /dev/null +++ b/xmake/scripts/module/luawrap/lua.h @@ -0,0 +1,31 @@ +/*!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 lua.h + * + */ +#ifndef XMI_LUA_H +#define XMI_LUA_H + +/* ////////////////////////////////////////////////////////////////////////////////////// + * includes + */ +#include "xmi.h" + +#endif + + diff --git a/xmake/scripts/module/luawrap/luaconf.h b/xmake/scripts/module/luawrap/luaconf.h new file mode 100644 index 000000000..e64d2ee39 --- /dev/null +++ b/xmake/scripts/module/luawrap/luaconf.h @@ -0,0 +1,790 @@ +/* +** $Id: luaconf.h $ +** Configuration file for Lua +** See Copyright Notice in lua.h +*/ + + +#ifndef luaconf_h +#define luaconf_h + +#include <limits.h> +#include <stddef.h> + + +/* +** =================================================================== +** General Configuration File for Lua +** +** Some definitions here can be changed externally, through the compiler +** (e.g., with '-D' options): They are commented out or protected +** by '#if !defined' guards. However, several other definitions +** should be changed directly here, either because they affect the +** Lua ABI (by making the changes here, you ensure that all software +** connected to Lua, such as C libraries, will be compiled with the same +** configuration); or because they are seldom changed. +** +** Search for "@@" to find all configurable definitions. +** =================================================================== +*/ + + +/* +** {==================================================================== +** System Configuration: macros to adapt (if needed) Lua to some +** particular platform, for instance restricting it to C89. +** ===================================================================== +*/ + +/* +@@ LUA_USE_C89 controls the use of non-ISO-C89 features. +** Define it if you want Lua to avoid the use of a few C99 features +** or Windows-specific features on Windows. +*/ +/* #define LUA_USE_C89 */ + + +/* +** By default, Lua on Windows use (some) specific Windows features +*/ +#if !defined(LUA_USE_C89) && defined(_WIN32) && !defined(_WIN32_WCE) +#define LUA_USE_WINDOWS /* enable goodies for regular Windows */ +#endif + + +#if defined(LUA_USE_WINDOWS) +#define LUA_DL_DLL /* enable support for DLL */ +#define LUA_USE_C89 /* broadly, Windows is C89 */ +#endif + + +#if defined(LUA_USE_LINUX) +#define LUA_USE_POSIX +#define LUA_USE_DLOPEN /* needs an extra library: -ldl */ +#endif + + +#if defined(LUA_USE_MACOSX) +#define LUA_USE_POSIX +#define LUA_USE_DLOPEN /* MacOS does not need -ldl */ +#endif + + +/* +@@ LUAI_IS32INT is true iff 'int' has (at least) 32 bits. +*/ +#define LUAI_IS32INT ((UINT_MAX >> 30) >= 3) + +/* }================================================================== */ + + + +/* +** {================================================================== +** Configuration for Number types. These options should not be +** set externally, because any other code connected to Lua must +** use the same configuration. +** =================================================================== +*/ + +/* +@@ LUA_INT_TYPE defines the type for Lua integers. +@@ LUA_FLOAT_TYPE defines the type for Lua floats. +** Lua should work fine with any mix of these options supported +** by your C compiler. The usual configurations are 64-bit integers +** and 'double' (the default), 32-bit integers and 'float' (for +** restricted platforms), and 'long'/'double' (for C compilers not +** compliant with C99, which may not have support for 'long long'). +*/ + +/* predefined options for LUA_INT_TYPE */ +#define LUA_INT_INT 1 +#define LUA_INT_LONG 2 +#define LUA_INT_LONGLONG 3 + +/* predefined options for LUA_FLOAT_TYPE */ +#define LUA_FLOAT_FLOAT 1 +#define LUA_FLOAT_DOUBLE 2 +#define LUA_FLOAT_LONGDOUBLE 3 + + +/* Default configuration ('long long' and 'double', for 64-bit Lua) */ +#define LUA_INT_DEFAULT LUA_INT_LONGLONG +#define LUA_FLOAT_DEFAULT LUA_FLOAT_DOUBLE + + +/* +@@ LUA_32BITS enables Lua with 32-bit integers and 32-bit floats. +*/ +#define LUA_32BITS 0 + + +/* +@@ LUA_C89_NUMBERS ensures that Lua uses the largest types available for +** C89 ('long' and 'double'); Windows always has '__int64', so it does +** not need to use this case. +*/ +#if defined(LUA_USE_C89) && !defined(LUA_USE_WINDOWS) +#define LUA_C89_NUMBERS 1 +#else +#define LUA_C89_NUMBERS 0 +#endif + + +#if LUA_32BITS /* { */ +/* +** 32-bit integers and 'float' +*/ +#if LUAI_IS32INT /* use 'int' if big enough */ +#define LUA_INT_TYPE LUA_INT_INT +#else /* otherwise use 'long' */ +#define LUA_INT_TYPE LUA_INT_LONG +#endif +#define LUA_FLOAT_TYPE LUA_FLOAT_FLOAT + +#elif LUA_C89_NUMBERS /* }{ */ +/* +** largest types available for C89 ('long' and 'double') +*/ +#define LUA_INT_TYPE LUA_INT_LONG +#define LUA_FLOAT_TYPE LUA_FLOAT_DOUBLE + +#else /* }{ */ +/* use defaults */ + +#define LUA_INT_TYPE LUA_INT_DEFAULT +#define LUA_FLOAT_TYPE LUA_FLOAT_DEFAULT + +#endif /* } */ + + +/* }================================================================== */ + + + +/* +** {================================================================== +** Configuration for Paths. +** =================================================================== +*/ + +/* +** LUA_PATH_SEP is the character that separates templates in a path. +** LUA_PATH_MARK is the string that marks the substitution points in a +** template. +** LUA_EXEC_DIR in a Windows path is replaced by the executable's +** directory. +*/ +#define LUA_PATH_SEP ";" +#define LUA_PATH_MARK "?" +#define LUA_EXEC_DIR "!" + + +/* +@@ LUA_PATH_DEFAULT is the default path that Lua uses to look for +** Lua libraries. +@@ LUA_CPATH_DEFAULT is the default path that Lua uses to look for +** C libraries. +** CHANGE them if your machine has a non-conventional directory +** hierarchy or if you want to install your libraries in +** non-conventional directories. +*/ + +#define LUA_VDIR LUA_VERSION_MAJOR "." LUA_VERSION_MINOR +#if defined(_WIN32) /* { */ +/* +** In Windows, any exclamation mark ('!') in the path is replaced by the +** path of the directory of the executable file of the current process. +*/ +#define LUA_LDIR "!\\lua\\" +#define LUA_CDIR "!\\" +#define LUA_SHRDIR "!\\..\\share\\lua\\" LUA_VDIR "\\" + +#if !defined(LUA_PATH_DEFAULT) +#define LUA_PATH_DEFAULT \ + LUA_LDIR"?.lua;" LUA_LDIR"?\\init.lua;" \ + LUA_CDIR"?.lua;" LUA_CDIR"?\\init.lua;" \ + LUA_SHRDIR"?.lua;" LUA_SHRDIR"?\\init.lua;" \ + ".\\?.lua;" ".\\?\\init.lua" +#endif + +#if !defined(LUA_CPATH_DEFAULT) +#define LUA_CPATH_DEFAULT \ + LUA_CDIR"?.dll;" \ + LUA_CDIR"..\\lib\\lua\\" LUA_VDIR "\\?.dll;" \ + LUA_CDIR"loadall.dll;" ".\\?.dll" +#endif + +#else /* }{ */ + +#define LUA_ROOT "/usr/local/" +#define LUA_LDIR LUA_ROOT "share/lua/" LUA_VDIR "/" +#define LUA_CDIR LUA_ROOT "lib/lua/" LUA_VDIR "/" + +#if !defined(LUA_PATH_DEFAULT) +#define LUA_PATH_DEFAULT \ + LUA_LDIR"?.lua;" LUA_LDIR"?/init.lua;" \ + LUA_CDIR"?.lua;" LUA_CDIR"?/init.lua;" \ + "./?.lua;" "./?/init.lua" +#endif + +#if !defined(LUA_CPATH_DEFAULT) +#define LUA_CPATH_DEFAULT \ + LUA_CDIR"?.so;" LUA_CDIR"loadall.so;" "./?.so" +#endif + +#endif /* } */ + + +/* +@@ LUA_DIRSEP is the directory separator (for submodules). +** CHANGE it if your machine does not use "/" as the directory separator +** and is not Windows. (On Windows Lua automatically uses "\".) +*/ +#if !defined(LUA_DIRSEP) + +#if defined(_WIN32) +#define LUA_DIRSEP "\\" +#else +#define LUA_DIRSEP "/" +#endif + +#endif + +/* }================================================================== */ + + +/* +** {================================================================== +** Marks for exported symbols in the C code +** =================================================================== +*/ + +/* +@@ LUA_API is a mark for all core API functions. +@@ LUALIB_API is a mark for all auxiliary library functions. +@@ LUAMOD_API is a mark for all standard library opening functions. +** CHANGE them if you need to define those functions in some special way. +** For instance, if you want to create one Windows DLL with the core and +** the libraries, you may want to use the following definition (define +** LUA_BUILD_AS_DLL to get it). +*/ +#if defined(LUA_BUILD_AS_DLL) /* { */ + +#if defined(LUA_CORE) || defined(LUA_LIB) /* { */ +#define LUA_API __declspec(dllexport) +#else /* }{ */ +#define LUA_API __declspec(dllimport) +#endif /* } */ + +#else /* }{ */ + +#define LUA_API extern + +#endif /* } */ + + +/* +** More often than not the libs go together with the core. +*/ +#define LUALIB_API LUA_API +#define LUAMOD_API LUA_API + + +/* +@@ LUAI_FUNC is a mark for all extern functions that are not to be +** exported to outside modules. +@@ LUAI_DDEF and LUAI_DDEC are marks for all extern (const) variables, +** none of which to be exported to outside modules (LUAI_DDEF for +** definitions and LUAI_DDEC for declarations). +** CHANGE them if you need to mark them in some special way. Elf/gcc +** (versions 3.2 and later) mark them as "hidden" to optimize access +** when Lua is compiled as a shared library. Not all elf targets support +** this attribute. Unfortunately, gcc does not offer a way to check +** whether the target offers that support, and those without support +** give a warning about it. To avoid these warnings, change to the +** default definition. +*/ +#if defined(__GNUC__) && ((__GNUC__*100 + __GNUC_MINOR__) >= 302) && \ + defined(__ELF__) /* { */ +#define LUAI_FUNC __attribute__((visibility("internal"))) extern +#else /* }{ */ +#define LUAI_FUNC extern +#endif /* } */ + +#define LUAI_DDEC(dec) LUAI_FUNC dec +#define LUAI_DDEF /* empty */ + +/* }================================================================== */ + + +/* +** {================================================================== +** Compatibility with previous versions +** =================================================================== +*/ + +/* +@@ LUA_COMPAT_5_3 controls other macros for compatibility with Lua 5.3. +** You can define it to get all options, or change specific options +** to fit your specific needs. +*/ +#if defined(LUA_COMPAT_5_3) /* { */ + +/* +@@ LUA_COMPAT_MATHLIB controls the presence of several deprecated +** functions in the mathematical library. +** (These functions were already officially removed in 5.3; +** nevertheless they are still available here.) +*/ +#define LUA_COMPAT_MATHLIB + +/* +@@ LUA_COMPAT_APIINTCASTS controls the presence of macros for +** manipulating other integer types (lua_pushunsigned, lua_tounsigned, +** luaL_checkint, luaL_checklong, etc.) +** (These macros were also officially removed in 5.3, but they are still +** available here.) +*/ +#define LUA_COMPAT_APIINTCASTS + + +/* +@@ LUA_COMPAT_LT_LE controls the emulation of the '__le' metamethod +** using '__lt'. +*/ +#define LUA_COMPAT_LT_LE + + +/* +@@ The following macros supply trivial compatibility for some +** changes in the API. The macros themselves document how to +** change your code to avoid using them. +** (Once more, these macros were officially removed in 5.3, but they are +** still available here.) +*/ +#define lua_strlen(L,i) lua_rawlen(L, (i)) + +#define lua_objlen(L,i) lua_rawlen(L, (i)) + +#define lua_equal(L,idx1,idx2) lua_compare(L,(idx1),(idx2),LUA_OPEQ) +#define lua_lessthan(L,idx1,idx2) lua_compare(L,(idx1),(idx2),LUA_OPLT) + +#endif /* } */ + +/* }================================================================== */ + + + +/* +** {================================================================== +** Configuration for Numbers (low-level part). +** Change these definitions if no predefined LUA_FLOAT_* / LUA_INT_* +** satisfy your needs. +** =================================================================== +*/ + +/* +@@ LUAI_UACNUMBER is the result of a 'default argument promotion' +@@ over a floating number. +@@ l_floatatt(x) corrects float attribute 'x' to the proper float type +** by prefixing it with one of FLT/DBL/LDBL. +@@ LUA_NUMBER_FRMLEN is the length modifier for writing floats. +@@ LUA_NUMBER_FMT is the format for writing floats. +@@ lua_number2str converts a float to a string. +@@ l_mathop allows the addition of an 'l' or 'f' to all math operations. +@@ l_floor takes the floor of a float. +@@ lua_str2number converts a decimal numeral to a number. +*/ + + +/* The following definitions are good for most cases here */ + +#define l_floor(x) (l_mathop(floor)(x)) + +#define lua_number2str(s,sz,n) \ + l_sprintf((s), sz, LUA_NUMBER_FMT, (LUAI_UACNUMBER)(n)) + +/* +@@ lua_numbertointeger converts a float number with an integral value +** to an integer, or returns 0 if float is not within the range of +** a lua_Integer. (The range comparisons are tricky because of +** rounding. The tests here assume a two-complement representation, +** where MININTEGER always has an exact representation as a float; +** MAXINTEGER may not have one, and therefore its conversion to float +** may have an ill-defined value.) +*/ +#define lua_numbertointeger(n,p) \ + ((n) >= (LUA_NUMBER)(LUA_MININTEGER) && \ + (n) < -(LUA_NUMBER)(LUA_MININTEGER) && \ + (*(p) = (LUA_INTEGER)(n), 1)) + + +/* now the variable definitions */ + +#if LUA_FLOAT_TYPE == LUA_FLOAT_FLOAT /* { single float */ + +#define LUA_NUMBER float + +#define l_floatatt(n) (FLT_##n) + +#define LUAI_UACNUMBER double + +#define LUA_NUMBER_FRMLEN "" +#define LUA_NUMBER_FMT "%.7g" + +#define l_mathop(op) op##f + +#define lua_str2number(s,p) strtof((s), (p)) + + +#elif LUA_FLOAT_TYPE == LUA_FLOAT_LONGDOUBLE /* }{ long double */ + +#define LUA_NUMBER long double + +#define l_floatatt(n) (LDBL_##n) + +#define LUAI_UACNUMBER long double + +#define LUA_NUMBER_FRMLEN "L" +#define LUA_NUMBER_FMT "%.19Lg" + +#define l_mathop(op) op##l + +#define lua_str2number(s,p) strtold((s), (p)) + +#elif LUA_FLOAT_TYPE == LUA_FLOAT_DOUBLE /* }{ double */ + +#define LUA_NUMBER double + +#define l_floatatt(n) (DBL_##n) + +#define LUAI_UACNUMBER double + +#define LUA_NUMBER_FRMLEN "" +#define LUA_NUMBER_FMT "%.14g" + +#define l_mathop(op) op + +#define lua_str2number(s,p) strtod((s), (p)) + +#else /* }{ */ + +#error "numeric float type not defined" + +#endif /* } */ + + + +/* +@@ LUA_UNSIGNED is the unsigned version of LUA_INTEGER. +@@ LUAI_UACINT is the result of a 'default argument promotion' +@@ over a LUA_INTEGER. +@@ LUA_INTEGER_FRMLEN is the length modifier for reading/writing integers. +@@ LUA_INTEGER_FMT is the format for writing integers. +@@ LUA_MAXINTEGER is the maximum value for a LUA_INTEGER. +@@ LUA_MININTEGER is the minimum value for a LUA_INTEGER. +@@ LUA_MAXUNSIGNED is the maximum value for a LUA_UNSIGNED. +@@ LUA_UNSIGNEDBITS is the number of bits in a LUA_UNSIGNED. +@@ lua_integer2str converts an integer to a string. +*/ + + +/* The following definitions are good for most cases here */ + +#define LUA_INTEGER_FMT "%" LUA_INTEGER_FRMLEN "d" + +#define LUAI_UACINT LUA_INTEGER + +#define lua_integer2str(s,sz,n) \ + l_sprintf((s), sz, LUA_INTEGER_FMT, (LUAI_UACINT)(n)) + +/* +** use LUAI_UACINT here to avoid problems with promotions (which +** can turn a comparison between unsigneds into a signed comparison) +*/ +#define LUA_UNSIGNED unsigned LUAI_UACINT + + +#define LUA_UNSIGNEDBITS (sizeof(LUA_UNSIGNED) * CHAR_BIT) + + +/* now the variable definitions */ + +#if LUA_INT_TYPE == LUA_INT_INT /* { int */ + +#define LUA_INTEGER int +#define LUA_INTEGER_FRMLEN "" + +#define LUA_MAXINTEGER INT_MAX +#define LUA_MININTEGER INT_MIN + +#define LUA_MAXUNSIGNED UINT_MAX + +#elif LUA_INT_TYPE == LUA_INT_LONG /* }{ long */ + +#define LUA_INTEGER long +#define LUA_INTEGER_FRMLEN "l" + +#define LUA_MAXINTEGER LONG_MAX +#define LUA_MININTEGER LONG_MIN + +#define LUA_MAXUNSIGNED ULONG_MAX + +#elif LUA_INT_TYPE == LUA_INT_LONGLONG /* }{ long long */ + +/* use presence of macro LLONG_MAX as proxy for C99 compliance */ +#if defined(LLONG_MAX) /* { */ +/* use ISO C99 stuff */ + +#define LUA_INTEGER long long +#define LUA_INTEGER_FRMLEN "ll" + +#define LUA_MAXINTEGER LLONG_MAX +#define LUA_MININTEGER LLONG_MIN + +#define LUA_MAXUNSIGNED ULLONG_MAX + +#elif defined(LUA_USE_WINDOWS) /* }{ */ +/* in Windows, can use specific Windows types */ + +#define LUA_INTEGER __int64 +#define LUA_INTEGER_FRMLEN "I64" + +#define LUA_MAXINTEGER _I64_MAX +#define LUA_MININTEGER _I64_MIN + +#define LUA_MAXUNSIGNED _UI64_MAX + +#else /* }{ */ + +#error "Compiler does not support 'long long'. Use option '-DLUA_32BITS' \ + or '-DLUA_C89_NUMBERS' (see file 'luaconf.h' for details)" + +#endif /* } */ + +#else /* }{ */ + +#error "numeric integer type not defined" + +#endif /* } */ + +/* }================================================================== */ + + +/* +** {================================================================== +** Dependencies with C99 and other C details +** =================================================================== +*/ + +/* +@@ l_sprintf is equivalent to 'snprintf' or 'sprintf' in C89. +** (All uses in Lua have only one format item.) +*/ +#if !defined(LUA_USE_C89) +#define l_sprintf(s,sz,f,i) snprintf(s,sz,f,i) +#else +#define l_sprintf(s,sz,f,i) ((void)(sz), sprintf(s,f,i)) +#endif + + +/* +@@ lua_strx2number converts a hexadecimal numeral to a number. +** In C99, 'strtod' does that conversion. Otherwise, you can +** leave 'lua_strx2number' undefined and Lua will provide its own +** implementation. +*/ +#if !defined(LUA_USE_C89) +#define lua_strx2number(s,p) lua_str2number(s,p) +#endif + + +/* +@@ lua_pointer2str converts a pointer to a readable string in a +** non-specified way. +*/ +#define lua_pointer2str(buff,sz,p) l_sprintf(buff,sz,"%p",p) + + +/* +@@ lua_number2strx converts a float to a hexadecimal numeral. +** In C99, 'sprintf' (with format specifiers '%a'/'%A') does that. +** Otherwise, you can leave 'lua_number2strx' undefined and Lua will +** provide its own implementation. +*/ +#if !defined(LUA_USE_C89) +#define lua_number2strx(L,b,sz,f,n) \ + ((void)L, l_sprintf(b,sz,f,(LUAI_UACNUMBER)(n))) +#endif + + +/* +** 'strtof' and 'opf' variants for math functions are not valid in +** C89. Otherwise, the macro 'HUGE_VALF' is a good proxy for testing the +** availability of these variants. ('math.h' is already included in +** all files that use these macros.) +*/ +#if defined(LUA_USE_C89) || (defined(HUGE_VAL) && !defined(HUGE_VALF)) +#undef l_mathop /* variants not available */ +#undef lua_str2number +#define l_mathop(op) (lua_Number)op /* no variant */ +#define lua_str2number(s,p) ((lua_Number)strtod((s), (p))) +#endif + + +/* +@@ LUA_KCONTEXT is the type of the context ('ctx') for continuation +** functions. It must be a numerical type; Lua will use 'intptr_t' if +** available, otherwise it will use 'ptrdiff_t' (the nearest thing to +** 'intptr_t' in C89) +*/ +#define LUA_KCONTEXT ptrdiff_t + +#if !defined(LUA_USE_C89) && defined(__STDC_VERSION__) && \ + __STDC_VERSION__ >= 199901L +#include <stdint.h> +#if defined(INTPTR_MAX) /* even in C99 this type is optional */ +#undef LUA_KCONTEXT +#define LUA_KCONTEXT intptr_t +#endif +#endif + + +/* +@@ lua_getlocaledecpoint gets the locale "radix character" (decimal point). +** Change that if you do not want to use C locales. (Code using this +** macro must include the header 'locale.h'.) +*/ +#if !defined(lua_getlocaledecpoint) +#define lua_getlocaledecpoint() (localeconv()->decimal_point[0]) +#endif + + +/* +** macros to improve jump prediction, used mostly for error handling +** and debug facilities. (Some macros in the Lua API use these macros. +** Define LUA_NOBUILTIN if you do not want '__builtin_expect' in your +** code.) +*/ +#if !defined(luai_likely) + +#if defined(__GNUC__) && !defined(LUA_NOBUILTIN) +#define luai_likely(x) (__builtin_expect(((x) != 0), 1)) +#define luai_unlikely(x) (__builtin_expect(((x) != 0), 0)) +#else +#define luai_likely(x) (x) +#define luai_unlikely(x) (x) +#endif + +#endif + + +#if defined(LUA_CORE) || defined(LUA_LIB) +/* shorter names for Lua's own use */ +#define l_likely(x) luai_likely(x) +#define l_unlikely(x) luai_unlikely(x) +#endif + + + +/* }================================================================== */ + + +/* +** {================================================================== +** Language Variations +** ===================================================================== +*/ + +/* +@@ LUA_NOCVTN2S/LUA_NOCVTS2N control how Lua performs some +** coercions. Define LUA_NOCVTN2S to turn off automatic coercion from +** numbers to strings. Define LUA_NOCVTS2N to turn off automatic +** coercion from strings to numbers. +*/ +/* #define LUA_NOCVTN2S */ +/* #define LUA_NOCVTS2N */ + + +/* +@@ LUA_USE_APICHECK turns on several consistency checks on the C API. +** Define it as a help when debugging C code. +*/ +#if defined(LUA_USE_APICHECK) +#include <assert.h> +#define luai_apicheck(l,e) assert(e) +#endif + +/* }================================================================== */ + + +/* +** {================================================================== +** Macros that affect the API and must be stable (that is, must be the +** same when you compile Lua and when you compile code that links to +** Lua). +** ===================================================================== +*/ + +/* +@@ LUAI_MAXSTACK limits the size of the Lua stack. +** CHANGE it if you need a different limit. This limit is arbitrary; +** its only purpose is to stop Lua from consuming unlimited stack +** space (and to reserve some numbers for pseudo-indices). +** (It must fit into max(size_t)/32.) +*/ +#if LUAI_IS32INT +#define LUAI_MAXSTACK 1000000 +#else +#define LUAI_MAXSTACK 15000 +#endif + + +/* +@@ LUA_EXTRASPACE defines the size of a raw memory area associated with +** a Lua state with very fast access. +** CHANGE it if you need a different size. +*/ +#define LUA_EXTRASPACE (sizeof(void *)) + + +/* +@@ LUA_IDSIZE gives the maximum size for the description of the source +@@ of a function in debug information. +** CHANGE it if you want a different size. +*/ +#define LUA_IDSIZE 60 + + +/* +@@ LUAL_BUFFERSIZE is the buffer size used by the lauxlib buffer system. +*/ +#define LUAL_BUFFERSIZE ((int)(16 * sizeof(void*) * sizeof(lua_Number))) + + +/* +@@ LUAI_MAXALIGN defines fields that, when used in a union, ensure +** maximum alignment for the other items in that union. +*/ +#define LUAI_MAXALIGN lua_Number n; double u; void *s; lua_Integer i; long l + +/* }================================================================== */ + + + + + +/* =================================================================== */ + +/* +** Local configuration. You can use this space to add your redefinitions +** without modifying the main part of the file. +*/ + + + + + +#endif + diff --git a/xmake/scripts/module/xmi.h b/xmake/scripts/module/xmi.h new file mode 100644 index 000000000..b1fd1572c --- /dev/null +++ b/xmake/scripts/module/xmi.h @@ -0,0 +1,672 @@ +/*!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 xmi.h + * + */ +#ifndef XMI_H +#define XMI_H + +/* ////////////////////////////////////////////////////////////////////////////////////// + * includes + */ +#include <stdio.h> +#include <stdlib.h> +#include <stdarg.h> +#ifndef LUA_VERSION +# include "luawrap/luaconf.h" +#endif + +/* ////////////////////////////////////////////////////////////////////////////////////// + * macros + */ + +#define XMI_LUA_MULTRET (-1) + +// thread status +#define XMI_LUA_OK 0 +#define XMI_LUA_YIELD 1 +#define XMI_LUA_ERRRUN 2 +#define XMI_LUA_ERRSYNTAX 3 +#define XMI_LUA_ERRMEM 4 +#define XMI_LUA_ERRERR 5 + +// basic types +#define XMI_LUA_TNONE (-1) + +#define XMI_LUA_TNIL 0 +#define XMI_LUA_TBOOLEAN 1 +#define XMI_LUA_TLIGHTUSERDATA 2 +#define XMI_LUA_TNUMBER 3 +#define XMI_LUA_TSTRING 4 +#define XMI_LUA_TTABLE 5 +#define XMI_LUA_TFUNCTION 6 +#define XMI_LUA_TUSERDATA 7 +#define XMI_LUA_TTHREAD 8 + +#define XMI_LUA_NUMTYPES 9 + +// pseudo-indices +#ifdef XMI_USE_LUAJIT +# define XMI_LUA_REGISTRYINDEX (-10000) +# define XMI_LUA_ENVIRONINDEX (-10001) +# define XMI_LUA_GLOBALSINDEX (-10002) +# define xmi_lua_upvalueindex(i) (XMI_LUA_GLOBALSINDEX - (i)) +#else +# define XMI_LUA_REGISTRYINDEX (-LUAI_MAXSTACK - 1000) +# define xmi_lua_upvalueindex(i) (XMI_LUA_REGISTRYINDEX - (i)) +#endif + +// get macros +#ifdef XMI_USE_LUAJIT +# define xmi_lua_getglobal(lua, s) xmi_lua_getfield(lua, LUA_GLOBALSINDEX, (s)) +# define xmi_lua_newuserdata(lua, s) (g_lua_ops)->_lua_newuserdata(lua, s) +#else +# define xmi_lua_getglobal(lua, name) (g_lua_ops)->_lua_getglobal(lua, name) +# define xmi_lua_geti(lua, idx, n) (g_lua_ops)->_lua_geti(lua, idx, n) +# define xmi_lua_rawgetp(lua, idx, p) (g_lua_ops)->_lua_rawgetp(lua, idx, p) +# define xmi_lua_getiuservalue(lua, idx, n) (g_lua_ops)->_lua_getiuservalue(lua, idx, n) +# define xmi_lua_newuserdatauv(lua, sz, nuvalue) (g_lua_ops)->_lua_newuserdatauv(lua, sz, nuvalue) +# define xmi_lua_newuserdata(lua, s) xmi_lua_newuserdatauv(lua, s, 1) +#endif +#define xmi_lua_gettable(lua, idx) (g_lua_ops)->_lua_gettable(lua, idx) +#define xmi_lua_getfield(lua, idx, k) (g_lua_ops)->_lua_getfield(lua, idx, k) +#define xmi_lua_rawget(lua, idx) (g_lua_ops)->_lua_rawget(lua, idx) +#define xmi_lua_rawgeti(lua, idx, n) (g_lua_ops)->_lua_rawgeti(lua, idx, n) +#define xmi_lua_createtable(lua, narr, nrec) (g_lua_ops)->_lua_createtable(lua, narr, nrec) +#define xmi_lua_getmetatable(lua, objindex) (g_lua_ops)->_lua_getmetatable(lua, objindex) +#define xmi_lua_newtable(lua) xmi_lua_createtable(lua, 0, 0) +#define xmi_lua_pop(lua, n) xmi_lua_settop(lua, -(n)-1) +#define xmi_lua_getuservalue(lua, idx) xmi_lua_getiuservalue(lua, idx, 1) + +// set macros +#ifdef XMI_USE_LUAJIT +# define xmi_lua_setglobal(lua, s) xmi_lua_setfield(lua, LUA_GLOBALSINDEX, (s)) +#else +# define xmi_lua_setglobal(lua, name) (g_lua_ops)->_lua_setglobal(lua, name) +# define xmi_lua_seti(lua, idx, n) (g_lua_ops)->_lua_seti(lua, idx, n) +# define xmi_lua_rawsetp(lua, idx, p) (g_lua_ops)->_lua_rawsetp(lua, idx, p) +# define xmi_lua_setiuservalue(lua, idx, n) (g_lua_ops)->_lua_setiuservalue(lua, idx, n) +#endif +#define xmi_lua_settable(lua, idx) (g_lua_ops)->_lua_settable(lua, idx) +#define xmi_lua_setfield(lua, idx, k) (g_lua_ops)->_lua_setfield(lua, idx, k) +#define xmi_lua_rawset(lua, idx) (g_lua_ops)->_lua_rawset(lua, idx) +#define xmi_lua_rawseti(lua, idx, n) (g_lua_ops)->_lua_rawseti(lua, idx, n) +#define xmi_lua_setmetatable(lua, objidx) (g_lua_ops)->_lua_setmetatable(lua, objidx) +#define xmi_lua_setuservalue(lua, idx) xmi_lua_setiuservalue(lua, idx, 1) + +// access macros +#define xmi_lua_isnumber(lua, idx) (g_lua_ops)->_lua_isnumber(lua, idx) +#define xmi_lua_isstring(lua, idx) (g_lua_ops)->_lua_isstring(lua, idx) +#define xmi_lua_iscfunction(lua, idx) (g_lua_ops)->_lua_iscfunction(lua, idx) +#define xmi_lua_isuserdata(lua, idx) (g_lua_ops)->_lua_isuserdata(lua, idx) +#define xmi_lua_type(lua, idx) (g_lua_ops)->_lua_type(lua, idx) +#define xmi_lua_typename(lua, idx) (g_lua_ops)->_lua_typename(lua, idx) +#ifndef XMI_USE_LUAJIT +# define xmi_lua_isinteger(lua, idx) (g_lua_ops)->_lua_isinteger(lua, idx) +#endif + +#define xmi_lua_isfunction(lua, n) (xmi_lua_type(lua, (n)) == XMI_LUA_TFUNCTION) +#define xmi_lua_istable(lua, n) (xmi_lua_type(lua, (n)) == XMI_LUA_TTABLE) +#define xmi_lua_islightuserdata(lua, n) (xmi_lua_type(lua, (n)) == XMI_LUA_TLIGHTUSERDATA) +#define xmi_lua_isnil(lua, n) (xmi_lua_type(lua, (n)) == XMI_LUA_TNIL) +#define xmi_lua_isboolean(lua, n) (xmi_lua_type(lua, (n)) == XMI_LUA_TBOOLEAN) +#define xmi_lua_isthread(lua, n) (xmi_lua_type(lua, (n)) == XMI_LUA_TTHREAD) +#define xmi_lua_isnone(lua, n) (xmi_lua_type(lua, (n)) == XMI_LUA_TNONE) +#define xmi_lua_isnoneornil(lua, n) (xmi_lua_type(lua, (n)) <= 0) + +#define xmi_lua_tonumberx(lua, idx, isnum) (g_lua_ops)->_lua_tonumberx(lua, idx, isnum) +#define xmi_lua_tointegerx(lua, idx, isnum) (g_lua_ops)->_lua_tointegerx(lua, idx, isnum) +#define xmi_lua_toboolean(lua, idx) (g_lua_ops)->_lua_toboolean(lua, idx) +#define xmi_lua_tolstring(lua, idx, len) (g_lua_ops)->_lua_tolstring(lua, idx, len) +#define xmi_lua_rawlen(lua, idx) (g_lua_ops)->_lua_rawlen(lua, idx) +#define xmi_lua_tocfunction(lua, idx) (g_lua_ops)->_lua_tocfunction(lua, idx) +#define xmi_lua_touserdata(lua, idx) (g_lua_ops)->_lua_touserdata(lua, idx) +#define xmi_lua_tothread(lua, idx) (g_lua_ops)->_lua_tothread(lua, idx) +#define xmi_lua_topointer(lua, idx) (g_lua_ops)->_lua_topointer(lua, idx) +#define xmi_lua_tonumber(lua, idx) xmi_lua_tonumberx(lua, (idx), NULL) +#define xmi_lua_tostring(lua, idx) xmi_lua_tolstring(lua, (idx), NULL) +#define xmi_lua_tointeger(lua, idx) xmi_lua_tointegerx(lua, (idx), NULL) + +// push macros +#define xmi_lua_pushnil(lua) (g_lua_ops)->_lua_pushnil(lua) +#define xmi_lua_pushinteger(lua, n) (g_lua_ops)->_lua_pushinteger(lua, n) +#define xmi_lua_pushboolean(lua, b) (g_lua_ops)->_lua_pushboolean(lua, b) +#define xmi_lua_pushnumber(lua, n) (g_lua_ops)->_lua_pushnumber(lua, n) +#define xmi_lua_pushlstring(lua, s, len) (g_lua_ops)->_lua_pushlstring(lua, s, len) +#define xmi_lua_pushstring(lua, s) (g_lua_ops)->_lua_pushstring(lua, s) +#define xmi_lua_pushvfstring(lua, fmt, argp) (g_lua_ops)->_lua_pushvfstring(lua, fmt, argp) +#if defined(_MSC_VER) +# define xmi_lua_pushfstring(lua, fmt, ...) (g_lua_ops)->_lua_pushfstring(lua, fmt, __VA_ARGS__) +#else +# define xmi_lua_pushfstring(lua, fmt, arg ...) (g_lua_ops)->_lua_pushfstring(lua, fmt, ## arg) +#endif +#define xmi_lua_pushcclosure(lua, fn, n) (g_lua_ops)->_lua_pushcclosure(lua, fn, n) +#define xmi_lua_pushlightuserdata(lua, p) (g_lua_ops)->_lua_pushlightuserdata(lua, p) +#define xmi_lua_pushthread(lua) (g_lua_ops)->_lua_pushthread(lua) +#define xmi_lua_pushcfunction(lua, f) xmi_lua_pushcclosure(lua, (f), 0) +#define xmi_lua_pushliteral(lua, s) xmi_lua_pushstring(lua, "" s) + +// stack functions +#ifdef XMI_USE_LUAJIT +# define xmi_lua_insert(lua, idx) (g_lua_ops)->_lua_insert(lua, idx) +# define xmi_lua_remove(lua, idx) (g_lua_ops)->_lua_remove(lua, idx) +# define xmi_lua_replace(lua, idx) (g_lua_ops)->_lua_replace(lua, idx) +#else +# define xmi_lua_absindex(lua, idx) (g_lua_ops)->_lua_absindex(lua, idx) +# define xmi_lua_rotate(lua, idx, n) (g_lua_ops)->_lua_rotate(lua, idx, n) +# define xmi_lua_insert(lua, idx) xmi_lua_rotate(lua, (idx), 1) +# define xmi_lua_remove(lua, idx) (xmi_lua_rotate(lua, (idx), -1), xmi_lua_pop(lua, 1)) +# define xmi_lua_replace(lua, idx) (xmi_lua_copy(lua, -1, (idx)), xmi_lua_pop(lua, 1)) +#endif +#define xmi_lua_gettop(lua) (g_lua_ops)->_lua_gettop(lua) +#define xmi_lua_settop(lua, idx) (g_lua_ops)->_lua_settop(lua, idx) +#define xmi_lua_pushvalue(lua, idx) (g_lua_ops)->_lua_pushvalue(lua, idx) +#define xmi_lua_copy(lua, fromidx, toidx) (g_lua_ops)->_lua_copy(lua, fromidx, toidx) +#define xmi_lua_checkstack(lua, n) (g_lua_ops)->_lua_checkstack(lua, n) +#define xmi_lua_xmove(from, to, n) (g_lua_ops)->_lua_xmove(from, to, n) + +// miscellaneous functions +#define xmi_lua_error(lua) (g_lua_ops)->_lua_error(lua) +#define xmi_lua_next(lua, idx) (g_lua_ops)->_lua_next(lua, idx) +#define xmi_lua_concat(lua, n) (g_lua_ops)->_lua_concat(lua, n) +#define xmi_lua_getallocf(lua, ud) (g_lua_ops)->_lua_getallocf(lua, ud) +#define xmi_lua_setallocf(lua, f, ud) (g_lua_ops)->_lua_setallocf(lua, f, ud) +#ifndef XMI_USE_LUAJIT +# define xmi_lua_len(lua, idx) (g_lua_ops)->_lua_len(lua, idx) +# define xmi_lua_toclose(lua, idx) (g_lua_ops)->_lua_toclose(lua, idx) +# define xmi_lua_closeslot(lua, idx) (g_lua_ops)->_lua_closeslot(lua, idx) +# define xmi_lua_stringtonumber(lua, s) (g_lua_ops)->_lua_stringtonumber(lua, s) +#endif + +// 'load' and 'call' functions +#ifdef XMI_USE_LUAJIT +# define xmi_lua_call(lua, n, nr) (g_lua_ops)->_lua_call(lua, n, nr) +# define xmi_lua_pcall(lua, n, nr, ef) (g_lua_ops)->_lua_pcall(lua, n, nr, ef) +# define xmi_lua_load(lua, r, dt, ch) (g_lua_ops)->_lua_load(lua, r, dt, ch) +# define xmi_lua_dump(lua, w, d) (g_lua_ops)->_lua_dump(lua, r, d) +#else +# define xmi_lua_callk(lua, n, nr, ctx, k) (g_lua_ops)->_lua_callk(lua, n, nr, ctx, k) +# define xmi_lua_pcallk(lua, n, nr, ef, ctx, k) (g_lua_ops)->_lua_pcallk(lua, n, nr, ef, ctx, k) +# define xmi_lua_call(lua, n, r) xmi_lua_callk(lua, (n), (r), 0, NULL) +# define xmi_lua_pcall(lua, n, r, f) xmi_lua_pcallk(lua, (n), (r), (f), 0, NULL) +# define xmi_lua_load(lua, r, dt, ch, mode) (g_lua_ops)->_lua_load(lua, r, dt, ch, mode) +# define xmi_lua_dump(lua, w, d, strip) (g_lua_ops)->_lua_dump(lua, r, d, strip) +#endif + +// luaL macros +#ifndef XMI_USE_LUAJIT +# define xmi_luaL_tolstring(lua, idx, len) (g_lua_ops)->_luaL_tolstring(lua, idx, len) +# define xmi_luaL_typeerror(lua, arg, tname) (g_lua_ops)->_luaL_typeerror(lua, arg, tname) +#endif +#define xmi_luaL_getmetafield(lua, obj, e) (g_lua_ops)->_luaL_getmetafield(lua, obj, e) +#define xmi_luaL_callmeta(lua, obj, e) (g_lua_ops)->_luaL_callmeta(lua, obj, e) +#define xmi_luaL_argerror(lua, numarg, extramsg) (g_lua_ops)->_luaL_argerror(lua, numarg, extramsg) +#define xmi_luaL_checklstring(lua, arg, l) (g_lua_ops)->_luaL_checklstring(lua, arg, l) +#define xmi_luaL_optlstring(lua, arg, def, l) (g_lua_ops)->_luaL_optlstring(lua, arg, def, l) +#define xmi_luaL_checknumber(lua, arg) (g_lua_ops)->_luaL_checknumber(lua, arg) +#define xmi_luaL_optnumber(lua, arg, def) (g_lua_ops)->_luaL_optnumber(lua, arg, def) +#define xmi_luaL_checkinteger(lua, idx) (g_lua_ops)->_luaL_checkinteger(lua, idx) +#define xmi_luaL_optinteger(lua, arg, def) (g_lua_ops)->_luaL_optinteger(lua, arg, def) +#define xmi_luaL_checkstack(lua, sz, msg) (g_lua_ops)->_luaL_checkstack(lua, sz, msg) +#define xmi_luaL_checktype(lua, arg, t) (g_lua_ops)->_luaL_checktype(lua, arg, t) +#define xmi_luaL_checkany(lua, arg) (g_lua_ops)->_luaL_checkany(lua, arg) +#define xmi_luaL_newmetatable(lua, tname) (g_lua_ops)->_luaL_newmetatable(lua, tname) +#define xmi_luaL_setmetatable(lua, tname) (g_lua_ops)->_luaL_setmetatable(lua, tname) +#define xmi_luaL_testudata(lua, tname) (g_lua_ops)->_luaL_testudata(lua, tname) +#define xmi_luaL_checkudata(lua, tname) (g_lua_ops)->_luaL_checkudata(lua, tname) +#define xmi_luaL_where(lua, lvl) (g_lua_ops)->_luaL_where(lua, lvl) +#if defined(_MSC_VER) +# define xmi_luaL_error(lua, fmt, ...) (g_lua_ops)->_luaL_error(lua, fmt, __VA_ARGS__) +#else +# define xmi_luaL_error(lua, fmt, arg ...) (g_lua_ops)->_luaL_error(lua, fmt, ## arg) +#endif +#define xmi_luaL_checkoption(lua, arg, def, lst) (g_lua_ops)->_luaL_checkoption(lua, arg, def, lst) +#define xmi_luaL_fileresult(lua, stat, fname) (g_lua_ops)->_luaL_fileresult(lua, stat, fname) +#define xmi_luaL_execresult(lua, stat) (g_lua_ops)->_luaL_execresult(lua, stat) +#define xmi_luaL_setfuncs(lua, l, nup) (g_lua_ops)->_luaL_setfuncs(lua, l, nup) + +#define xmi_luaL_newlibtable(lua, l) xml_lua_createtable(lua, 0, sizeof(l)/sizeof((l)[0]) - 1) +#define xmi_luaL_newlib(lua, l) \ + (xmi_luaL_checkversion(lua), xmi_luaL_newlibtable(lua,l), xmi_luaL_setfuncs(lua,l,0)) +#define xmi_luaL_argcheck(lua, cond, arg, extramsg) \ + ((void)(luai_likely(cond) || xmi_luaL_argerror(lua, (arg), (extramsg)))) +#define xmi_luaL_argexpected(lua, cond, arg, tname) \ + ((void)(luai_likely(cond) || xmi_luaL_typeerror(lua, (arg), (tname)))) +#define xmi_luaL_checkstring(lua, n) (xmi_luaL_checklstring(lua, (n), NULL)) +#define xmi_luaL_optstring(lua, n, d) (xmi_luaL_optlstring(lua, (n), (d), NULL)) +#define xmi_luaL_typename(lua, i) xmi_lua_typename(lua, xmi_lua_type(lua,(i))) +#define xmi_luaL_dofile(lua, fn) \ + (xmi_luaL_loadfile(lua, fn) || xmi_lua_pcall(lua, 0, XMI_LUA_MULTRET, 0)) +#define xmi_luaL_dostring(lua, s) \ + (xmi_luaL_loadstring(lua, s) || xmi_lua_pcall(lua, 0, XMI_LUA_MULTRET, 0)) +#define xmi_luaL_getmetatable(lua, n) (xmi_lua_getfield(lua, XMI_LUA_REGISTRYINDEX, (n))) +#define xmi_luaL_opt(lua, f, n, d) (xmi_lua_isnoneornil(lua,(n)) ? (d) : f(lua,(n))) +#define xmi_luaL_loadbuffer(lua, s, sz, n) xmi_luaL_loadbufferx(lua, s, sz, n, NULL) +#define xmi_luaL_pushfail(lua) xmi_lua_pushnil(lua) + +/* we cannot redefine lua functions in loadxmi.c, + * because original lua.h has been included + */ +#ifndef XM_PREFIX_H + +// thread status +# define LUA_OK XMI_LUA_OK +# define LUA_YIELD XMI_LUA_YIELD +# define LUA_ERRRUN XMI_LUA_ERRRUN +# define LUA_ERRSYNTAX XMI_LUA_ERRSYNTAX +# define LUA_ERRMEM XMI_LUA_ERRMEM +# define LUA_ERRERR XMI_LUA_ERRERR + +// basic types +# define LUA_TNONE XMI_LUA_TNONE +# define LUA_TNIL XMI_LUA_TNIL +# define LUA_TBOOLEAN XMI_LUA_TBOOLEAN +# define LUA_TLIGHTUSERDATA XMI_LUA_TLIGHTUSERDATA +# define LUA_TNUMBER XMI_LUA_TNUMBER +# define LUA_TSTRING XMI_LUA_TSTRING +# define LUA_TTABLE XMI_LUA_TTABLE +# define LUA_TFUNCTION XMI_LUA_TFUNCTION +# define LUA_TUSERDATA XMI_LUA_TUSERDATA +# define LUA_TTHREAD XMI_LUA_TTHREAD +# define LUA_NUMTYPES XMI_LUA_NUMTYPES + +// get macros +# define lua_getglobal xmi_lua_getglobal +# define lua_gettable xmi_lua_gettable +# define lua_getfield xmi_lua_getfield +# define lua_geti xmi_lua_geti +# define lua_rawget xmi_lua_rawget +# define lua_rawgeti xmi_lua_rawgeti +# define lua_rawgetp xmi_lua_rawgetp +# define lua_createtable xmi_lua_createtable +# define lua_newuserdatauv xmi_lua_newuserdatauv +# define lua_getmetatable xmi_lua_getmetatable +# define lua_getiuservalue xmi_lua_getiuservalue +# define lua_upvalueindex xmi_lua_upvalueindex +# define lua_newtable xmi_lua_newtable +# define lua_pop xmi_lua_pop +# define lua_newuserdata xmi_lua_newuserdata +# define lua_getuservalue xmi_lua_getuservalue + +// set macros +# define lua_setglobal xmi_lua_setglobal +# define lua_settable xmi_lua_settable +# define lua_setfield xmi_lua_setfield +# define lua_seti xmi_lua_seti +# define lua_rawset xmi_lua_rawset +# define lua_rawseti xmi_lua_rawseti +# define lua_rawsetp xmi_lua_rawsetp +# define lua_setmetatable xmi_lua_setmetatable +# define lua_setiuservalue xmi_lua_setiuservalue +# define lua_setuservalue xmi_lua_setuservalue + +// access macros +# define lua_isnumber xmi_lua_isnumber +# define lua_isstring xmi_lua_isstring +# define lua_iscfunction xmi_lua_iscfunction +# define lua_isuserdata xmi_lua_isuserdata +# define lua_type xmi_lua_type +# define lua_typename xmi_lua_typename +# ifndef XMI_USE_LUAJIT +# define lua_isinteger xmi_lua_isinteger +# endif + +# define lua_isfunction xmi_lua_isfunction +# define lua_istable xmi_lua_istable +# define lua_islightuserdata xmi_lua_islightuserdata +# define lua_isnil xmi_lua_isnil +# define lua_isboolean xmi_lua_isboolean +# define lua_isthread xmi_lua_isthread +# define lua_isnone xmi_lua_isnone +# define lua_isnoneornil xmi_lua_isnoneornil + +# define lua_tonumberx xmi_lua_tonumberx +# define lua_tointegerx xmi_lua_tointegerx +# define lua_toboolean xmi_lua_toboolean +# define lua_tolstring xmi_lua_tolstring +# define lua_rawlen xmi_lua_rawlen +# define lua_tocfunction xmi_lua_tocfunction +# define lua_touserdata xmi_lua_touserdata +# define lua_tothread xmi_lua_tothread +# define lua_topointer xmi_lua_topointer +# define lua_tostring xmi_lua_tostring +# define lua_tonumber xmi_lua_tonumber +# define lua_tointeger xmi_lua_tointeger + +// push macros +# define lua_pushnil xmi_lua_pushnil +# define lua_pushinteger xmi_lua_pushinteger +# define lua_pushboolean xmi_lua_pushboolean +# define lua_pushnumber xmi_lua_pushnumber +# define lua_pushlstring xmi_lua_pushlstring +# define lua_pushstring xmi_lua_pushstring +# define lua_pushvfstring xmi_lua_pushvfstring +# define lua_pushfstring xmi_lua_pushfstring +# define lua_pushcclosure xmi_lua_pushcclosure +# define lua_pushlightuserdata xmi_lua_pushlightuserdata +# define lua_pushthread xmi_lua_pushthread +# define lua_pushcfunction xmi_lua_pushcfunction +# define lua_pushliteral xmi_lua_pushliteral + +// stack functions +# define lua_absindex xmi_lua_absindex +# define lua_gettop xmi_lua_gettop +# define lua_settop xmi_lua_settop +# define lua_pushvalue xmi_lua_pushvalue +# define lua_rotate xmi_lua_rotate +# define lua_copy xmi_lua_copy +# define lua_checkstack xmi_lua_checkstack +# define lua_xmove xmi_lua_xmove +# define lua_insert xmi_lua_insert +# define lua_remove xmi_lua_remove +# define lua_replace xmi_lua_replace + +// miscellaneous functions +# define lua_error xmi_lua_error +# define lua_next xmi_lua_next +# define lua_concat xmi_lua_concat +# define lua_len xmi_lua_len +# define lua_stringtonumber xmi_lua_stringtonumber +# define lua_getallocf xmi_lua_getallocf +# define lua_setallocf xmi_lua_setallocf +# define lua_toclose xmi_lua_toclose +# define lua_closeslot xmi_lua_closeslot + +// 'load' and 'call' functions +# ifndef XMI_USE_LUAJIT +# define lua_callk xmi_lua_callk +# define lua_pcallk xmi_lua_pcallk +# endif +# define lua_call xmi_lua_call +# define lua_pcall xmi_lua_pcall +# define lua_load xmi_lua_load +# define lua_dump xmi_lua_dump + +// luaL macros +# define luaL_getmetafield xmi_luaL_getmetafield +# define luaL_callmeta xmi_luaL_callmeta +# define luaL_tolstring xmi_luaL_tolstring +# define luaL_argerror xmi_luaL_argerror +# define luaL_typeerror xmi_luaL_typeerror +# define luaL_checklstring xmi_luaL_checklstring +# define luaL_optlstring xmi_luaL_optlstring +# define luaL_checknumber xmi_luaL_checknumber +# define luaL_optnumber xmi_luaL_optnumber +# define luaL_checkinteger xmi_luaL_checkinteger +# define luaL_optinteger xmi_luaL_optinteger +# define luaL_checkstack xmi_luaL_checkstack +# define luaL_checktype xmi_luaL_checktype +# define luaL_checkany xmi_luaL_checkany +# define luaL_newmetatable xmi_luaL_newmetatable +# define luaL_setmetatable xmi_luaL_setmetatable +# define luaL_testudata xmi_luaL_testudata +# define luaL_checkudata xmi_luaL_checkudata +# define luaL_where xmi_luaL_where +# define luaL_error xmi_luaL_error +# define luaL_checkoption xmi_luaL_checkoption +# define luaL_fileresult xmi_luaL_fileresult +# define luaL_execresult xmi_luaL_execresult +# define luaL_setfuncs xmi_luaL_setfuncs + +# define luaL_newlibtable xmi_luaL_newlibtable +# define luaL_newlib xmi_luaL_newlib +# define luaL_argcheck xmi_luaL_argcheck +# define luaL_argexpected xmi_luaL_argexpected +# define luaL_checkstring xmi_luaL_checkstring +# define luaL_optstring xmi_luaL_optstring +# define luaL_typename xmi_luaL_typename +# define luaL_dofile xmi_luaL_dofile +# define luaL_dostring xmi_luaL_dostring +# define luaL_getmetatable xmi_luaL_getmetatable +# define luaL_opt xmi_luaL_opt +# define luaL_loadbuffer xmi_luaL_loadbuffer +# define luaL_pushfail xmi_luaL_pushfail + +// types +# define luaL_Reg xmi_luaL_Reg +# define lua_State xmi_lua_State +# define lua_Number xmi_lua_Number +# define lua_Integer xmi_lua_Integer +# define lua_Unsigned xmi_lua_Unsigned +# define lua_KContext xmi_lua_KContext +# define lua_CFunction xmi_lua_CFunction +# define lua_KFunction xmi_lua_KFunction +# define lua_Reader xmi_lua_Reader +# define lua_Writer xmi_lua_Writer +# define lua_Alloc xmi_lua_Alloc +# define lua_WarnFunction xmi_lua_WarnFunction +#endif + +// extern c +#ifdef __cplusplus +# define xmi_extern_c_enter extern "C" { +# define xmi_extern_c_leave } +#else +# define xmi_extern_c_enter +# define xmi_extern_c_leave +#endif + +// define lua module entry function +#define luaopen(name, lua) \ +__dummy = 1; \ +xmi_lua_ops_t* g_lua_ops = NULL; \ +xmi_extern_c_enter \ +int xmiopen_##name(lua); \ +xmi_extern_c_leave \ +int xmisetup(xmi_lua_ops_t* ops) { \ + g_lua_ops = ops; \ + return __dummy; \ +} \ +int xmiopen_##name(lua) + +/* ////////////////////////////////////////////////////////////////////////////////////// + * types + */ +typedef LUA_NUMBER xmi_lua_Number; +typedef LUA_INTEGER xmi_lua_Integer; +#ifndef XMI_USE_LUAJIT +typedef LUA_UNSIGNED xmi_lua_Unsigned; +typedef LUA_KCONTEXT xmi_lua_KContext; +#endif + +typedef struct xmi_lua_State_ { + int dummy; +}xmi_lua_State; + +typedef int (*xmi_lua_CFunction)(lua_State* lua); +#ifndef XMI_USE_LUAJIT +typedef int (*xmi_lua_KFunction)(lua_State* lua, int status, lua_KContext ctx); +#endif +typedef const char* (*xmi_lua_Reader)(lua_State* lua, void* ud, size_t* sz); +typedef int (*xmi_lua_Writer)(lua_State* lua, const void* p, size_t sz, void* ud); +typedef void* (*xmi_lua_Alloc)(void* ud, void* ptr, size_t osize, size_t nsize); +typedef void (*xmi_lua_WarnFunction)(void* ud, const char* msg, int tocont); + +typedef struct xmi_luaL_Reg_ { + char const* name; + xmi_lua_CFunction func; +}xmi_luaL_Reg; + +typedef struct xmi_lua_ops_t_ { + + // get functions +#ifdef XMI_USE_LUAJIT + void* (*_lua_newuserdata)(lua_State* lua, size_t sz); + void (*_lua_gettable)(lua_State* lua, int idx); + void (*_lua_getfield)(lua_State* lua, int idx, const char* k); + void (*_lua_rawgeti)(lua_State* lua, int idx, int n); + void (*_lua_rawget)(lua_State* lua, int idx); +#else + int (*_lua_getglobal)(lua_State* lua, const char* name); + int (*_lua_geti)(lua_State* lua, int idx, lua_Integer n); + int (*_lua_rawgetp)(lua_State* lua, int idx, const void* p); + int (*_lua_getiuservalue)(lua_State* lua, int idx, int n); + void* (*_lua_newuserdatauv)(lua_State* lua, size_t sz, int nuvalue); + int (*_lua_gettable)(lua_State* lua, int idx); + int (*_lua_getfield)(lua_State* lua, int idx, const char* k); + int (*_lua_rawgeti)(lua_State* lua, int idx, lua_Integer n); + int (*_lua_rawget)(lua_State* lua, int idx); +#endif + void (*_lua_createtable)(lua_State* lua, int narr, int nrec); + int (*_lua_getmetatable)(lua_State* lua, int objindex); + + // set functions +#ifdef XMI_USE_LUAJIT + void (*_lua_rawseti)(lua_State* lua, int idx, int n); +#else + void (*_lua_setglobal)(lua_State* lua, const char* name); + void (*_lua_seti)(lua_State* lua, int idx, lua_Integer n); + void (*_lua_rawsetp)(lua_State* lua, int idx, const void* p); + int (*_lua_setiuservalue)(lua_State* lua, int idx, int n); + void (*_lua_rawseti)(lua_State* lua, int idx, lua_Integer n); +#endif + void (*_lua_settable)(lua_State* lua, int idx); + void (*_lua_setfield)(lua_State* lua, int idx, const char* k); + void (*_lua_rawset)(lua_State* lua, int idx); + int (*_lua_setmetatable)(lua_State* lua, int objindex); + + // access functions + int (*_lua_isnumber)(lua_State* lua, int idx); + int (*_lua_isstring)(lua_State* lua, int idx); + int (*_lua_iscfunction)(lua_State* lua, int idx); + int (*_lua_isuserdata)(lua_State* lua, int idx); + int (*_lua_type)(lua_State* lua, int idx); + const char* (*_lua_typename)(lua_State* lua, int tp); +#ifndef XMI_USE_LUAJIT + int (*_lua_isinteger)(lua_State* lua, int idx); +#endif + + lua_Number (*_lua_tonumberx)(lua_State* lua, int idx, int* isnum); + lua_Integer (*_lua_tointegerx)(lua_State* lua, int idx, int* isnum); + int (*_lua_toboolean)(lua_State* lua, int idx); + const char* (*_lua_tolstring)(lua_State* lua, int idx, size_t* len); + lua_CFunction (*_lua_tocfunction)(lua_State* lua, int idx); + void* (*_lua_touserdata)(lua_State* lua, int idx); + lua_State* (*_lua_tothread)(lua_State* lua, int idx); + const void* (*_lua_topointer)(lua_State* lua, int idx); +#ifndef XMI_USE_LUAJIT + lua_Unsigned (*_lua_rawlen)(lua_State* lua, int idx); +#endif + + // push functions + void (*_lua_pushnil)(lua_State* lua); + void (*_lua_pushinteger)(lua_State* lua, lua_Integer n); + void (*_lua_pushboolean)(lua_State* lua, int b); + void (*_lua_pushnumber)(lua_State* lua, lua_Number n); +#ifdef XMI_USE_LUAJIT + void (*_lua_pushlstring)(lua_State* lua, const char* s, size_t len); + void (*_lua_pushstring)(lua_State* lua, const char* s); +#else + const char* (*_lua_pushlstring)(lua_State* lua, const char* s, size_t len); + const char* (*_lua_pushstring)(lua_State* lua, const char* s); +#endif + const char* (*_lua_pushvfstring)(lua_State* lua, const char* fmt, va_list argp); + const char* (*_lua_pushfstring)(lua_State* lua, const char* fmt, ...); + void (*_lua_pushcclosure)(lua_State* lua, lua_CFunction fn, int n); + void (*_lua_pushlightuserdata)(lua_State* lua, void* p); + int (*_lua_pushthread)(lua_State* lua); + + // stack functions +#ifdef XMI_USE_LUAJIT + void (*_lua_insert)(lua_State* lua, int idx); + void (*_lua_remove)(lua_State* lua, int idx); + void (*_lua_replace)(lua_State* lua, int idx); +#else + int (*_lua_absindex)(lua_State* lua, int idx); + void (*_lua_rotate)(lua_State* lua, int idx, int n); +#endif + int (*_lua_gettop)(lua_State* lua); + void (*_lua_settop)(lua_State* lua, int idx); + void (*_lua_pushvalue)(lua_State* lua, int idx); + void (*_lua_copy)(lua_State* lua, int fromidx, int toidx); + int (*_lua_checkstack)(lua_State* lua, int n); + void (*_lua_xmove)(lua_State* from, lua_State* to, int n); + + // miscellaneous functions + int (*_lua_error)(lua_State* lua); + int (*_lua_next)(lua_State* lua, int idx); + void (*_lua_concat)(lua_State* lua, int n); + lua_Alloc (*_lua_getallocf)(lua_State* lua, void** ud); + void (*_lua_setallocf)(lua_State* lua, lua_Alloc f, void* ud); +#ifndef XMI_USE_LUAJIT + void (*_lua_len)(lua_State* lua, int idx); + void (*_lua_toclose)(lua_State* lua, int idx); + void (*_lua_closeslot)(lua_State* lua, int idx); + size_t (*_lua_stringtonumber)(lua_State* lua, const char* s); +#endif + + // 'load' and 'call' functions +#ifdef XMI_USE_LUAJIT + void (*_lua_call)(lua_State* lua, int nargs, int nresults); + int (*_lua_pcall)(lua_State* lua, int nargs, int nresults, int errfunc); + int (*_lua_load)(lua_State* lua, lua_Reader reader, void* dt, const char* chunkname); + int (*_lua_dump)(lua_State* lua, lua_Writer writer, void* data); +#else + void (*_lua_callk)(lua_State* lua, int nargs, int nresults, lua_KContext ctx, lua_KFunction k); + int (*_lua_pcallk)(lua_State* lua, int nargs, int nresults, int errfunc, lua_KContext ctx, lua_KFunction k); + int (*_lua_load)(lua_State* lua, lua_Reader reader, void* dt, const char* chunkname, const char* mode); + int (*_lua_dump)(lua_State* lua, lua_Writer writer, void* data, int strip); +#endif + + // luaL functions +#ifndef XMI_USE_LUAJIT + const char* (*_luaL_tolstring)(lua_State* lua, int idx, size_t* len); + int (*_luaL_typeerror)(lua_State* lua, int arg, const char* tname); +#endif + int (*_luaL_getmetafield)(lua_State* lua, int obj, const char* e); + int (*_luaL_callmeta)(lua_State* lua, int obj, const char* e); + int (*_luaL_argerror)(lua_State* lua, int numarg, const char* extramsg); + const char* (*_luaL_checklstring)(lua_State* lua, int arg, size_t* l); + const char* (*_luaL_optlstring)(lua_State* lua, int arg, const char* def, size_t* l); + lua_Number (*_luaL_checknumber)(lua_State* lua, int arg); + lua_Number (*_luaL_optnumber)(lua_State* lua, int arg, lua_Number def); + lua_Integer (*_luaL_checkinteger)(lua_State* lua, int idx); + lua_Integer (*_luaL_optinteger)(lua_State* lua, int arg, lua_Integer def); + void (*_luaL_checkstack)(lua_State* lua, int sz, const char* msg); + void (*_luaL_checktype)(lua_State* lua, int arg, int t); + void (*_luaL_checkany)(lua_State* lua, int arg); + int (*_luaL_newmetatable)(lua_State* lua, const char* tname); + void (*_luaL_setmetatable)(lua_State* lua, const char* tname); + void* (*_luaL_testudata)(lua_State* lua, int ud, const char* tname); + void* (*_luaL_checkudata)(lua_State* lua, int ud, const char* tname); + void (*_luaL_where)(lua_State* lua, int lvl); + int (*_luaL_error)(lua_State* lua, const char* fmt, ...); + int (*_luaL_checkoption)(lua_State* lua, int arg, const char* def, const char* const lst[]); + int (*_luaL_fileresult)(lua_State* lua, int stat, const char* fname); + int (*_luaL_execresult)(lua_State* lua, int stat); + void (*_luaL_setfuncs)(lua_State* lua, const luaL_Reg* l, int nup); + +}xmi_lua_ops_t; + +/* ////////////////////////////////////////////////////////////////////////////////////// + * globals + */ +extern xmi_lua_ops_t* g_lua_ops; + +/* ////////////////////////////////////////////////////////////////////////////////////// + * interfaces + */ +xmi_extern_c_enter + +// setup lua interfaces +int xmisetup(xmi_lua_ops_t* ops); + +xmi_extern_c_leave +#endif + + diff --git a/xmake/templates/c++/module.shared/project/modules/shared/foo/src/foo.cpp b/xmake/templates/c++/module.shared/project/modules/shared/foo/src/foo.cpp index b6eb451ba..a98baca02 100644 --- a/xmake/templates/c++/module.shared/project/modules/shared/foo/src/foo.cpp +++ b/xmake/templates/c++/module.shared/project/modules/shared/foo/src/foo.cpp @@ -1,8 +1,4 @@ -#include <stdlib.h> -extern "C" { -#include <lua.h> -#include <lauxlib.h> -} +#include <xmi.h> static int add(lua_State* lua) { int a = lua_tointeger(lua, 1); @@ -18,16 +14,14 @@ static int sub(lua_State* lua) { return 1; } -static const luaL_Reg g_funcs[] = { - {"add", add}, - {"sub", sub}, - {NULL, NULL} -}; - -extern "C" { - int luaopen_foo(lua_State* lua) { - lua_newtable(lua); - luaL_setfuncs(lua, g_funcs, 0); - return 1; - } +int luaopen(foo, lua_State* lua) { + static const luaL_Reg funcs[] = { + {"add", add}, + {"sub", sub}, + {NULL, NULL} + }; + lua_newtable(lua); + luaL_setfuncs(lua, funcs, 0); + return 1; } + diff --git a/xmake/templates/c++/module.shared/project/modules/shared/foo/xmake.lua b/xmake/templates/c++/module.shared/project/modules/shared/foo/xmake.lua index deef51363..9b3423d41 100644 --- a/xmake/templates/c++/module.shared/project/modules/shared/foo/xmake.lua +++ b/xmake/templates/c++/module.shared/project/modules/shared/foo/xmake.lua @@ -1,9 +1,6 @@ add_rules("mode.debug", "mode.release") -add_requires("lua 5.4") - target("foo") add_rules("module.shared") add_files("src/foo.cpp") - add_packages("lua") diff --git a/xmake/templates/c/module.shared/project/modules/shared/foo/src/foo.c b/xmake/templates/c/module.shared/project/modules/shared/foo/src/foo.c index 3024f9380..a98baca02 100644 --- a/xmake/templates/c/module.shared/project/modules/shared/foo/src/foo.c +++ b/xmake/templates/c/module.shared/project/modules/shared/foo/src/foo.c @@ -1,6 +1,4 @@ -#include <stdlib.h> -#include <lua.h> -#include <lauxlib.h> +#include <xmi.h> static int add(lua_State* lua) { int a = lua_tointeger(lua, 1); @@ -16,14 +14,14 @@ static int sub(lua_State* lua) { return 1; } -static const luaL_Reg g_funcs[] = { - {"add", add}, - {"sub", sub}, - {NULL, NULL} -}; - -int luaopen_foo(lua_State* lua) { +int luaopen(foo, lua_State* lua) { + static const luaL_Reg funcs[] = { + {"add", add}, + {"sub", sub}, + {NULL, NULL} + }; lua_newtable(lua); - luaL_setfuncs(lua, g_funcs, 0); + luaL_setfuncs(lua, funcs, 0); return 1; } + diff --git a/xmake/templates/c/module.shared/project/modules/shared/foo/xmake.lua b/xmake/templates/c/module.shared/project/modules/shared/foo/xmake.lua index ad4590ffa..035573d9f 100644 --- a/xmake/templates/c/module.shared/project/modules/shared/foo/xmake.lua +++ b/xmake/templates/c/module.shared/project/modules/shared/foo/xmake.lua @@ -1,9 +1,6 @@ add_rules("mode.debug", "mode.release") -add_requires("lua 5.4") - target("foo") add_rules("module.shared") add_files("src/foo.c") - add_packages("lua") |
