| 173 | } |
| 174 | |
| 175 | void ScriptWriter::endComplex() { |
| 176 | if(_layers.empty()) { |
| 177 | SCRIPT_BEGIN(_pState) |
| 178 | SCRIPT_ERROR("end struct called without begin struct calling"); |
| 179 | SCRIPT_END |
| 180 | return; |
| 181 | } |
| 182 | |
| 183 | /* Allow to create method on typed object! |
| 184 | function onTypedObject(type,object) |
| 185 | if type=="Cat" then |
| 186 | function object:meow() |
| 187 | print("meow") |
| 188 | end |
| 189 | end |
| 190 | end*/ |
| 191 | lua_getfield(_pState, -1, "__type"); |
| 192 | if (lua_isstring(_pState, -1)) { |
| 193 | int top=lua_gettop(_pState); |
| 194 | SCRIPT_BEGIN(_pState) |
| 195 | SCRIPT_FUNCTION_BEGIN("onTypedObject", LUA_ENVIRONINDEX) |
| 196 | lua_pushvalue(_pState, top); // type |
| 197 | lua_pushvalue(_pState, top-1); // object |
| 198 | SCRIPT_FUNCTION_CALL |
| 199 | SCRIPT_FUNCTION_END |
| 200 | SCRIPT_END |
| 201 | } |
| 202 | lua_pop(_pState, 1); |
| 203 | |
| 204 | if (_layers.back()!=-1) { |
| 205 | _layers.pop_back(); |
| 206 | return end(); |
| 207 | } |
| 208 | _layers.back()=1; // mixed object, now we are writing the array part |
| 209 | } |