Mercurial Hosting > luan
comparison website/src/manual.html.luan @ 1316:11d3640e739d
load_file returns nil for missing file
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Thu, 31 Jan 2019 04:26:23 -0700 |
parents | 693da73c8a2f |
children | 3860ed4b8552 |
comparison
equal
deleted
inserted
replaced
1315:5763597ca5c0 | 1316:11d3640e739d |
---|---|
1815 <p> | 1815 <p> |
1816 Could be defined as: | 1816 Could be defined as: |
1817 | 1817 |
1818 <pre> | 1818 <pre> |
1819 function Luan.do_file(uri) | 1819 function Luan.do_file(uri) |
1820 return <a href="#Luan.load_file">Luan.load_file</a>(uri)() | 1820 local fn = <a href="#Luan.load_file">Luan.load_file</a>(uri) or <a href="#Luan.error">Luan.error</a>("file '"..uri.."' not found") |
1821 return fn() | |
1821 end | 1822 end |
1822 </pre> | 1823 </pre> |
1823 | 1824 |
1824 | 1825 |
1825 | 1826 |
1928 | 1929 |
1929 <pre> | 1930 <pre> |
1930 function Luan.load_file(file_uri) | 1931 function Luan.load_file(file_uri) |
1931 file_uri = file_uri or "stdin:" | 1932 file_uri = file_uri or "stdin:" |
1932 local f = Io.uri(file_uri) | 1933 local f = Io.uri(file_uri) |
1933 f.exists() or <a href="#Luan.error">Luan.error</a>("file '"..file_uri.."' not found") | 1934 if not f.exists() then |
1935 return nil | |
1936 end | |
1934 return <a href="#Luan.load">Luan.load</a>( f.read_text(), file_uri ) | 1937 return <a href="#Luan.load">Luan.load</a>( f.read_text(), file_uri ) |
1935 end | 1938 end |
1936 </pre> | 1939 </pre> |
1937 | 1940 |
1938 | 1941 |