Skip to content

Commit

Permalink
loader: load only .tl files, support tl.path
Browse files Browse the repository at this point in the history
  • Loading branch information
hishamhm committed Mar 5, 2025
1 parent 03034b6 commit a0a7ce7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
16 changes: 10 additions & 6 deletions tl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,8 @@ local tl = { GenerateOptions = {}, CheckOptions = {}, Env = {}, Result = {}, Err








Expand Down Expand Up @@ -7127,12 +7129,12 @@ local function search_for(module_name, suffix, path, tried)
return nil, nil, tried
end

tl.search_module = function(module_name, search_dtl)
tl.search_module = function(module_name, search_all)
local found
local fd
local tried = {}
local path = os.getenv("TL_PATH") or package.path
if search_dtl then
local path = os.getenv("TL_PATH") or tl.path or package.path
if search_all then
found, fd, tried = search_for(module_name, ".d.tl", path, tried)
if found then
return found, fd
Expand All @@ -7142,9 +7144,11 @@ tl.search_module = function(module_name, search_dtl)
if found then
return found, fd
end
found, fd, tried = search_for(module_name, ".lua", path, tried)
if found then
return found, fd
if search_all then
found, fd, tried = search_for(module_name, ".lua", path, tried)
if found then
return found, fd
end
end
return nil, nil, tried
end
Expand Down
18 changes: 11 additions & 7 deletions tl.tl
Original file line number Diff line number Diff line change
Expand Up @@ -664,11 +664,13 @@ local record tl
parse_program: function(tokens: {Token}, errs: {Error}, filename?: string, parse_lang?: ParseLang): Node, {string}
check_file: function(filename: string, env?: Env, fd?: FILE): (Result, string)
check_string: function(input: string, env?: Env, filename?: string, parse_lang?: ParseLang): Result
search_module: function(module_name: string, search_dtl: boolean): string, FILE, {string}
search_module: function(module_name: string, search_all: boolean): string, FILE, {string}
symbols_in_scope: function(tr: TypeReport, y: integer, x: integer, filename: string): {string:integer}
target_from_lua_version: function(str: string): GenTarget
version: function(): string

path: string -- if set be the user, this overrides package.path for Teal

-----------------------------------------------------------------------------
-- Deprecated, mantained for backwards compatibility:
-----------------------------------------------------------------------------
Expand Down Expand Up @@ -7127,12 +7129,12 @@ local function search_for(module_name: string, suffix: string, path: string, tri
return nil, nil, tried
end

tl.search_module = function(module_name: string, search_dtl: boolean): string, FILE, {string}
tl.search_module = function(module_name: string, search_all: boolean): string, FILE, {string}
local found: string
local fd: FILE
local tried: {string} = {}
local path = os.getenv("TL_PATH") or package.path
if search_dtl then
local path = os.getenv("TL_PATH") or tl.path or package.path
if search_all then
found, fd, tried = search_for(module_name, ".d.tl", path, tried)
if found then
return found, fd
Expand All @@ -7142,9 +7144,11 @@ tl.search_module = function(module_name: string, search_dtl: boolean): string, F
if found then
return found, fd
end
found, fd, tried = search_for(module_name, ".lua", path, tried)
if found then
return found, fd
if search_all then
found, fd, tried = search_for(module_name, ".lua", path, tried)
if found then
return found, fd
end
end
return nil, nil, tried
end
Expand Down

0 comments on commit a0a7ce7

Please sign in to comment.