called from the metamethod for __newindex obj is the object pointer
| 1158 | // called from the metamethod for __newindex |
| 1159 | // obj is the object pointer |
| 1160 | int luabind::detail::class_rep::lua_class_settable(lua_State* L) |
| 1161 | { |
| 1162 | object_rep* obj = static_cast<object_rep*>(lua_touserdata(L, 1)); |
| 1163 | class_rep* crep = obj->crep(); |
| 1164 | |
| 1165 | #ifndef LUABIND_NO_ERROR_CHECKING |
| 1166 | |
| 1167 | if (obj->flags() & object_rep::call_super) |
| 1168 | { |
| 1169 | // this block makes sure the string_class is destructed |
| 1170 | // before lua_error is called |
| 1171 | { |
| 1172 | string_class msg = "derived class '"; |
| 1173 | msg += crep->name(); |
| 1174 | msg += "'must call super on base"; |
| 1175 | lua_pushstring(L, msg.c_str()); |
| 1176 | } |
| 1177 | lua_error(L); |
| 1178 | } |
| 1179 | |
| 1180 | #endif |
| 1181 | |
| 1182 | // we have to ignore the first argument since this may point to |
| 1183 | // a method that is not present in this class (but in a subclass) |
| 1184 | // BUG: This will not work with keys with extra nulls in them |
| 1185 | const char* key = lua_tostring(L, 2); |
| 1186 | |
| 1187 | |
| 1188 | map_class<const char*, class_rep::callback, ltstr>::iterator j = crep->m_setters.find(key); |
| 1189 | |
| 1190 | // if the strlen(key) is not the true length, |
| 1191 | // it means that the member-name contains |
| 1192 | // extra nulls. luabind does not support such |
| 1193 | // names as member names. So, use the lua |
| 1194 | // table as fall-back |
| 1195 | if (j == crep->m_setters.end() |
| 1196 | || std::strlen(key) != lua_strlen(L, 2)) |
| 1197 | { |
| 1198 | map_class<const char*, class_rep::callback, ltstr>::iterator k = crep->m_getters.find(key); |
| 1199 | |
| 1200 | #ifndef LUABIND_NO_ERROR_CHECKING |
| 1201 | |
| 1202 | if (k != crep->m_getters.end()) |
| 1203 | { |
| 1204 | { |
| 1205 | string_class msg = "cannot set property '"; |
| 1206 | msg += crep->name(); |
| 1207 | msg += "."; |
| 1208 | msg += key; |
| 1209 | msg += "', because it's read only"; |
| 1210 | lua_pushstring(L, msg.c_str()); |
| 1211 | } |
| 1212 | lua_error(L); |
| 1213 | } |
| 1214 | |
| 1215 | #endif |
| 1216 | |
| 1217 | detail::lua_reference const& tbl = obj->get_lua_table(); |
nothing calls this directly
no test coverage detected