![]() |
|
String s="\\\t\n\"\'\\\'hello\tworld\\";
s.replaceChar('\t', 'T');
s.replaceChar('\n', 'N');
s.replaceChar('\"', 'D');
s.replaceChar('\'', 'S');
s.replaceChar('\\', 'B');
print s;
Administrator@delta /cygdrive/f/Projects/tks-examples $ tks testtime.tks it's already 23:56:14 and still the 13-Sep-2005. today is Tuesday, the 13. of Sep in the year 2005. xmas is on a Sunday, the 358. day of this year. the 1-Jan-1970 was a Thursday. unix time (seconds since 1.Jan.1970): 1126648574 RIO.timeString = 2005-09-13-21-56-14-773226764 RIO.timeString = 2005-09-13-21-56-14-782016150
return as 4 "PersonDAO" "RoleDAO" "rio" "TestDAO"
return ap 2 namespaces 0 : as procedures 1 name s : s
return ap 2 create 2 key s value s : TestVO find 1 key s : TestVO
return ap 2 findById 1 id l : RoleVO findByName 1 name s : RoleVO
return ap 7 findById 1 id l : aPersonVO findByName 1 name s : aPersonVO create 1 person PersonVO : PersonVO remove 1 person PersonVO : b find 1 person PersonVO : aPersonVO findBySurname 1 surname s : aPersonVO findByMinMaxBirthdate 2 min t max t : aPersonVO.
return (PersonVO 7 forename s "Foo" role_id l 1 surname s "Bar" birthdate t 2005-08-25-17-52-04-781250000 id l 1 role (RoleVO 3 granted_procedures as 0 id l 1 name s "User" name s "Foo Bar"
YAC
)
Object o;
o <= new HashTable; o["key"]="value"; print o["key"];
o <= new FloatArray; o["2"] =12345; print o[2];
class C {} c; boolean b=c instanceof Class;
works now. Each script class can now be casted to class_id 0 (I added a root ancestor script class)
class C {Object o;}
compiles now
function HTTP_Date():String {
Time t; t.gmtime();
return
"Date: " +
(["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"][t.weekday]) +
", " +
Integer.New(t.monthday).printf("%02i") +
" " +
(["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"][t.month]) +
" " +
t.year +
" " +
(Integer.New(t.hour).printf("%02i")+":"+Integer.New(t.min).printf("%02i")+":"+Integer.New(t.sec).printf("%02i")) +
" GMT\n";
}
function Testo(Object o) { print "Testo: o="+#(o); }
Testo(42); // 42 will be casted to Integer(42) object
Testo(PI); // PI will be casted to Float(PI) object
function Tests(String s) { print "Tests: s="+#(s); }
Tests(42);
Tests(PI);
delegate
keyword; see class_delegates.tks. *really* useful for GUIs :-)
Viewport.width
and Viewport.height
now returns the initial OpenGL viewport size.
class MyClass {} class MyClass2 : MyClass {} class NotMyClass {}
class C {
// triggers "notnull" constraint violation (instanceof failed)
static testr3() returns MyClass.notnull { return NotMyClass; }
}
C.testr3();
constraint cs1 [0,2,4,6,8].contains(_) "value must be one of [0,2,4,6,8]";
class C {
static test1(int _i.cs1) { print "_i="+_i; }
static test2(String _s.notnull) { _s.append("..."); print "_s="+_s; }
}
C.test1(8);
C.test2("hello, world.");
C.test2(null);
[---] Runtime callstack: [---] 1.: "MUI":897: MyForm::consumeAction() (in "Main":93). [---] 2.: "MButton":103: Layer::provideAction() (in "MUI":819). [---] 3.: "MUI":1181: Button::onMouse() (in "MButton":90). [---] 4.: "MUI":1237: UI::HandleMouseEvent() (in "MUI":1078). [---] 5.: "MUI":142: UI::OnMouse() (in "MUI":1097). [---] 6.: "MUI":1076: <native> SDL::eventLoop(). [---] 7.: "Main":220: UI::Run() (in "MUI":1038).
Double d=2;
trace d + " " + 5f;
HashTable ht<=#[a="a_defined"];
String s<=ht["b_defined"];
print #(s); // should print "<null>"
class CB { String my_string; }
class CA extends CB { _init(String _s){my_string=_s;} }
function CA (String _s) returns CB { local CA ca; ca._init(_s); return deref ca; }
function CA2(String _s) returns CA { local CA ca; ca._init(_s); return deref ca; }
print CA("hello, world.").my_string;
print CA2("hallo, welt.").my_string;
class C {
public function Dist(float x, y, z):float {
return sqrt(x*x+y*y+z*z);
}
}
print C.Dist(2,3,4);
@()
builtin function which converts an object to its address (i.e. just changes type). Example:
Value v1=PI, v2=PI;
if(v1==v2) // tests whether the value objects are equal
print "ok";
if(@(v1)!=@(v2)) // tests whether the value objects are not identical
print "ok";
function f() returns Double { return 42; } print #(f());
Integer j=0, i=10;
while(i--!=0) print "Hello"+(j--);
// Note: while(i) tests whether the object value is not null, this is not what we want here.
// It is strongly recommended to use the comparison operators (==,!=,<,>,..) for atomic numbers
// and number objects so the program behaviour does not change when switching from e.g. native
// ints to LongLong number objects.
while
and if
statements will simply check whether the Object is null. See above.
String t,s="the quick brown fox jumps over the lazy dog";
Integer i=s.length;
loop(i) { t=s; t.abbrev(i); print "t["+i.printf("%02i")+"]="+t; i--;}
( output )
io_offset
, yacArrayGetMaxElements returns size
.
class MyClass {
yacToString(String _s) { // convert object to String (_s is a pre-allocated String)
_s="hello from MyClass";
}
}
print MyClass;
print [1,2,3,-4,-5,-6].absMin;
String s=
"line1\n"
"\n"
"line3\n"
"\n"
"\n"
"line6\n"
;
String t;
foreach t in s.splitChar('\n') {
print "t="+t;
}
method
keyword instead if you want that)
instanceof
expression (see class_instanceof.tks example)
<=
initializers, see class_init.tks.
class MyBaseClass
{
HashTable hashtable1 =#[a="b", c="d"]; // copy object (assign by value)
HashTable hashtable2<=#[e="f", g="h"]; // grab (constant) object (assign by reference)
}
- please note that in this example, <= grabs the _occurence_ of the constant hashtable object; it is not altered until the next class instance is created (i.e. the #[] expression is called again). Please consider this if your initializers contain non-constant expressions!
class MC {
define int CONSTANT_I=42;
int i=CONSTANT_I;
}
MC mc;
print mc.i;
String xml = "<test a=\"2\" ><some text></test>";
TreeNode t<=xml.parseXML();
HashTable ht<=t.objectValue;
print "flowtext=\""+ht["<>"]+"\"";
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |