Table::TableFind Table::getTable(const String &key, bool create) { SLB_DEBUG_CALL; if (_separator.empty()) return TableFind(this,key); String::size_type pos = key.find(_separator); if (pos != String::npos) { const String &base = key.substr(0, pos); const String &next = key.substr(pos+_separator.length()); Table* subtable = slb_dynamic_cast<Table>(rawGet(base)); if (subtable == 0) { if (create) { SLB_DEBUG(6, "Table (%p) create Subtable %s -> %s", this, base.c_str(), next.c_str()); subtable = new (Malloc(sizeof(Table))) Table(_separator, _cacheable); rawSet(base,subtable); } else { return TableFind((Table*)0,key); // not found } } return subtable->getTable(next, create); //< TODO: recursivity... replace with iterative version. } // else : return TableFind(this,key); }
void LuaInterface::clearTable(int index) { assert(hasIndex(index) && isTable(index)); pushNil(); // table, nil bool stop = false; while(next(index-1)) { // table, key, value pop(); // table, key pushValue(); // table, key, key if(next(index-2)) { // table, key, nextkey, value pop(); // table, key, nextkey insert(-2); // table, nextkey, key pushNil(); // table, nextkey, key, nil rawSet(index-3); // table, nextkey } else { // table, key pushNil(); // table, key, nil rawSet(index-2); // table break; } } }