Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion luaclang-parser.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
#include <clang-c/Index.h>
#include <lua.hpp>



#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"
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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}
Expand Down Expand Up @@ -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},
Expand All @@ -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);
Expand Down