Ability to return Functions from peripherals.
Mathilde411 opened this issue ยท 6 comments
Hey I tried something like that but it didn't work.
@LuaFunction
public final Function<String, String> test() {
return (t) -> {
return "Test " + t;
};
}
So I assume that it is impossible to return functions.
Would it be possible to add such a feature ?
Thanks ^^
I guess it would be possible to allow returning something similar to a ILuaCallback
, but one which accepts IArguments
. Handling the more generic Function<_, _>
(and other functional interfaces like Consumer<_>
) is much harder to do.
Just curious as to what the use-case is here? It's not something we've really needed before, so interested to see where it's wanted.
I would use it for defining functions in Prepared SQL request-like system with object oriented lua on a Database peripheral.
Like you'd do:
local r = db.prepareTableCreation()
and then
r.executeRequest()
or
r.setPrimaryKey()
that could verify if a primary key already exists.
If you just need a table of objects, you can just return another object with @LuaFunction
s. For instance,
@LuaFunction
public final TableBuilder prepareTableCreation() {
return new TableBuilder();
}
public static class TableBuilder {
@LuaFunction
public final Object executeRequest() { return null; }
}