ludic/packages/ludic.ui/lib_util.ludic
Orkuncakilkaya 19fcf60599 wip(0.S3): packages and examples migrated again from their pre-0.S sources in one run
ludic migrate state packages <every example program> packages/ludic.lab/example/plate.ludic
  1804 vars into 126 states, 64 into lets; 23498 edits in 460 files

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-25 15:31:34 +03:00

41 lines
1.2 KiB
Text

# lib_util.ludic - a file made, found, read, and a path beside another (or from the project's
# root, when it starts with /)
function lib_find(names: []string, name: string) -> int {
for i in 0 .. len(names) {
if names[i] == name { return i }
}
return -1
}
function lib_new(ui_st: mut UiState, path: string) -> UiFile {
let f = lib_blank(path)
push(ui_st.lib_files, f)
return f
}
# a file that is not one of the loaded ones (a component's own)
function lib_blank(path: string) -> UiFile {
let f = new UiFile
f.path = path
f.names = new []string
f.comps = new []UiTpl
f.exported = new []bool
f.imp_as = new []string
f.imp = new []UiFile
f.own = new []UiRule
return f
}
function lib_text(ui_st: UiState, path: string) -> string {
var src = ""
if ui_st.ui_be != null and ui_st.ui_be.read != null { src = ui_st.ui_be.read(path) } else { src = Fs.read_text(path) }
if src == null { return "" }
return src
}
# `src` read from beside the file that imports it
function lib_beside(path: string, src: string) -> string {
var cut = -1
for i in 0 .. len(path) {
if path[i] == 47 { cut = i }
}
if len(src) > 0 and src[0] == 47 { return src[1..len(src)] }
if cut < 0 { return src }
return path[0..cut + 1] + src
}