MCPcopy Create free account
hub / github.com/RomanKubiak/ctrlr / setCodeInternal

Method setCodeInternal

Source/Lua/Methods/CtrlrLuaMethod.cpp:153–197  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

151}
152
153bool CtrlrLuaMethod::setCodeInternal(const String &newMethodCode)
154{
155 errorString.clear();
156 errorString.append ("Compile: "+getName()+" - ", out, Colours::black);
157
158 if (owner.isLuaDisabled())
159 {
160 errorString.append("FAILED lua is disabled\n", out.withStyle(Font::bold), Colours::darkred);
161 return (false);
162 }
163
164 bool compileRet = owner.getOwner().runCode(newMethodCode, getName());
165
166 String error;
167
168 if (compileRet && getName() != "")
169 {
170 try
171 {
172 setObject ( (luabind::object)luabind::globals (getLuaState()) [(const char *)getName().toUTF8()] );
173 }
174 catch (const luabind::error &e)
175 {
176 error = String(e.what());
177 }
178 }
179 else if (compileRet == false)
180 {
181 error = owner.getOwner().getLastError();
182 }
183
184 if (compileRet)
185 {
186 errorString.append ("OK\n", out.withStyle(Font::bold), Colours::black);
187 }
188 else
189 {
190 errorString.append ("FAILED\n", out.withStyle(Font::bold), Colours::darkred);
191 errorString.append (error + "\n" , out, Colours::darkred);
192 }
193
194 setValid(compileRet);
195
196 return (compileRet);
197}
198
199void CtrlrLuaMethod::setValid (const bool _methodIsValid)
200{

Callers

nothing calls this directly

Calls 11

globalsFunction · 0.85
withStyleMethod · 0.80
getNameFunction · 0.50
StringFunction · 0.50
clearMethod · 0.45
appendMethod · 0.45
isLuaDisabledMethod · 0.45
runCodeMethod · 0.45
getOwnerMethod · 0.45
toUTF8Method · 0.45
getLastErrorMethod · 0.45

Tested by

no test coverage detected