diff options
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/crypto.md | 2 | ||||
| -rw-r--r-- | docs/io.md | 2 | ||||
| -rw-r--r-- | docs/math.md | 2 | ||||
| -rw-r--r-- | docs/net/listen.md | 36 | ||||
| -rw-r--r-- | docs/readme.md | 16 | ||||
| -rw-r--r-- | docs/table.md | 2 | ||||
| -rw-r--r-- | docs/thread.md | 2 | ||||
| -rw-r--r-- | docs/thread/async.md | 51 | ||||
| -rw-r--r-- | docs/thread/buffer.md | 31 | ||||
| -rw-r--r-- | docs/thread/mutex.md | 23 | ||||
| -rw-r--r-- | docs/thread/usleep.md | 5 |
11 files changed, 163 insertions, 9 deletions
diff --git a/docs/crypto.md b/docs/crypto.md index c55e6ed..9f785af 100644 --- a/docs/crypto.md +++ b/docs/crypto.md @@ -1,5 +1,7 @@ # crypto +> out of date! + ## hashing \* is optional @@ -1,5 +1,7 @@ # io +> out of date!! + ## common ### pprint diff --git a/docs/math.md b/docs/math.md index 0a84a8a..4bc1743 100644 --- a/docs/math.md +++ b/docs/math.md @@ -1,5 +1,7 @@ # math +> out of date!! + ## common ### lcm diff --git a/docs/net/listen.md b/docs/net/listen.md index 333f0f2..cc464b3 100644 --- a/docs/net/listen.md +++ b/docs/net/listen.md @@ -5,6 +5,26 @@ net.listen(function, port) (intentionally styled after expressjs:3)
the function will be ran on initilization, the argument has info on the server and functions to set it up
+if the 'server' upvalue needs to be accessible inside of the network threads, you will need to make the value global or redefine it. the upvalue itself (as a argument to the listen function) will simply not exist when the route functions are called, despite it looking like they would be.
+because the route functions (GET, POST, etc..) are just assigning functions to these paths, and not running them, they will just not see the server value.
+this also explains another weird behaviour where routes can read locals before they've been defined. (the upvalues of the functions are defined when the listen function is complete)
+
+```lua
+llby.net.listen(function(server)
+ _G.server = server
+
+ server:GET("/", function(res, req)
+ --first will always be null, second will be null without the second line
+ print(server, _G.server)
+
+ --will be valid despite being defined later
+ print(awa)
+ end)
+
+ local awa = 22
+end)
+```
+
|name|default value|extra info|
|--|--|--|
|mimetypes|/etc/mime.types|file used to auto assign content-type when using res:sendfile, nil to skip|
@@ -22,20 +42,14 @@ the server will send these codes for these reasons |414|request uri is longer than max_uri|
```lua
-llib.net.listen(function(server)
+llby.net.listen(function(server)
...
end, 80)
```
-```lua
-llib.net.listen(function(server)
- ...
-end, 80)
-```
+### server:close
-### server:close **
-
-closes server
+closes server, will not halt other already accepted requests
### server:GET/POST/...
@@ -132,6 +146,8 @@ res.header["test"] = "wowa" res:sendfile(filepath, options?)
+this can return an error if the file is not found or if the user does not have read permissions
+
res.header["Content-Type"] is set automatically (unless already set) depending on the file extention, using /etc/mime.types, or whatever option was supplied to listen (see listen options)
options table
@@ -170,6 +186,8 @@ these can, of course be used with wildcards however you want req:roll(bytes?)
+> this will be changed to be a stream internally, see common.md
+
when bytes is null it will read as much as possible (may not be the full request)
will update req according to how the bytes needed to be parsed, returns the number of bytes read (not necessarily parsed), 0 if there
diff --git a/docs/readme.md b/docs/readme.md index 9436ba0..83c02e5 100644 --- a/docs/readme.md +++ b/docs/readme.md @@ -1,4 +1,7 @@ # lullaby (llby)
+
+> all files besides this and the content of net/ are out of date! ill be working on them later
+
(name subject to change)
with the library in the same directory [(or one of the other valid search locations)](https://www.lua.org/pil/8.1.html)
@@ -49,6 +52,19 @@ the number of bytes can be selected, the function will return an amount close to some streams may not support the bytes param, and may just ignore it. if it is ignored or not given it will always read the entire stream
+### errors
+
+errors will typically be created and propogated using luaI_error (in c) but will always retain a common style (unless mentioned otherwise)
+
+it will return 3 values, in order
+
+* nil (just always a nil value first, useful to do a quick check for errors on functions with a return value)
+* string (an error message)
+* integer (an error code)
+
+similarily, when luaI_assert is called, the string will be the expression and the integer will be -1
+
+
---
## big changes
diff --git a/docs/table.md b/docs/table.md index e58dd54..9e23332 100644 --- a/docs/table.md +++ b/docs/table.md @@ -1,5 +1,7 @@ # table (tables and sorting) +> out of date!! + ## sorting |name|accepted types|type of sorting|order| diff --git a/docs/thread.md b/docs/thread.md index 62e31bf..aff9aab 100644 --- a/docs/thread.md +++ b/docs/thread.md @@ -1,5 +1,7 @@ # threads **
+> out of date!!
+
## buffer
'takes 'anything'
diff --git a/docs/thread/async.md b/docs/thread/async.md new file mode 100644 index 0000000..a13b18b --- /dev/null +++ b/docs/thread/async.md @@ -0,0 +1,51 @@ +## async + +thread.async(function(res)) + +despite the name, this function provides a new state running under a new thread. coroutines would be more what you are looking for for async + +the argument function is executed by the thread until it has been completed. the res paramater is a function that takes any number of arguments and sets them as the value for the thread:await() call, and kills the thread (safely) + +the reason for the res function it because lua_call (in the c api) requires a number or return values before you run the function + +the res function also provides some child methods for thread managment + +though variables are copied, some may not be able to clone perfectly (complex userdata, lightuserdata, etc..) and the __gc call from the main thread may effect the copy on the new thread. this issue wont be permanent, but it may require a workaround for now. + +### res:testclose + +res:testclose() + +closes the thread if it is being requested to close from async:close + +### res:autoclose + +res:autoclose() + +calls res:testclose() every lua line, using a debug hook + +--- + +### async:await + +async:await() + +pauses the current thread until the selected thread exits, or calls res(), the return value is whatever the thread passed to res + +### async:kill + +async:kill() + +kills the thread, this may close it in an unsafe way, and should be avoided + +### async:close + +async:close() + +waits for the thread to internally call res:testclose or exit + +### async:clean + +async:clean() + +calls the __gc metamethod, will call async:kill() if it is still running diff --git a/docs/thread/buffer.md b/docs/thread/buffer.md new file mode 100644 index 0000000..e366a33 --- /dev/null +++ b/docs/thread/buffer.md @@ -0,0 +1,31 @@ +## buffer + +thread.buffer(V) + +a buffer is a container that allows a variable to be shared between threads & states in a thread safe manor. + +it is able to store 'anything' though lightuserdata will likely not work properly. poorly structured user data may retain some shared state with the original, which could cause some use-after-free in some really poor situations. providing a __copy metamethod will alleviate this issue (read more in readme.md) + +the __gc metamethod will be stripped from the original object and called when the buffer's __gc gets called. you should not reuse the original object after putting in a buffer for this reason. + +the __index metamethod will index any value that is not a buffer.* method on the original object (i will try not to add any more) + +every other metamethod will be replaced with a proxy to the metamethod in the copied object + +### buffer:get + +buffer:get() + +copies the value in the buffer to the current state + +### buffer:set + +buffer:set(V) + +sets the value in the buffer + +### buffer:mod + +buffer:mod(function(V)) + +takes a function with a single argument (the value), the return value of this will be the new value, if it is nil, the value will return unchanged diff --git a/docs/thread/mutex.md b/docs/thread/mutex.md new file mode 100644 index 0000000..09acd77 --- /dev/null +++ b/docs/thread/mutex.md @@ -0,0 +1,23 @@ +## mutex + +thread.mutex() + +creates a pthread_mutex + +### mutex:lock + +mutex:lock() + +locks the mutex + +### mutex:unlock + +mutex:unlock() + +you'll never guess what this one does (unlocks the mutex) + +### mutex:free + +mutex:free() + +calls the __gc method diff --git a/docs/thread/usleep.md b/docs/thread/usleep.md new file mode 100644 index 0000000..75208a9 --- /dev/null +++ b/docs/thread/usleep.md @@ -0,0 +1,5 @@ +## usleep + +thread.usleep(μN) + +puts the thread to sleep for N microseconds (duh) |
