Skip to content
Merged
Show file tree
Hide file tree
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
9 changes: 6 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions cmake/Modules/FindLuaJIT.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
22 changes: 21 additions & 1 deletion src/imstring.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
5 changes: 3 additions & 2 deletions src/imvue_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -97,6 +97,7 @@ namespace ImVue {
}
ctx->fs = fs;
ctx->script = script;
ctx->userdata = userdata;
return ctx;
}

Expand All @@ -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;
}
Expand Down
4 changes: 3 additions & 1 deletion src/imvue_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 22 additions & 2 deletions src/imvue_element.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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);
}
}
}

Expand Down
29 changes: 6 additions & 23 deletions src/imvue_element.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<ImString>().c_str();
i++;
continue;
}
Expand Down Expand Up @@ -714,10 +714,10 @@ namespace ImVue {
typedef std::map<const char*, HandlerFactory*, CmpAttributeName> Handlers;
Handlers mHandlers;

typedef std::vector<std::string> Inheritance;
typedef std::vector<ImString> Inheritance;
Inheritance mInheritance;

std::string mTag;
ImString mTag;
};

/**
Expand Down Expand Up @@ -790,7 +790,7 @@ namespace ImVue {
if(mTag == name) {
return *this;
}
mInheritance.push_back(name);
mInheritance.push_back(ImString(name));
return *this;
}
};
Expand Down Expand Up @@ -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;

Expand Down