LUADOC - Farming Simulator 19

DataGrid

Description
A datagrid datastructure
Functions

delete

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

getValue

Description
Gets value at given row and column
Definition
getValue(integer rowIndex, integer colIndex)
Arguments
integerrowIndexindex of row
integercolIndexindex of column
Return Values
tablevaluevalue at the given position
Code
44function DataGrid:getValue(rowIndex, colIndex)
45 if rowIndex < 1 or rowIndex > self.numRows then
46 g_logManager:error("rowIndex out of bounds!")
47 printCallstack()
48 return nil
49 end
50 if colIndex < 1 or colIndex > self.numColumns then
51 g_logManager: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 i=1, numRows do
27 table.insert(self.grid, {})
28 end
29
30 return self
31end

setValue

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