From 4f8c5d0f284e1f4da717aea5008915f185cd2e05 Mon Sep 17 00:00:00 2001 From: Lua Team Date: Tue, 1 Jul 1997 12:00:00 +0000 Subject: Lua 3.0 --- test/README | 7 ++-- test/array.lua | 6 +-- test/bisect.lua | 4 +- test/dump.lua | 26 +++++++------ test/examples/complex/complex.lua | 82 --------------------------------------- test/examples/complex/mandel.lua | 25 ------------ test/examples/www/README | 10 +++++ test/examples/www/db.lua | 46 ++++++++++++++++++++++ test/examples/www/staff.lua | 37 ++++++++++++++++++ test/examples/www/template.html | 29 ++++++++++++++ test/hello.lua | 2 +- test/loop.lua | 6 --- test/lua | 1 + test/luac | 1 + test/sort.lua | 2 +- test/split.lua | 18 --------- test/type.lua | 37 ------------------ 17 files changed, 149 insertions(+), 190 deletions(-) delete mode 100644 test/examples/complex/complex.lua delete mode 100644 test/examples/complex/mandel.lua create mode 100644 test/examples/www/README create mode 100644 test/examples/www/db.lua create mode 100644 test/examples/www/staff.lua create mode 100644 test/examples/www/template.html delete mode 100644 test/loop.lua create mode 120000 test/lua create mode 120000 test/luac delete mode 100644 test/split.lua delete mode 100644 test/type.lua (limited to 'test') diff --git a/test/README b/test/README index 625644d0..6f410ee4 100644 --- a/test/README +++ b/test/README @@ -1,7 +1,6 @@ These are simple tests for Lua. Some of them contain useful code. They are meant to be run to make sure Lua is ok and also to be read, to see how Lua programs can look like. -In the directory examples/, there is more useful code, such as a library for -complex arithmetic (a good example of fallbacks for overloading and redefinition -of primitive functions), and a library for PostScript output. Both libraries -include simple examples. + +In the directory examples/, there is more useful code: a library for PostScript +output and a database for a fake web site. diff --git a/test/array.lua b/test/array.lua index 7caca888..48c28576 100644 --- a/test/array.lua +++ b/test/array.lua @@ -2,14 +2,14 @@ $debug a = {} -i=0 +local i=0 while i<10 do a[i] = i*i i=i+1 end -r,v = next(a,nil) +local r,v = next(a,nil) while r ~= nil do - print ("array["..r.."] = "..v) + write ("array[",r,"] = ",v,"\n") r,v = next(a,r) end diff --git a/test/bisect.lua b/test/bisect.lua index cfb1bbfd..8b720654 100644 --- a/test/bisect.lua +++ b/test/bisect.lua @@ -2,7 +2,7 @@ $debug -- bisection method for solving non-linear equations function bisect(f,a,b,fa,fb) -print(n.." a="..a.." fa="..fa.." b="..b.." fb="..fb) + write(n," a=",a," fa=",fa," b=",b," fb=",fb,"\n") local c=(a+b)/2 if abs(a-b)=0 then s="+" else s="" end - Complex.oldprint(x.re..s..x.im.."I") - end -end - -function Complex.newabs(x) - if type(x)~="complex" then - return Complex.oldabs(x) - else - return Complex.abs(x) - end -end - -Complex.oldfallback=setfallback("arith",Complex.fallback) -Complex.oldtype=type type=Complex.newtype -Complex.oldprint=print print=Complex.print -Complex.oldabs=abs abs=Complex.abs diff --git a/test/examples/complex/mandel.lua b/test/examples/complex/mandel.lua deleted file mode 100644 index 5e3d3eb6..00000000 --- a/test/examples/complex/mandel.lua +++ /dev/null @@ -1,25 +0,0 @@ -dofile("complex.lua") - -xmin=-2 xmax=2 ymin=-2 ymax=2 -d=.125 - -function level(x,y) - local c=complex(x,y) - local l=0 - local z=c - repeat - z=z*z+c - l=l+1 - until abs(z)>2 or l>255 - return l-1 -end - -x=xmin -while xProgram of Computer Graphics, '.. +'Cornell University', + WWW="|PCG|/~celes/", + AREAS="Image segmentation and 3D reconstruction; " +.."Physical simulation and educational software;" +.."Geometric modeling and topological data structures;" +.."Extension languages and customizable applications" +} + +staff{ + LOGIN="lhf", + NAME="Luiz Henrique de Figueiredo", + TITLE='D.Sc., IMPA, 1992', + POSITION='Visiting Research fellow at LNCC; Consultant at |TECGRAF|', + AREAS="Geometric modeling; Software tools", + WWW="http://www2.lncc.br/~lhf/", +} diff --git a/test/examples/www/staff.lua b/test/examples/www/staff.lua new file mode 100644 index 00000000..7fa5b810 --- /dev/null +++ b/test/examples/www/staff.lua @@ -0,0 +1,37 @@ +$debug + +readfrom("template.html") +TEMPLATE=read(".*") +readfrom() + +PAT="|(%a%a*)|" + +GLOBAL={ + DATE=date("%d/%m/%Y %T"), +} + +function get(i) + if LOCAL[i] then return LOCAL[i] + elseif GLOBAL[i] then return GLOBAL[i] + else return "?"..i.."?" end +end + +function global(t) + local i,v=next(t,nil) + while i do + GLOBAL[i]=v + i,v=next(t,i) + end +end + +function staff(t) + LOCAL=t + if t.AREAS then t.AREAS=gsub(t.AREAS,"[;,] *","\n
  • ") end + local p,n=TEMPLATE + if t.WWW=="" then p=gsub(p,'|NAME|',"|NAME|") end + repeat p,n=gsub(p,PAT,get) until n==0 + write(t.LOGIN,"\n") + writeto(t.LOGIN..".html") + write(p) + writeto() +end diff --git a/test/examples/www/template.html b/test/examples/www/template.html new file mode 100644 index 00000000..c8494b76 --- /dev/null +++ b/test/examples/www/template.html @@ -0,0 +1,29 @@ + + + +Imaginary web site:Staff:|LOGIN| + + + + +

    |NAME|

    +|EMAIL| +

    + +|POSITION|
    +|TITLE|

    + +

    Research areas

    +
      +
    • |AREAS| +
    +

    + +


    +Last update in |DATE| by +websmaster. +

    + + + + diff --git a/test/hello.lua b/test/hello.lua index 639144b6..ea818b9a 100644 --- a/test/hello.lua +++ b/test/hello.lua @@ -1,3 +1,3 @@ -- the first program in every language -print("hello world, from Lua!") +write("hello world, from Lua!\n") diff --git a/test/loop.lua b/test/loop.lua deleted file mode 100644 index b464d09e..00000000 --- a/test/loop.lua +++ /dev/null @@ -1,6 +0,0 @@ -$debug -i=0 -repeat - print(i) - i=i+1 -until i>10 diff --git a/test/lua b/test/lua new file mode 120000 index 00000000..3b0b1a28 --- /dev/null +++ b/test/lua @@ -0,0 +1 @@ +../bin/lua \ No newline at end of file diff --git a/test/luac b/test/luac new file mode 120000 index 00000000..694bc0dc --- /dev/null +++ b/test/luac @@ -0,0 +1 @@ +../bin/luac \ No newline at end of file diff --git a/test/sort.lua b/test/sort.lua index d665e96b..a5eb0956 100644 --- a/test/sort.lua +++ b/test/sort.lua @@ -28,7 +28,7 @@ function selectionsort(a,n) end function show(m,x) - write(m.."\n\t") + write(m,"\n\t") local i=0 while x[i] do write(x[i]) diff --git a/test/split.lua b/test/split.lua deleted file mode 100644 index 0f64c508..00000000 --- a/test/split.lua +++ /dev/null @@ -1,18 +0,0 @@ -function split (s) - local n = 1 - local f = strfind(s,"/") - while f do - n = n+f - f = strfind(strsub(s,n),"/") - end - return strsub(s,1,n-1), strsub(s,n) -end - - -function test(s) - local path, filename = split(s) - print(s .. "=[".. path.."]+["..filename.."]") -end - -test("a:/lua/obj/lua.c") -test("lua.lib") diff --git a/test/type.lua b/test/type.lua deleted file mode 100644 index 5bfc33e4..00000000 --- a/test/type.lua +++ /dev/null @@ -1,37 +0,0 @@ -$debug - -function check (object, class) - local v = next(object,nil); - while v ~= nil do - if class[v] == nil then - print("unknown field: " .. v) - elseif type(object[v]) ~= class[v].type then - print("wrong type for field " .. v) - end - v = next(object,v); - end - v = next(class,nil); - while v ~= nil do - if object[v] == nil then - if class[v].default ~= nil then - object[v] = class[v].default - else - print("field "..v.." not initialized") - end - end - v = next(class,v); - end -end - -typeblock = {x = {default = 0, type = "number"}, - y = {default = 0, type = "number"}, - name = {type = "string"} - } - -function block(t) check(t,typeblock) end - -block{ x = 7, name = "3"} -block{ x = "7", name = "3"} -block{ x = 7, name = 3} -block{ x = 7} -block{ x = 7, name = "3", bogus=3.14} -- cgit v1.2.1