SL4A 中多种编程语言的使用及 Python 基础介绍
1. 多种编程语言在 SL4A 中的应用
1.1 Lua
Lua 可实现 RPC 调用功能,以下是实现 RPC 调用函数的 Lua 代码:
function rpc(client, method, ...)
assert(method, 'method param is nil')
local rpc = {
['id'] = id,
['method'] = method,
params = arg
}
local request = json.encode(rpc)
client:send(request .. '\n')
id = id + 1
local response = client:receive('*l')
local result = json.decode(response)
if result.error ~= nil then
print(result.error)
end
return result
end
Lua 的“Hello, World”脚本如下:
require "android"
name = android.getInput("Hello!", "What is your name?")
android.printDict(name) -- A convenience method for inspecting dicts (tab
超级会员免费看
订阅专栏 解锁全文
564

被折叠的 条评论
为什么被折叠?



