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.
| 107 | // requested number of tokens if specified and > 0, or nil if we already |
| 108 | // processed the last row in the file. |
| 109 | int 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 | |
| 133 | DFHACK_PLUGIN_LUA_FUNCTIONS { |
| 134 | DFHACK_LUA_FUNCTION(open_xlsx_file), |
nothing calls this directly
no test coverage detected