From 96322d338d9ae49ac0908e5f0abc2dfc5a841461 Mon Sep 17 00:00:00 2001 From: kellygod Date: Thu, 10 Jan 2019 11:53:23 +0800 Subject: [PATCH] add windows api export support add method isConst add type get spelling --- luaclang-parser.cpp | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/luaclang-parser.cpp b/luaclang-parser.cpp index 5320f23..c72bab5 100644 --- a/luaclang-parser.cpp +++ b/luaclang-parser.cpp @@ -1,6 +1,14 @@ #include #include + + +#if defined(_WIN32) +#define EXPORT_API __declspec(dllexport) +#else +#define EXPORT_API +#endif + #define LCM_INDEX "ClangIndex" #define LCM_TU "ClangTU" #define LCM_CURSOR "ClangCursor" @@ -583,6 +591,12 @@ static int l_isStatic(lua_State *L) { return 1; } +static int l_method_isConst(lua_State *L){ + CXCursor cur = toCursor(L, 1); + lua_pushboolean(L, clang_CXXMethod_isConst(cur)); + return 1; +} + static int l_isVirtual(lua_State *L) { CXCursor cur = toCursor(L, 1); lua_pushboolean(L, clang_CXXMethod_isVirtual(cur)); @@ -621,6 +635,7 @@ static luaL_Reg cursor_functions[] = { {"definition", l_definition}, {"isStatic", l_isStatic}, {"isVirtual", l_isVirtual}, + {"isConst",l_method_isConst}, {"resultType", l_resultType}, {"__eq", l_cursorEqual}, {NULL, NULL} @@ -687,9 +702,19 @@ static int l_isConst(lua_State *L) { return 1; } +static int l_spelling(lua_State* L) +{ + CXType type = toType(L, 1); + CXString str = clang_getTypeSpelling(type); + lua_pushstring(L, clang_getCString(str)); + clang_disposeString(str); + return 1; +} + static luaL_Reg type_functions[] = { {"__tostring", l_typeToString}, {"name", l_typeToString}, + {"spelling",l_spelling}, {"canonical", l_canonical}, {"pointee", l_pointee}, {"isPod", l_isPod}, @@ -708,7 +733,7 @@ void newMetatable(lua_State *L, const char * name, luaL_Reg *reg) { lua_setfield(L, -2, "__index"); } -extern "C" int luaopen_parser(lua_State *L) { +extern "C" EXPORT_API int luaopen_parser(lua_State *L) { newMetatable(L, LCM_INDEX, index_functions); newMetatable(L, LCM_TU, tu_functions); newMetatable(L, LCM_CURSOR, cursor_functions);