Skip to content

Commit e869c47

Browse files
authored
Prefer static luajit library over dynamic (#8)
1 parent 3bc688e commit e869c47

File tree

7 files changed

+63
-34
lines changed

7 files changed

+63
-34
lines changed

CMakeLists.txt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ option(IMVUE_USE_LUAJIT "use luajit" OFF)
1313

1414
set(IMVUE_LUA_VERSION "5.1" CACHE STRING "")
1515
set(LIB_NAME "imvue")
16-
set(CMAKE_CXX_STANDARD 11)
17-
set(CMAKE_CXX_STANDARD_REQUIRED ON) #...is required...
18-
set(CMAKE_CXX_EXTENSIONS OFF) #...without compiler extensions like gnu++11
16+
if(NOT CMAKE_CXX_STANDARD)
17+
set(CMAKE_CXX_STANDARD 11)
18+
endif(NOT CMAKE_CXX_STANDARD)
1919

2020
include_directories(src)
2121
include_directories("${imvue_SOURCE_DIR}/imgui")
@@ -29,6 +29,9 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
2929
if(BUILD_LUA_BINDINGS)
3030
if(IMVUE_USE_LUAJIT)
3131
find_package(LuaJIT ${IMVUE_LUA_VERSION} REQUIRED)
32+
if(LUA_STATIC_LIBRARY)
33+
set(LUA_LIBRARIES ${LUA_STATIC_LIBRARY})
34+
endif(LUA_STATIC_LIBRARY)
3235
else(IMVUE_USE_LUAJIT)
3336
find_package(Lua ${IMVUE_LUA_VERSION} REQUIRED)
3437
endif(IMVUE_USE_LUAJIT)

cmake/Modules/FindLuaJIT.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ FIND_PATH(LUA_INCLUDE_DIR lua.h
4444
)
4545

4646
FIND_LIBRARY(LUA_LIBRARY
47-
NAMES luajit-51 luajit-5.1 luajit
47+
NAMES libluajit-static.a luajit-51 luajit-5.1 luajit
4848
HINTS
4949
$ENV{LUAJIT_DIR}
5050
PATH_SUFFIXES lib64 lib
@@ -60,7 +60,7 @@ FIND_LIBRARY(LUA_LIBRARY
6060
)
6161

6262
FIND_LIBRARY(LUA_STATIC_LIBRARY
63-
NAMES libluajit-51.a libluajit-5.1.a
63+
NAMES libluajit-static.a libluajit-51.a libluajit-5.1.a
6464
HINTS
6565
$ENV{LUAJIT_DIR}
6666
PATH_SUFFIXES lib64 lib

src/imstring.h

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,27 @@ SOFTWARE.
8282

8383
operator char* () { return mData; }
8484

85-
ImString& operator=(char* string)
85+
bool operator==(const char* string)
86+
{
87+
return strcmp(string, mData) == 0;
88+
}
89+
90+
bool operator!=(const char* string)
91+
{
92+
return strcmp(string, mData) != 0;
93+
}
94+
95+
bool operator==(const ImString& string)
96+
{
97+
return strcmp(string.c_str(), mData) == 0;
98+
}
99+
100+
bool operator!=(const ImString& string)
101+
{
102+
return strcmp(string.c_str(), mData) != 0;
103+
}
104+
105+
ImString& operator=(const char* string)
86106
{
87107
if(mData)
88108
unref();

src/imvue_context.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ namespace ImVue {
8383
}
8484
}
8585

86-
Context* createContext(ElementFactory* factory, ScriptState* script, TextureManager* texture, FileSystem* fs)
86+
Context* createContext(ElementFactory* factory, ScriptState* script, TextureManager* texture, FileSystem* fs, void* userdata)
8787
{
8888
Context* ctx = new Context();
8989
memset(ctx, 0, sizeof(Context));
@@ -97,6 +97,7 @@ namespace ImVue {
9797
}
9898
ctx->fs = fs;
9999
ctx->script = script;
100+
ctx->userdata = userdata;
100101
return ctx;
101102
}
102103

@@ -106,7 +107,7 @@ namespace ImVue {
106107
script = ctx->script->clone();
107108
}
108109

109-
Context* child = createContext(ctx->factory, script, ctx->texture, ctx->fs);
110+
Context* child = createContext(ctx->factory, script, ctx->texture, ctx->fs, ctx->userdata);
110111
child->parent = ctx;
111112
return child;
112113
}

src/imvue_context.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,14 @@ namespace ImVue {
112112
FileSystem* fs;
113113
ComponentContainer* root;
114114
Context* parent;
115+
// additional userdata that will be available from all the components
116+
void* userdata;
115117
};
116118

117119
/**
118120
* Create new context
119121
*/
120-
Context* createContext(ElementFactory* factory, ScriptState* script = 0, TextureManager* texture = 0, FileSystem* fs = 0);
122+
Context* createContext(ElementFactory* factory, ScriptState* script = 0, TextureManager* texture = 0, FileSystem* fs = 0, void* userdata = 0);
121123

122124
/**
123125
* Clone existing context

src/imvue_element.cpp

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,7 @@ namespace ImVue {
780780

781781
int inheritedLayer = 0;
782782
for(Inheritance::iterator iter = mInheritance.begin(); iter != mInheritance.end(); ++iter) {
783-
ElementBuilder* b = f->get((*iter).c_str());
783+
ElementBuilder* b = f->get(iter->c_str());
784784
inheritedLayer = std::max(b->getLayer(f), inheritedLayer);
785785
}
786786

@@ -789,7 +789,27 @@ namespace ImVue {
789789

790790
void ElementBuilder::readInheritance(ElementFactory* f) {
791791
for(Inheritance::iterator iter = mInheritance.begin(); iter != mInheritance.end(); ++iter) {
792-
merge(*f->get((*iter).c_str()));
792+
merge(*f->get(iter->c_str()));
793+
}
794+
}
795+
796+
void ElementFactory::buildInheritance()
797+
{
798+
mLayers.clear();
799+
mDirty = false;
800+
801+
for(ElementBuilders::iterator iter = mElementBuilders.begin(); iter != mElementBuilders.end(); ++iter) {
802+
int layer = iter->second->getLayer(this);
803+
if(mLayers.count(layer) == 0) {
804+
mLayers[layer] = ElementBuilders();
805+
}
806+
mLayers[layer][iter->first] = iter->second;
807+
}
808+
809+
for(Layers::iterator iter = mLayers.begin(); iter != mLayers.end(); ++iter) {
810+
for(ElementBuilders::iterator it = iter->second.begin(); it != iter->second.end(); ++it) {
811+
it->second->readInheritance(this);
812+
}
793813
}
794814
}
795815

src/imvue_element.h

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -569,10 +569,10 @@ namespace ImVue {
569569
}
570570

571571
if(evaluation && std::strncmp(&str[i], "}}", 2) == 0) {
572-
scriptState->eval(&ss.str()[0], &retval, fields, element->getContext());
572+
Object object = scriptState->getObject(&ss.str()[0], fields, element->getContext());
573573
ss = std::stringstream();
574574
evaluation = false;
575-
result << retval;
575+
result << object.as<ImString>().c_str();
576576
i++;
577577
continue;
578578
}
@@ -714,10 +714,10 @@ namespace ImVue {
714714
typedef std::map<const char*, HandlerFactory*, CmpAttributeName> Handlers;
715715
Handlers mHandlers;
716716

717-
typedef std::vector<std::string> Inheritance;
717+
typedef std::vector<ImString> Inheritance;
718718
Inheritance mInheritance;
719719

720-
std::string mTag;
720+
ImString mTag;
721721
};
722722

723723
/**
@@ -790,7 +790,7 @@ namespace ImVue {
790790
if(mTag == name) {
791791
return *this;
792792
}
793-
mInheritance.push_back(name);
793+
mInheritance.push_back(ImString(name));
794794
return *this;
795795
}
796796
};
@@ -869,24 +869,7 @@ namespace ImVue {
869869
}
870870

871871
private:
872-
void buildInheritance() {
873-
mLayers.clear();
874-
mDirty = false;
875-
876-
for(ElementBuilders::iterator iter = mElementBuilders.begin(); iter != mElementBuilders.end(); ++iter) {
877-
int layer = iter->second->getLayer(this);
878-
if(mLayers.count(layer) == 0) {
879-
mLayers[layer] = ElementBuilders();
880-
}
881-
mLayers[layer][iter->first] = iter->second;
882-
}
883-
884-
for(Layers::iterator iter = mLayers.begin(); iter != mLayers.end(); ++iter) {
885-
for(ElementBuilders::iterator it = iter->second.begin(); it != iter->second.end(); ++it) {
886-
it->second->readInheritance(this);
887-
}
888-
}
889-
}
872+
void buildInheritance();
890873

891874
ElementBuilders mElementBuilders;
892875

0 commit comments

Comments
 (0)