[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: About the annotation
 
- From: kurapica <kurapica125@...>
 
- Date: Thu, 25 Apr 2019 23:36:31 -0700 (MST)
 
I'm still not familiar with the format, the code part is missing, so I post
it again:
The first example:
 >   -- Declare a web applcaiton as the private environment
 >   Application "TestWebApp" (function(_ENV)                     
 >       __Route__("/user", HttpMethod.GET)   -- Bind the route GET
/user?name=ann to the function                          
 >       __Form__{ name = { type = String, require = true } }  -- Bind the
form validation, the result will be passed to the form & err
 >       __Json__()   -- The return value will be serialized as JSON to the
response
 >       function JsonHandler(context, form, err)
 >           if err then return {} end
 >   
 >           local user
 >   
 >           -- Like the Using in C#, auto close the database connection
 >           with(UserDataContext())(function(ctx)
 >               -- Get the serializable data entity
 >               user = ctx.Users:Query{ name = form.name }:First() or {}
 >           end, function(err)
 >               -- skip
 >           end)
 >   
 >           return user or {}
 >       end
 >   end)
The second example:
 >   UnitTest "UnitTest.Example" (function(_ENV)
 >       __Test__"Should always succeed"
 >       function test1() end
 >   
 >       __Test__"Should always fail"
 >       function test2() Assert.Nil(1) end
 >   end)
 >   
 >   Module "Type.Validation" (function(_ENV)
 >       __Return__{ String }
 >       __Arguments__{ String, Number/1 }
 >       function rep(str, count)
 >           return string.rep(str, count)
 >       end
 >   
 >       print(rep("h"))     -- h
 >       print(rep("h", "")) -- Usage: rep(System.String, [System.Number =
1]) - the 2nd argument must be number, got string
 >   end)
--
Sent from: http://lua.2524044.n2.nabble.com/Lua-l-f2524044.html