Greetings all,
Today I discovered the "typedef" keyword in the ycp langauge. I'd not
realised this existed because I hadn't seen it in any documentation,
or used in modules. It seems it's very occasionally used. Is there any
reason for this? It seems to provide a mechanism to avoid having to
deal with lists of maps of lists all over the place. The typedefs
can't be imported out of a module, but one can work around this by
"including imports". See example.
// Test.ycp
{
include "Car.ycp";
include "CarBrand.ycp";
Car car = Car::newInstance();
y2milestone("New car speed is %1",Car::getSpeed(car));
Car::setSpeed(car,100);
y2milestone("Now car speed is %1",Car::getSpeed(car));
y2milestone("This car is a %1",Car::getBrand(car));
Car audi = Car::newBranded(CarBrand::AUDI);
y2milestone("This car is a %1",Car::getBrand(audi));
}
// output
2007-12-03 18:00:06 <1> padd(5080) [YCP] yast/Test.ycp:6 New car speed is 0
2007-12-03 18:00:06 <1> padd(5080) [YCP] yast/Test.ycp:8 Now car speed is 100
2007-12-03 18:00:06 <1> padd(5080) [YCP] yast/Test.ycp:10 This car is a `FORD
2007-12-03 18:00:06 <1> padd(5080) [YCP] yast/Test.ycp:12 This car is a `AUDI
// modules/car.ycp
{
module "Car";
include "CarBrand.ycp";
include "Car.ycp";
global Car newInstance()
{
Car car =
$[
"speed":0,
"brand":CarBrand::FORD,
"colour":"red"
];
return car;
}
global Car newBranded(CarBrand brand)
{
Car car =
$[
"speed":0,
"brand":brand,
"colour":"red"
];
return car;
}
global void setSpeed(Car & instance, integer speed)
{
instance["speed"] = speed;
}
global integer getSpeed(Car & instance)
{
return instance["speed"]:0;
}
global CarBrand getBrand(Car & instance)
{
return (CarBrand)instance["brand"]:nil;
}
}
// include/Car.ycp
{
import "Car";
typedef map
http://bw.uwcs.co.uk/yastscratch incase something ate the tabbing. -- To unsubscribe, e-mail: yast-devel+unsubscribe@opensuse.org For additional commands, e-mail: yast-devel+help@opensuse.org
Benji Weber napsal(a):
Greetings all,
Today I discovered the "typedef" keyword in the ycp langauge. I'd not realised this existed because I hadn't seen it in any documentation, or used in modules. It seems it's very occasionally used.
Great! :) Do you want to document it :)? http://svn.opensuse.org/svn/yast/trunk/doc/ BTW: for instance yast2-inetd uses typedef. -- Lukas Ocilka, YaST Developer (xn--luk-gla45d) ----------------------------------------------------------------- SUSE LINUX, s. r. o., Lihovarska 1060/12, Praha 9, Czech Republic
On 03/12/2007, Lukas Ocilka
Benji Weber napsal(a):
Greetings all,
Today I discovered the "typedef" keyword in the ycp langauge. I'd not realised this existed because I hadn't seen it in any documentation, or used in modules. It seems it's very occasionally used.
Great! :) Do you want to document it :)?
Well I was first wondering whether there are any potential problems with using it in the way I indicated, or if anyone can think of a better way of achieving the same result. Also where would be the most appropriate place in the documentation? -- Benjamin Weber -- To unsubscribe, e-mail: yast-devel+unsubscribe@opensuse.org For additional commands, e-mail: yast-devel+help@opensuse.org
Benji Weber napsal(a):
On 03/12/2007, Lukas Ocilka
wrote: Benji Weber napsal(a):
Greetings all,
Today I discovered the "typedef" keyword in the ycp langauge. I'd not realised this existed because I hadn't seen it in any documentation, or used in modules. It seems it's very occasionally used. Great! :) Do you want to document it :)?
Well I was first wondering whether there are any potential problems with using it in the way I indicated, or if anyone can think of a better way of achieving the same result.
Also where would be the most appropriate place in the documentation?
Well, probably somewhere in http://svn.opensuse.org/svn/yast/trunk/core/libycp/doc/ (XML docbook) ...and then link it from http://svn.opensuse.org/svn/yast/trunk/doc/tdg/yast.xml Maybe we already have some documentation. See http://svn.opensuse.org/svn/yast/trunk/core/libycp/doc/ycp/implementation/bu... Lukas
participants (2)
-
Benji Weber
-
Lukas Ocilka