From 954d698350e41df2bca00c4cba09dfe55f3a8e40 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Wed, 16 Dec 2015 07:11:28 -0800 Subject: Useful feature: object post-initialization. Structs can now have code which executes after an object is initialized, which is useful for doing work like registering objects in global lists and whatever, when those actions need access to the initialized slots of the object. * share/txr/stdlib/struct.tl (defstruct): Handle :posinit syntax, by generating lambda as eighth argument of sys:make-struct call. * struct.c (struct struct_type): New member, postinitfun. (struct_init): Adjust registrations of make_struct_type to account for new parameter. The user visible make-struct-type is registered as having one optional argument, for backward compat. (make_struct_type): New argument, postinitfun. Store this in the structure. For backward compatibility, the argument is defaulted. (struct_type_mark): Mark the new postinitfun member. (call_postinitfun_chain): New static function. (make_struct, lazy_struct_init): Call call_postinitfun_chain after slots are initialized, and after the boa function is called. * struct.h (make_struct_type): Declaration updated. * lib.c (time_init): Pass eighth argument to make_struct type. * sysif.c (sysif_init): Likewise. * unwind.c (uw_late_init): Likewise. * tests/012/struct.tl: Update defstruct expansion test case. * txr.1: Document new argument of make-struct-type, and clarify ordering of initfun with regard to other actions. Likewise, document :postinit, and clarify ordering of :init actions with regard to other actions. --- lib.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib.c') diff --git a/lib.c b/lib.c index c87c2360..7b5df796 100644 --- a/lib.c +++ b/lib.c @@ -8725,7 +8725,7 @@ static void time_init(void) make_struct_type(time_s, nil, nil, list(year_s, month_s, day_s, - hour_s, min_s, sec_s, dst_s, nao), nil, nil, nil); + hour_s, min_s, sec_s, dst_s, nao), nil, nil, nil, nil); } void init(const wchar_t *pn, mem_t *(*oom)(mem_t *, size_t), -- cgit v1.2.3