MCPcopy Create free account
hub / github.com/danomatika/ofxLua / doString

Method doString

src/ofxLua.cpp:109–151  ·  view source on GitHub ↗

------------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

107
108//------------------------------------------------------------------------------
109bool ofxLua::doString(const std::string& text) {
110
111 if(!isValid()) {
112 ofLogError("ofxLua") << "Cannot do std::string, lua state not inited!";
113 return false;
114 }
115
116 if(text.length() < 10) {
117 ofLogVerbose("ofxLua") << "Doing std::string: \"" << text << "\"";
118 }
119 else {
120 ofLogVerbose("ofxLua") << "Doing std::string: \"" << text.substr(0,10) << "..." << "\"";
121 }
122
123 // load the std::string
124 int ret = luaL_loadstring(L, text.c_str());
125 if(ret != 0) {
126 switch(ret) {
127 case LUA_ERRSYNTAX: {
128 std::string msg = (std::string) lua_tostring(L, LUA_STACK_TOP);
129 errorOccurred(msg);
130 break;
131 }
132 case LUA_ERRMEM: {
133 std::string msg = "Memory error",
134 errorOccurred(msg);
135 break;
136 }
137 }
138
139 return false;
140 }
141
142 // run the std::string
143 ret = lua_pcall(L, 0, LUA_MULTRET, 0);
144 if(ret != 0) {
145 std::string msg = (std::string) lua_tostring(L, LUA_STACK_TOP);
146 errorOccurred(msg);
147 return false;
148 }
149
150 return true;
151}
152
153//------------------------------------------------------------------------------
154bool ofxLua::doScript(const std::string& script, bool changeDir) {

Callers 1

keyPressedMethod · 0.80

Calls 1

luaL_loadstringFunction · 0.85

Tested by

no test coverage detected