While you're reading this text we're suffering from russia's bombs. Please help us to stand against russia's invasion and prevent World War III. It's pretty easy with UNITED24 fundraising platform. Thank you!
This project aims to provide the power of Yue for any language/framework without need in modification of runtime core sources.
Written in Lua 5.1 with LuaJIT as a runtime core.
Server should be created as a subprocess of your app. On Unix-like systems there is need to create two named FIFOs and provide their paths to the server using CLI args:
$ yues /path/to/infifo /path/to/outfifoNaming description: infifo is the FIFO your program writes to, outfifo is the FIFO your program reads from.
The idea of such server is allowance of executing arbitrary code on server side and get the results on client side. Any definitions of components should be implemented on client side (example). That's why this server is compatible with any Yue library version. Needed library version also should be checked at the client side (example).
Each message is a JSON-encoded object with one required prop —
typethat is string and describes the type of the message. The rest props are defined according to the type of the message. Each message should have newline ending (U+000A)
-
INITSent once after server is initialized. Has no more props
-
POSTMESSAGESent right after global
postMessagehas been called. List of props:
val—any, the value that is passed topostMessagecall. Can be of any serializable type -
CREATE_RThe result of function creation
id—string, the id passed toCREATEcall
res— optional,string, the id of created function
err— optional,string, the error message if there is an error -
CALL_RThe result of function call
id—string, the id passed toCALLcall
res— optional,any, the result of function call. May be of any serializable type
err— optional,string, the error message if there is an error -
REMOVE_RThe result of function removal
id—string, the id passed toREMOVEcall -
IIFE_RThe result of function creation and immidiate invocation
id—string, the id passed toIIFEcall
res— optional,any, the result of function call. May be of any serializable type
err— optional,string, the error message if there is an error
-
CREATECreates the function and returns it's id. See Function scope section.
id—string, the id of the call, pseudorandom string used to properly corellate and get back result of the invocation. It's recommended to use UUIDv4
args—Array<string>, list of argument names to be passed to the function at its invocation
body—string, the body of the function written in Lua 5.1 -
CALLCalls already created function by it's id
id—string, the id of the call, pseudorandom string used to properly corellate and get back result of the invocation. It's recommended to use UUIDv4
ref—string, the id of the function to be invoked
args—Array<any>, the arguments passed to function call -
REMOVERemoves already created function by it's id
id—string, the id of the call, pseudorandom string used to properly corellate and get back result of the invocation. It's recommended to use UUIDv4
ref—string, the id of the function to be removed -
IIFECreates function, invokes it, returns the result and removes the function immidiately. See Function scope section.
id—string, the id of the call, pseudorandom string used to properly corellate and get back result of the invocation. It's recommended to use UUIDv4
argNames—Array<string>, list of argument names to be passed to the function at its invocation
body—string, the body of the function written in Lua 5.1
args—Array<any>, the arguments passed to function call
There are some new globals available:
-
gui— object that contains all the stuff from Yue lib. The same asrequire('yue.gui') -
JSON— JSON reader/encoder (seeJSON.luain Bundled dependencies section) -
postMessage— method that sendsPOSTMESSAGEwith a value passed to the method. Usable for sending event messages.Signature:
postMessage(value: any): void -
sleep— method that temporarily stops the invocation for specified period of time in seconds.Signature:
sleep(seconds: number): void -
__readMessagesSync— method that synchronously reads new messages frominfifoand invokesmessaging.onmessagefor each new message.Signature:
__readMessagesSync(): void -
__getFunction— method that returns a function that was previously created with aCREATEcall by specified id.Signature:
__getFunction(ref: string): (...args: any[]) => any