local


local function (behavior)

Principle
local obj
Use
examples
See also

Principe:

        "Local functions" can be defined on objects to create real programs internal to the object and constitute its "behavior".
These functions can communicate with each other, with other objects or the outside world, see exec local). Automatic variables, static, external and global of objects can be defined. Global variables are known in all functions local to this object and are unknown to the outside.
        Multiple objects with the same local functions do not necessarily behave in the same way depending on the context. This method allows you to define "actors" equipped with autonomous behavior.
       The first local function of an object is executed when displaying if yes local is active.

Important notes:
1) When local functions are added to an object , they are automatically duplicated and compiled inside the object.
However, it will be necessary to do link local obj in order to resolve all the indefinites
2) By default the local functions of an object id are inhibited.
To activate: validate local obj(id)=1.
To inhibit: validate local obj(id)=0.

local obj

local(id_loc) obj(id_obj)

        Returns the text of the local function id_loc of object id_obj.

local(id_loc)compile obj(id_obj)

        Prints the compilation of local function id_loc of object id_obj.

local(id_loc)obj(id_obj)="f"

        Assignes functiuon f() as the local function id_loc of object id_obj.

local(0)obj(id_obj)="f"

        Adds the local function f() to object id_obj.

local(0)obj(id_obj)=num

        First local function of object id_obj corresponding to case num: (num <= 0) of function EXEC_OBJ_C(struct Objet *p_obj, long num) of file utilb.c

Notes:

       When displaying (ifyes local has been enabled) the first local function will be executed just before displaying this volume. .
Useful for attaching dynamic properties to a given volume (eg a view or a special light).
       One of commands number local or number local returns the identifier of the object whose a local function is currently running and can be used in such a function for modifying.
       For each calculation of the perspective, the first local function (if it exists) of the current view is executed. In such a function you can reset the view (eye, flight, length, roll) calculated according to the point that is returned by poi. Useful for creating adaptive perspective (ie depending on the point watching).

Use

Assign a local function to an object

1) Write a function f(){...}
2) Assign it as local function to several objects id1, id2, .. by:
local(0)obj(id1)="f";
local(0)obj(id2)="f";
...
3)Activate local by: yes local.
All objects id1, id2, ..., equipped with the same behavior f, behave differently depending on the context (they are identical but with programs running differently).

Calls and variables

        A local variable declared local in a local function of an object is considered external to all functions of the local object but unknown to the outside.
        Static variables declared in a local function are specific to that function and to the object concerned.
        In a local function, you can call another local function in the same object simply by invoking its name.
        To call a local function of a specific object id, do
exec local(id_loc) object(id_obj) var(x1) var(x2) ...,; avec:
        x1, x2, ...: call parameters.
        The first function of a local object is executed during use (if yes local is active).
        Can compile and link a local function of a particular object id by:
compile local.
link local.

Examples

Vue adaptative

To associate a view to a volume just write a local function that defines the vue settings according to the characteristics of this volume.
For example, to see volume 1 still face (even if it is rotated for example by roty(.2*PI)vol(1);):
cube(1);local(0)vol(1)="f";generate axis vol(1);
f()
{
self=number local; /* Get the identifier of the volume */
cg=CG matrix vol(self); /* CG of volume */
ax=axis vol(self);x=ax{0}; /* x axis of volume */
r=radius vol(self); /* Radius of volume */
eye(cg+3*r*x); /* The eye is on x axis at distance 3 * r */
}

local(0)vol(1)="f";yes local;

See also:

compile local
edit local
exec local
no local
rem local
validate local
yes local