MCPcopy Create free account
hub / github.com/danomatika/ofxLua / clearTable

Method clearTable

src/ofxLua.cpp:753–782  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

751}
752
753void ofxLua::clearTable() {
754 if(!isValid()) {
755 return;
756 }
757
758 if(tables.empty()) {
759 ofLogWarning("ofxLua") << "No table to clear, did you push?";
760 return;
761 }
762 if(!lua_istable(L, LUA_STACK_TOP)) {
763 ofLogWarning("ofxLua") << "Couldn't clear table, stack var is not a table";
764 }
765
766 // clears all elements by setting them to nil, this way the original table
767 // pointer is preserved
768 lua_pushvalue(L, LUA_STACK_TOP); // stack: -1 => table
769 lua_pushnil(L); // stack: -1 => table; -2 => nil
770
771 while(lua_next(L, -2)) {
772 // stack: -3 => table; -2 => key; -1 => value
773 lua_pop(L, 1); // stack: -2 => table; -1 => key
774
775 lua_pushvalue(L, -1);
776 lua_pushnil(L);
777 lua_settable(L, -4); // stack: -2 => table; -1 => key
778 }
779
780 // stack: -1 => table
781 lua_pop(L, 1); // stack:
782}
783
784void ofxLua::clearTable(const std::string& tableName) {
785 if(!pushTable(tableName)) {

Callers 1

runTestsMethod · 0.80

Calls 4

lua_pushvalueFunction · 0.85
lua_pushnilFunction · 0.85
lua_nextFunction · 0.85
lua_settableFunction · 0.85

Tested by

no test coverage detected