User Tools

Site Tools


doc:lua:start

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Last revisionBoth sides next revision
doc:lua:start [2011/06/19 19:45] admindoc:lua:start [2013/12/29 16:14] admin
Line 114: Line 114:
   * Flagset(Integer): This is an integer value, where each bit represents a flag. The meanings of these flags are explained in the [[:dev:clientdesignguide|Client design guide]] (look for System Flags)   * Flagset(Integer): This is an integer value, where each bit represents a flag. The meanings of these flags are explained in the [[:dev:clientdesignguide|Client design guide]] (look for System Flags)
   * id(String): The id is used to add an individual marker to a menu item. This is widely used when one single Lua function should support many menu items. This is descripted in detail in the [[#the_menu_function_call|Menu Function Calls]] below.   * id(String): The id is used to add an individual marker to a menu item. This is widely used when one single Lua function should support many menu items. This is descripted in detail in the [[#the_menu_function_call|Menu Function Calls]] below.
 +
 +=== "advanced" addElement(Description, function, initialValue, Flagset, id, type) === 
 +
 +
 +
 +
  
 === pageDone() === === pageDone() ===
Line 174: Line 180:
  
 Writes //String// to the build in output console. Writes //String// to the build in output console.
 +
 +=== dbLookup(db-File , searchstring) ===
 +
 +Searches in the //db-file// for all entries with index //searchstring//. The //db-file// needs to be in the same directory as the Lua- script itself. The //db-file// itself is made by [[doc:oodbcreate|oodbCreate]].
 +
 +dbLookup() returns a Lua table
 +  
 +  myTable = dbLookup("dtc.oodb", "0815")
 +
 +//myTable.len// tells the success status:
 +  * if //myTable.len// < 0 then an error has occured
 +  * if //myTable.len// = 0 then //searchstring// has not been found
 +  * if //myTable.len// > 0 then //myTable.len// tells the number of entries found
 +
 +When something has been found, than //myTable// contains two sections, //header// and //data//.
 +
 +The header section is needed in case you don't know in which column your wanted result is stored; you can identify the column by its column header name instead:
 +
 +   col= myTable.header["DTC-Text"]
 +   print (col)
 +   2
 +   
 + //myTable.header.size// tells the number of colums in total **without** the first index column, which is always surpressed.
 +
 +
 +The //data// section then contains the found data itself, arranged as a two dimensional array, sorted by rows and columns. 
 +
 +    result=myTable.data[row][column]
 +  
 +**ATTENTION**: Although the row and column indexes are expressed as numbers (1,2,3,4..), they are internally represented as string values ("1","2","3","4"...), so to read the result correctly, numeric row and column counters need to be converted to strings first to address the array correctly
 +
 +    column=3
 +    row=2
 +    result=myTable.data[tostring(row)][tostring(column)])
 +    
 +    
 + Here after all a piece of sample code
 +
 +<code lua>
 +myTable= dbLookupCall("dtc.oodb","005")
 +
 +print ("header")
 +for k,v in pairs (myTable.header) do
 +    print (k,"=",v)
 +end
 +
 +nrOfColumns = myTable.header.size
 +nrOfRows = myTable.len
 +
 +print ("Rows x Columns:" ,nrOfRows, nrOfColumns)
 +
 +
 +for row = 1 , nrOfRows , 1 do
 +  for column = 1 , nrOfColumns, 1 do 
 +  
 +   print (cy, cx, myTable.data[tostring(row)][tostring(column)])
 +  end
 +end
 +</code>
  
 ===== Some Programming Tricks ===== ===== Some Programming Tricks =====
Line 215: Line 280:
  
 By that it's possible without big efforts to fill a menu  with real data already during initialization, so the actual data is visible straight from the beginning. By that it's possible without big efforts to fill a menu  with real data already during initialization, so the actual data is visible straight from the beginning.
- 
-