| 151 | } |
| 152 | |
| 153 | bool 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 | |
| 199 | void CtrlrLuaMethod::setValid (const bool _methodIsValid) |
| 200 | { |
nothing calls this directly
no test coverage detected