Lua Lambda string functionI created a lambda function to manipulate a string of lua code and parse it into a callable function. When I made the lambda function I was in need of a simple or fast way to write short simple functions used as a callback in looping functions in my Array (https://ihacks.dev/cc-archive/Hack/src/branch/master/Hack/core/Array.lua) class.
The lambda string function manipulates a string in two ways, it replaces `$x` with `__args__
- ` and adds a return statement in the start of the code to return the first statement in your code automatically. That can be avoided by writing 'do' in front of the string (see examples).
Known Issues* Dollar arguments does not respect whether or not it is placed in a string or comment node.
Example: Simple lambda functionlocal cb = lambda "$1 + $2";
Example: Lambda multi-statement functionlocal cb = lambda "do local x, y = $1, $2; return x * 2, y * 2;"
Example: Lambda multi-statement & multi-line functionlocal cb = lambda [[ do
local x, y = $1, $2;
return x * 2, y * 2;
]]
The source code for the lambda function lies in the URL below.
https://ihacks.dev/cc-archive/lambda (https://ihacks.dev/cc-archive/lambda)
Although, if you are planning to use it in your own code you should probably use the minified version:
https://ihacks.dev/cc-archive/lambda/src/branch/master/lambda.min.lua (https://ihacks.dev/cc-archive/lambda/src/branch/master/lambda.min.lua)
Also on pastebin:
https://pastebin.com/87huSSSd (https://pastebin.com/87huSSSd)
Oooh, looks neat! Almost reminds me of Scheme's cut/cute macros, though (ab)using text processing instead.
Worth noting the links to your Gitea repo are 404ing - I assume the repository hasn't been made public?