LUADOC - Farming Simulator 22

DataGrid

Description
A datagrid datastructure
Functions

delete

Description
Deletes data grid
Definition
delete()
Code
35function DataGrid:delete()
36 self.grid = nil
37end

getValue

Description
@param integer colIndex index of column
Definition
getValue()
Return Values
tablevaluevalue at the given position
Code
44function DataGrid:getValue(rowIndex, colIndex)
45 if rowIndex < 1 or rowIndex > self.numRows then
46 Logging.error("rowIndex out of bounds!")
47 printCallstack()
48 return nil
49 end
50 if colIndex < 1 or colIndex > self.numColumns then
51 Logging.error("colIndex out of bounds!")
52 printCallstack()
53 return nil
54 end
55
56 return self.grid[rowIndex][colIndex]
57end

new

Description
Creating data grid
Definition
new(integer numRows, integer numColumns, table customMt)
Arguments
integernumRowsnumber of rows
integernumColumnsnumber of columns
tablecustomMtcustom metatable
Return Values
tableinstanceinstance of object
Code
19function DataGrid.new(numRows, numColumns, customMt)
20 local self = {}
21 setmetatable(self, customMt or DataGrid_mt)
22
23 self.grid = {}
24 self.numRows = numRows
25 self.numColumns = numColumns
26 for _=1, numRows do
27 table.insert(self.grid, {})
28 end
29
30 return self
31end

setValue

Description
@param integer colIndex index of column
Definition
setValue(table value)
Arguments
tablevaluevalue at the given position
Code
64function DataGrid:setValue(rowIndex, colIndex, value)
65 if rowIndex < 1 or rowIndex > self.numRows then
66 Logging.error("rowIndex out of bounds!")
67 printCallstack()
68 return false
69 end
70 if colIndex < 1 or colIndex > self.numColumns then
71 Logging.error("colIndex out of bounds!")
72 printCallstack()
73 return false
74 end
75
76 self.grid[rowIndex][colIndex] = value
77 return true
78end