-
Notifications
You must be signed in to change notification settings - Fork 865
/
luaj.lua
81 lines (60 loc) · 2.41 KB
/
luaj.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
--[[
Copyright (c) 2011-2014 chukong-inc.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
]]
--[[--
Lua 与 Java 的交互接口
]]
local luaj = {}
local callJavaStaticMethod = CCLuaJavaBridge.callStaticMethod
--[[--
私有方法
]]
local function checkArguments(args, sig)
if type(args) ~= "table" then args = {} end
if sig then return args, sig end
sig = {"("}
for i, v in ipairs(args) do
local t = type(v)
if t == "number" then
sig[#sig + 1] = "F"
elseif t == "boolean" then
sig[#sig + 1] = "Z"
elseif t == "function" then
sig[#sig + 1] = "I"
else
sig[#sig + 1] = "Ljava/lang/String;"
end
end
sig[#sig + 1] = ")V"
return args, table.concat(sig)
end
--[[--
调用java类的接口。
只能调用java类的静态方法
@param string className java类名
@param string methodName java类静态方法名
@param table args java类静态方法所需要的各种参数 数组
@param [string sig] java类方法的签名
@return boolean ok, mixed ret ok为是否调用成功, ok为true时,ret为java方法的返回值,ok为false时,ret为出错原因
]]
function luaj.callStaticMethod(className, methodName, args, sig)
local args, sig = checkArguments(args, sig)
printInfo("luaj.callStaticMethod(\"%s\",\n\t\"%s\",\n\targs,\n\t\"%s\"", className, methodName, sig)
return callJavaStaticMethod(className, methodName, args, sig)
end
return luaj