MCPcopy Create free account
hub / github.com/DFHack/dfhack / get_row

Function get_row

plugins/xlsxreader.cpp:109–131  ·  view source on GitHub ↗

takes the sheet handle and returns a table-list of strings, limited to the requested number of tokens if specified and > 0, or nil if we already processed the last row in the file.

Source from the content-addressed store, hash-verified

107// requested number of tokens if specified and > 0, or nil if we already
108// processed the last row in the file.
109int get_row(lua_State *L) {
110 auto sheet_handle = (xlsx_sheet_handle *)get_xlsxreader_handle(L);
111 CHECK_NULL_POINTER(sheet_handle->handle);
112 lua_Integer max_tokens = luaL_optinteger(L, 2, 0);
113 bool ok = get_next_row(sheet_handle);
114 if (!ok) {
115 lua_pushnil(L);
116 } else {
117 std::string value;
118 auto cells = std::vector<std::string>();
119 while (get_next_cell(sheet_handle, value)) {
120 // read all cells in the row, even if we don't need to;
121 // otherwise xlsxio will return a spurious empty row on
122 // next call
123 if (max_tokens <= 0 || int(cells.size()) < max_tokens) {
124 cells.push_back(value);
125 }
126 }
127 Lua::PushVector(L, cells, true);
128 }
129
130 return 1;
131}
132
133DFHACK_PLUGIN_LUA_FUNCTIONS {
134 DFHACK_LUA_FUNCTION(open_xlsx_file),

Callers

nothing calls this directly

Calls 7

get_xlsxreader_handleFunction · 0.85
luaL_optintegerFunction · 0.85
get_next_rowFunction · 0.85
lua_pushnilFunction · 0.85
get_next_cellFunction · 0.85
PushVectorFunction · 0.85
sizeMethod · 0.45

Tested by

no test coverage detected