]> gitweb.factorcode.org Git - factor.git/blob - core/init/init.factor
change add-init-hook to add-startup-hook, new add-shutdown-hook word
[factor.git] / core / init / init.factor
1 ! Copyright (C) 2004, 2009 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: continuations continuations.private kernel
4 kernel.private sequences assocs namespaces namespaces.private ;
5 IN: init
6
7 SYMBOL: startup-hooks
8 SYMBOL: shutdown-hooks
9
10 startup-hooks global [ drop V{ } clone ] cache drop
11 shutdown-hooks global [ drop V{ } clone ] cache drop
12
13 : do-hooks ( assoc -- )
14     [ nip call( -- ) ] assoc-each ;
15
16 : do-startup-hooks ( -- ) startup-hooks get do-hooks ;
17
18 : do-shutdown-hooks ( -- ) shutdown-hooks get do-hooks ;
19
20 : add-startup-hook ( quot name -- )
21     startup-hooks get
22     [ at [ drop ] [ call( -- ) ] if ]
23     [ set-at ] 3bi ;
24
25 : add-shutdown-hook ( quot name -- )
26     shutdown-hooks get set-at ;
27
28 : boot ( -- ) init-namespaces init-catchstack init-error-handler ;
29
30 : boot-quot ( -- quot ) 20 getenv ;
31
32 : set-boot-quot ( quot -- ) 20 setenv ;