diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2015-12-16 07:11:28 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2015-12-16 07:11:28 -0800 |
commit | 954d698350e41df2bca00c4cba09dfe55f3a8e40 (patch) | |
tree | 4cfe48c1fd17644541ae82a4de3f125ed7aec714 /struct.h | |
parent | b860fe2ea8450109c4bcc0de755bccac40f377ef (diff) | |
download | txr-954d698350e41df2bca00c4cba09dfe55f3a8e40.tar.gz txr-954d698350e41df2bca00c4cba09dfe55f3a8e40.tar.bz2 txr-954d698350e41df2bca00c4cba09dfe55f3a8e40.zip |
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.
Diffstat (limited to 'struct.h')
-rw-r--r-- | struct.h | 3 |
1 files changed, 2 insertions, 1 deletions
@@ -27,7 +27,8 @@ extern val struct_type_s, meth_s; val make_struct_type(val name, val super, val static_slots, val slots, - val static_initfun, val initfun, val boactor); + val static_initfun, val initfun, val boactor, + val postinitfun); val struct_type_p(val obj); val super(val type); val make_struct(val type, val plist, struct args *); |