diff --git a/CMakeLists.txt b/CMakeLists.txt index 4c6ed72..01769e5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,9 +13,9 @@ option(IMVUE_USE_LUAJIT "use luajit" OFF) set(IMVUE_LUA_VERSION "5.1" CACHE STRING "") set(LIB_NAME "imvue") -set(CMAKE_CXX_STANDARD 11) -set(CMAKE_CXX_STANDARD_REQUIRED ON) #...is required... -set(CMAKE_CXX_EXTENSIONS OFF) #...without compiler extensions like gnu++11 +if(NOT CMAKE_CXX_STANDARD) + set(CMAKE_CXX_STANDARD 11) +endif(NOT CMAKE_CXX_STANDARD) include_directories(src) include_directories("${imvue_SOURCE_DIR}/imgui") @@ -29,6 +29,9 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/") if(BUILD_LUA_BINDINGS) if(IMVUE_USE_LUAJIT) find_package(LuaJIT ${IMVUE_LUA_VERSION} REQUIRED) + if(LUA_STATIC_LIBRARY) + set(LUA_LIBRARIES ${LUA_STATIC_LIBRARY}) + endif(LUA_STATIC_LIBRARY) else(IMVUE_USE_LUAJIT) find_package(Lua ${IMVUE_LUA_VERSION} REQUIRED) endif(IMVUE_USE_LUAJIT) diff --git a/cmake/Modules/FindLuaJIT.cmake b/cmake/Modules/FindLuaJIT.cmake index d973433..a0340a3 100644 --- a/cmake/Modules/FindLuaJIT.cmake +++ b/cmake/Modules/FindLuaJIT.cmake @@ -44,7 +44,7 @@ FIND_PATH(LUA_INCLUDE_DIR lua.h ) FIND_LIBRARY(LUA_LIBRARY - NAMES luajit-51 luajit-5.1 luajit + NAMES libluajit-static.a luajit-51 luajit-5.1 luajit HINTS $ENV{LUAJIT_DIR} PATH_SUFFIXES lib64 lib @@ -60,7 +60,7 @@ FIND_LIBRARY(LUA_LIBRARY ) FIND_LIBRARY(LUA_STATIC_LIBRARY - NAMES libluajit-51.a libluajit-5.1.a + NAMES libluajit-static.a libluajit-51.a libluajit-5.1.a HINTS $ENV{LUAJIT_DIR} PATH_SUFFIXES lib64 lib diff --git a/src/imstring.h b/src/imstring.h index 5b48ae0..7ab7441 100644 --- a/src/imstring.h +++ b/src/imstring.h @@ -82,7 +82,27 @@ SOFTWARE. operator char* () { return mData; } - ImString& operator=(char* string) + bool operator==(const char* string) + { + return strcmp(string, mData) == 0; + } + + bool operator!=(const char* string) + { + return strcmp(string, mData) != 0; + } + + bool operator==(const ImString& string) + { + return strcmp(string.c_str(), mData) == 0; + } + + bool operator!=(const ImString& string) + { + return strcmp(string.c_str(), mData) != 0; + } + + ImString& operator=(const char* string) { if(mData) unref(); diff --git a/src/imvue_context.cpp b/src/imvue_context.cpp index 6de5ee4..34187c9 100644 --- a/src/imvue_context.cpp +++ b/src/imvue_context.cpp @@ -83,7 +83,7 @@ namespace ImVue { } } - Context* createContext(ElementFactory* factory, ScriptState* script, TextureManager* texture, FileSystem* fs) + Context* createContext(ElementFactory* factory, ScriptState* script, TextureManager* texture, FileSystem* fs, void* userdata) { Context* ctx = new Context(); memset(ctx, 0, sizeof(Context)); @@ -97,6 +97,7 @@ namespace ImVue { } ctx->fs = fs; ctx->script = script; + ctx->userdata = userdata; return ctx; } @@ -106,7 +107,7 @@ namespace ImVue { script = ctx->script->clone(); } - Context* child = createContext(ctx->factory, script, ctx->texture, ctx->fs); + Context* child = createContext(ctx->factory, script, ctx->texture, ctx->fs, ctx->userdata); child->parent = ctx; return child; } diff --git a/src/imvue_context.h b/src/imvue_context.h index ddff858..2cf6588 100644 --- a/src/imvue_context.h +++ b/src/imvue_context.h @@ -112,12 +112,14 @@ namespace ImVue { FileSystem* fs; ComponentContainer* root; Context* parent; + // additional userdata that will be available from all the components + void* userdata; }; /** * Create new context */ - Context* createContext(ElementFactory* factory, ScriptState* script = 0, TextureManager* texture = 0, FileSystem* fs = 0); + Context* createContext(ElementFactory* factory, ScriptState* script = 0, TextureManager* texture = 0, FileSystem* fs = 0, void* userdata = 0); /** * Clone existing context diff --git a/src/imvue_element.cpp b/src/imvue_element.cpp index 1184011..bdd74a4 100644 --- a/src/imvue_element.cpp +++ b/src/imvue_element.cpp @@ -780,7 +780,7 @@ namespace ImVue { int inheritedLayer = 0; for(Inheritance::iterator iter = mInheritance.begin(); iter != mInheritance.end(); ++iter) { - ElementBuilder* b = f->get((*iter).c_str()); + ElementBuilder* b = f->get(iter->c_str()); inheritedLayer = std::max(b->getLayer(f), inheritedLayer); } @@ -789,7 +789,27 @@ namespace ImVue { void ElementBuilder::readInheritance(ElementFactory* f) { for(Inheritance::iterator iter = mInheritance.begin(); iter != mInheritance.end(); ++iter) { - merge(*f->get((*iter).c_str())); + merge(*f->get(iter->c_str())); + } + } + + void ElementFactory::buildInheritance() + { + mLayers.clear(); + mDirty = false; + + for(ElementBuilders::iterator iter = mElementBuilders.begin(); iter != mElementBuilders.end(); ++iter) { + int layer = iter->second->getLayer(this); + if(mLayers.count(layer) == 0) { + mLayers[layer] = ElementBuilders(); + } + mLayers[layer][iter->first] = iter->second; + } + + for(Layers::iterator iter = mLayers.begin(); iter != mLayers.end(); ++iter) { + for(ElementBuilders::iterator it = iter->second.begin(); it != iter->second.end(); ++it) { + it->second->readInheritance(this); + } } } diff --git a/src/imvue_element.h b/src/imvue_element.h index ce99437..63b3a90 100644 --- a/src/imvue_element.h +++ b/src/imvue_element.h @@ -569,10 +569,10 @@ namespace ImVue { } if(evaluation && std::strncmp(&str[i], "}}", 2) == 0) { - scriptState->eval(&ss.str()[0], &retval, fields, element->getContext()); + Object object = scriptState->getObject(&ss.str()[0], fields, element->getContext()); ss = std::stringstream(); evaluation = false; - result << retval; + result << object.as().c_str(); i++; continue; } @@ -714,10 +714,10 @@ namespace ImVue { typedef std::map Handlers; Handlers mHandlers; - typedef std::vector Inheritance; + typedef std::vector Inheritance; Inheritance mInheritance; - std::string mTag; + ImString mTag; }; /** @@ -790,7 +790,7 @@ namespace ImVue { if(mTag == name) { return *this; } - mInheritance.push_back(name); + mInheritance.push_back(ImString(name)); return *this; } }; @@ -869,24 +869,7 @@ namespace ImVue { } private: - void buildInheritance() { - mLayers.clear(); - mDirty = false; - - for(ElementBuilders::iterator iter = mElementBuilders.begin(); iter != mElementBuilders.end(); ++iter) { - int layer = iter->second->getLayer(this); - if(mLayers.count(layer) == 0) { - mLayers[layer] = ElementBuilders(); - } - mLayers[layer][iter->first] = iter->second; - } - - for(Layers::iterator iter = mLayers.begin(); iter != mLayers.end(); ++iter) { - for(ElementBuilders::iterator it = iter->second.begin(); it != iter->second.end(); ++it) { - it->second->readInheritance(this); - } - } - } + void buildInheritance(); ElementBuilders mElementBuilders;