LUA refers to "Tables" where I refer to Collections and have referred to Structures. A LUA collection contains an indexed set of objects. The index can be either an integer or a string. The index can be specified or assumed during construction. A collection is constructed by a paired set of braces({ and }) . The collection can be constructed empty or with objects in it. Here is an empty constructor:
x={}
The index is identified by a paired set of brackets ([ and ]). The index will be evaluated during assignment. A variable name is equivalent to index with it's name quoted. When elements are indexed during construction the elements must be separated by either a comma (,) or semicolon (;). Here the construction of a collection with named indexes:
x={[1]='first',[2]='second',['third']='value indexed by "third"',forth='value indexed by "forth"'}
A constructor can span lines.
During construction elements whose index is not specified are assigned to sequential integer indexes starting from 1.
A string index can be referenced using "dot" notation or by using normal bracket notation. These produce the same results:
print(x.forth)
print(x['forth'])
After construction elements can be added to the collection by placing the collection and index on the left side of the equal sign (=) in an assignment statement. Remember that the index is evaluated prior to use. Here is a small script you can try and modify to prove your understanding:
a=4;
x={
[1]='lookout index 1 will be overlayed',
'implied index of 1',
'implied index of 2',
x='"x" masquerading as a variable';
["a"]='indexed by "a" can be referenced using dot notation';
[a]='indexed by the value of a, in this case 4'
};
print('x[1]=', x[1])
print('x[2]=', x[2])
print('x["x"]=', x["x"])
print('x.a=', x.a)
print('x[4]=', x[4])
I hope you are beginning to get an idea about how FoldIt builds scripts. A script is a collection with some special syntax. Running a script means to evaluate the integer indexes in order.
Next time I'll cover functions and start to move into writing maintainable programs.
A journal of a FoldIt player's thoughts while learning to play the game and it's application to improving our lives.
Since this is a journal you may find starting from earlier articles helpful. I have covered a bit about the science, the FoldIT user interface, GUI recipes, and Script recipes. If you give me hints where I could be helpful I will focus in that general direction to my discretion. Currently I am going though the basic concepts of LUA script recipes. Once I get past intoductory LUA scripting I can start exploring the science of folding proteins by using LUA scripts.
Thursday, October 7, 2010
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment