gshub.api
简介
组件接口
api.gs
函数原型 | 函数作用 |
---|---|
GshubConsole get_self_console() | 获取当前控制台对象 |
array get_all_launchers() | 获取当前所有已配置的启动器 |
GshubConsole launch_by_id(string id) | 通过 ID 启动一个已配置的启动器 |
GshubConsole launch_gs(string cmd) | 通过命令行启动一个新的 GS 实例 |
array get_all_consoles() | 获取所有控制台信息 |
类
GshubConsole
Gshub 控制台对象
成员变量
变量名 | 类型 | 初始值 | 须初始化 | 描述 |
---|---|---|---|---|
id | int | 0 | 可选 | |
type | string | "GS" | 可选 | GS | BAT |
pid | int | -1 | 可选 |
成员方法
函数原型 | 函数作用 |
---|---|
void stop() | 停止当前控制台 |
void restart() | 重启当前控制台 |
void focus() | 聚焦当前控制台 |
mixed eval(string code) | 在当前控制台中执行代码 |
GshubLaunchConfig
Gshub 启动器配置对象
成员变量
变量名 | 类型 | 初始值 | 须初始化 | 描述 |
---|---|---|---|---|
uuid | string | nil | 可选 | 启动器唯一 ID |
type | string | nil | 是 | 启动器类型, 可选值有 "GS", "BAT" |
isAutoHide | bool | false | 是 | 启动后是否自动隐藏控制台窗口 |
isTelnet | bool | false | 是 | 是否以 telnet 客户端模式启动 |
isClient | bool | false | 是 | 是否以客户端模式启动 |
fileOperation | array | nil | 是 | 文件操作列表 |
name | string | nil | 是 | 启动器名称 |
exitAfterBoot | bool | false | 是 | 是否在启动后退出 |
mounts | array | nil | 是 | 挂载点列表 |
preLoadObject | array | nil | 是 | 预加载对象列表 |
scriptArgs | array | nil | 是 | 脚本参数列表 |
macros | array | nil | 是 | 宏定义列表 |
otherArgs | array | nil | 是 | 其他参数列表 |
disableInput | bool | false | 是 | 是否禁用输入 |
bootObject | string | nil | 是 | gs 入口路径 |
isUsingGshubName | bool | true | 是 | 是否使用 gshub 名称作为窗口标题 |
config | string | nil | 可选 | 启动 gs config 配置 |
cwd | string | nil | 可选 | 启动时的工作目录 |
driver | string | nil | 可选 | 指定 driver 版本, 优先级高于项目配置 |
driverPath | string | nil | 可选 | 指定 driver 路径, 优先级高于 driver 版本 |
disableAutoUpdatePkg | bool | false | 可选 | 是否禁用自动更新包 |
rootPath | string | nil | 可选 | gs 根目录 |
成员方法
函数原型 | 函数作用 |
---|---|
GshubConsole launch() | 通过该配置启动一个新的 GS 实例 |
GshubConsole launch_by_id() | 通过该配置的 ID 启动一个新的 GS 实例 |
样例
import pkg.gshub.api;
coroutine.create(nil, () {
array configs = api.get_all_launchers();
for (GshubLaunchConfig config : configs)
{
if (config.name == "test")
{
config.launch();
}
}
return;
GshubLaunchConfig config = configs[0];
config.bootObject = nil; // 修改 gs 入口路径
// 通过配置启动一个新的 GS 实例
GshubConsole console = config.launch();
coroutine.sleep(2); // 等待 GS 启动完成
console.stop();
GshubConsole console2 = api.launch_gs("/r ./");
coroutine.sleep(2); // 等待 GS 启动完成
// 在控制台中执行代码,并获取返回值
console2.eval("write(\"hello process\\n\")");
printf("2 + 2 = %d\n", console2.eval("2 + 2"));
console2.eval("write(\"2 秒后关闭\\n\")");
coroutine.sleep(2);
// 关闭当前控制台
console2.stop();
});