@@ -51,16 +51,16 @@ COLOR_DARKGRAY = COLOR_DARKGREY
5151
5252-- Events
5353
54-
55- SC_WORLD_LOADED = 0
56- SC_WORLD_UNLOADED = 1
57- SC_MAP_LOADED = 2
58- SC_MAP_UNLOADED = 3
59- SC_VIEWSCREEN_CHANGED = 4
60- SC_CORE_INITIALIZED = 5
61- SC_PAUSED = 7
62- SC_UNPAUSED = 8
63-
54+ if dfhack . is_core_context then
55+ SC_WORLD_LOADED = 0
56+ SC_WORLD_UNLOADED = 1
57+ SC_MAP_LOADED = 2
58+ SC_MAP_UNLOADED = 3
59+ SC_VIEWSCREEN_CHANGED = 4
60+ SC_CORE_INITIALIZED = 5
61+ SC_PAUSED = 7
62+ SC_UNPAUSED = 8
63+ end
6464
6565-- User-changeable options
6666
@@ -105,7 +105,7 @@ function dfhack.with_finalize(cleanup_fn,fn,...) end
105105function dfhack .with_onerror (cleanup_fn ,fn ,...) end
106106
107107--- @param obj DFObject
108- local function call_delete ( obj ) end
108+
109109
110110--- @generic T
111111--- @param obj DFObject
@@ -118,7 +118,7 @@ dfhack.exception.__index = dfhack.exception
118118
119119-- Module loading
120120
121- local function find_required_module_arg () end
121+
122122
123123--- @nodiscard
124124--- @param module string
@@ -153,17 +153,17 @@ NEWLINE = "\n"
153153COMMA = " ,"
154154PERIOD = " ."
155155
156- local function _wrap_iterator ( next_fn , ...) end
156+
157157
158158function safe_pairs (t , iterator_fn ) end
159159
160160-- calls elem_cb(k, v) for each element of the table
161161-- returns true if we iterated successfully, false if not
162162-- this differs from safe_pairs() above in that it only calls pcall() once per
163163-- full iteration and it returns whether iteration succeeded or failed.
164- local function safe_iterate (table , iterator_fn , elem_cb ) end
165164
166- local function print_element (k , v ) end
165+
166+
167167
168168--- @param table table
169169function printall (table ) end
@@ -173,7 +173,7 @@ function printall_ipairs(table) end
173173
174174local do_print_recurse
175175
176- local function print_string ( printfn , v , seen , indent ) end
176+
177177
178178local fill_chars = {
179179 __index = function (table , key , value )
@@ -185,13 +185,13 @@ local fill_chars = {
185185
186186setmetatable (fill_chars , fill_chars )
187187
188- local function print_fields ( value , seen , indent , prefix ) end
188+
189189
190190-- This should be same as print_array but userdata doesn't compare equal even if
191191-- they hold same pointer.
192- local function print_userdata (printfn , value , seen , indent ) end
193192
194- local function print_array (printfn , value , seen , indent ) end
193+
194+
195195
196196local recurse_type_map = {
197197 number = print_string ,
@@ -399,12 +399,12 @@ function dfhack.world.getCurrentSite() end
399399--- @param key string
400400--- @param default ? any
401401--- @return any
402- local function persistent_getData ( which , key , default ) end
402+
403403
404404--- @param which string
405405--- @param key string
406406--- @param data any
407- local function persistent_saveData ( which , key , data ) end
407+
408408
409409--- @nodiscard
410410--- @param key string
@@ -484,7 +484,7 @@ function dfhack.current_script_name() end
484484
485485function dfhack .script_help (script_name , extension ) end
486486
487- local function _run_command ( args , use_console ) end
487+
488488
489489function dfhack .run_command_silent (...) end
490490
@@ -494,57 +494,8 @@ function dfhack.run_command(...) end
494494
495495function dfhack .getSavePath () end
496496
497-
498- local function loadInitFile (path , name )
499- local env = setmetatable ({ SAVE_PATH = path }, { __index = base_env })
500- local f ,perr = loadfile (name , ' t' , env )
501- if f == nil then
502- if dfhack .filesystem .exists (name ) then
503- dfhack .printerr (perr )
504- end
505- elseif safecall (f ) then
506- if not internal .save_init then
507- internal .save_init = {}
508- end
509- table.insert (internal .save_init , env )
510- end
511- end
512-
513- dfhack .onStateChange .DFHACK_PER_SAVE = function (op )
514- if op == SC_WORLD_LOADED or op == SC_WORLD_UNLOADED then
515- if internal .save_init then
516- for k ,v in ipairs (internal .save_init ) do
517- if v .onUnload then
518- safecall (v .onUnload )
519- end
520- end
521- internal .save_init = nil
522- end
523-
524- local path = dfhack .getSavePath ()
525-
526- if path and op == SC_WORLD_LOADED then
527- loadInitFile (path , path .. ' /init.lua' )
528-
529- local dirlist = dfhack .internal .getDir (path .. ' /init.d/' )
530- if dirlist then
531- table.sort (dirlist )
532- for i ,name in ipairs (dirlist ) do
533- if string.match (name ,' %.lua$' ) then
534- loadInitFile (path , path .. ' /init.d/' .. name )
535- end
536- end
537- end
538- end
539- elseif internal .save_init then
540- for k ,v in ipairs (internal .save_init ) do
541- if v .onStateChange then
542- safecall (v .onStateChange , op )
543- end
544- end
545- end
546- end
547-
497+ if dfhack .is_core_context then
498+
548499
549500-- Feed the table back to the require() mechanism.
550501return dfhack
0 commit comments