[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Determining which functions to call
- From: Björn De Meyer <bjorn.demeyer@...>
- Date: Mon, 20 Jan 2003 20:59:37 +0100
Florian Berger wrote:
> I would like to make a script system which determines the order of needed
> function calls to solve a problem. The basic idea is that I know values of
> some variables and then I have functions which can or cannot solve the
> problem with existing variables.
> Simple example:
> I have a Circle-object which has two attributes: radius and diameter.
> I know the circle's radius but not the diameter.
> I have two functions: one which calculates diameter from radius and other
> which calculates area of circle using diameter.
> I would like to make my system solve the area of circle so, that it
> automatically solves the diameter for the area-function.
> Are there some examples of this kind of problems for LUA and do you think
> LUA is good choice for this kind of programming?
This would be quite simple:
(Lua 5 beta code, I think it's PI in stead of math.pi in Lua 4)
return math.pi * d * d / 4
if circle.radius then --will be false if not defined.
circle.diameter = circle.radius * 2
--This skips certain sanity checks that might be useful
"No one knows true heroes, for they speak not of their greatness." --
Björn De Meyer