gudzpoz / luajava

Lua for Java on Windows, Mac OS X, Linux, Android. 5.1, 5.2, 5.3, 5.4, LuaJ or LuaJIT.
https://gudzpoz.github.io/luajava/
Other
154 stars 21 forks source link

Signature-based method resolution grammar #10

Closed gudzpoz closed 2 years ago

gudzpoz commented 2 years ago

Currently we iterate through all the methods to find one matching the parameters on stack, trying to convert the parameters for every method. Maybe we should provide a way to let the user specify the signature of the target method, so that we can jump right to that method without all those iterations.

Operator mangling

Since we made JFunctions closures, we may replace the original object calling grammar into the signature'd calling grammar:

javaObject:toString()
-- With signature
javaObject('toString', '')()

Consider static methods, you won't expect the following method calling to be anything other than constructor calling:

String = java.import('java.lang.String')
s = String('string')

We must not use the above grammar, maybe later...

(jobject/'int,int,java.lang.String'/'methodName')(1, 2, 'Hello')
-- or
(jobject/'int,int,java.lang.String'):methodName(1, 2, 'Hello')
-- or
java.call(jobject, 'methodName', 'int,int,java.lang.String')(1, 2, 'Hello')

The most ideal one may be:

jobject.methodName['signature'](1, 2, 'Hello')
-- have to be
jobject.methodName['signature'](jobject, 1, 2, 'Hello')

But we lose track of jobject.

Keyword abuse

Use Java reserved words.


jobject.try('int,int,java.lang.String'):methodName(1, 2, 'Hello')
gudzpoz commented 2 years ago

Only java.method(jobject, 'methodName', 'optionalSignature') for now.