Skip to content

Commit 9385d5f

Browse files
committed
添加弹窗支持并返回给lua
1 parent 7dd3c02 commit 9385d5f

File tree

6 files changed

+312
-11
lines changed

6 files changed

+312
-11
lines changed

Diff for: GokeyLua/Tool/CallGo/CallGo.go

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package CallGo
2+
3+
import (
4+
KeyTool "GoRobotScript/GokeyLog/Tool"
5+
"github.com/go-vgo/robotgo"
6+
"github.com/yuin/gopher-lua"
7+
)
8+
9+
func Loader(L *lua.LState) int {
10+
// register functions to the table
11+
mod := L.SetFuncs(L.NewTable(), exports)
12+
// register other stuff
13+
L.SetField(mod, "name", lua.LString("value"))
14+
15+
// returns the module
16+
L.Push(mod)
17+
return 1
18+
}
19+
20+
// 定义一个map类型的变量exports,其中key为string类型,value为lua.LGFunction类型
21+
var exports = map[string]lua.LGFunction{
22+
"myfunc": myfunc, // 将myfunc函数注册到exports中
23+
"keyLog": keyLog, // 将keyLog函数注册到exports中
24+
"showalert": showalert,
25+
}
26+
27+
func keyLog(L *lua.LState) int {
28+
KeyTool.KeyLog()
29+
return 0
30+
}
31+
32+
// 定义showalert函数,该函数接收两个参数,分别为title和msg
33+
// title和msg均为string类型
34+
// 函数返回值为int类型
35+
func showalert(L *lua.LState) int {
36+
// 将第一个参数转换为string类型
37+
title := L.ToString(1)
38+
// 将第二个参数转换为string类型
39+
msg := L.ToString(2)
40+
// 调用robotgo.ShowAlert函数,弹出一个提示框,返回值为bool类型
41+
abool := robotgo.ShowAlert(title, msg)
42+
// 将返回值转换为lua.LBool类型,并压入栈中
43+
L.Push(lua.LBool(abool))
44+
// 将弹出的Alert窗口置顶
45+
robotgo.ActiveName(title)
46+
// 返回参数个数1
47+
return 1
48+
}
49+
50+
func myfunc(L *lua.LState) int {
51+
return 0
52+
}
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
package CallGo
1+
package SuKey
22

33
import (
4-
KeyTool "GoRobotScript/GokeyLog/Tool"
4+
"github.com/go-vgo/robotgo"
55
"github.com/yuin/gopher-lua"
66
)
77

@@ -16,16 +16,14 @@ func Loader(L *lua.LState) int {
1616
return 1
1717
}
1818

19+
// 定义一个map类型的变量exports,其中key为string类型,value为lua.LGFunction类型
1920
var exports = map[string]lua.LGFunction{
20-
"myfunc": myfunc,
21-
"keyLog": keyLog,
22-
}
21+
"TypeStr": typeStr, // 将myfunc函数注册到exports中
2322

24-
func keyLog(L *lua.LState) int {
25-
KeyTool.KeyLog()
26-
return 0
2723
}
2824

29-
func myfunc(L *lua.LState) int {
25+
func typeStr(L *lua.LState) int {
26+
str := L.ToString(1)
27+
robotgo.TypeStr(str)
3028
return 0
3129
}

Diff for: GokeyLua/main.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
package main
22

33
import (
4-
CallGo "GoRobotScript/GokeyLua/Tool"
4+
CallGo "GoRobotScript/GokeyLua/Tool/CallGo"
5+
SuKey "GoRobotScript/GokeyLua/Tool/SuKey"
56
"flag"
67
"fmt"
78
lua "github.com/yuin/gopher-lua"
@@ -14,9 +15,11 @@ func ReadscriptUsage() {
1415

1516
}
1617
func main() {
18+
1719
L := lua.NewState()
1820
defer L.Close()
1921
L.PreloadModule("CallGo", CallGo.Loader)
22+
L.PreloadModule("SuKey", SuKey.Loader)
2023
scriptpath := flag.String("script", "path", "Script Path")
2124
//scriptpatht := *scriptpath
2225
Simkeyrun := "main"

Diff for: bin/GokeyLua.exe

5.37 MB
Binary file not shown.

Diff for: bin/main.lua

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
print("Hello World!")
22
local m = require("CallGo")
3+
local key = require("SuKey")
4+
key.TypeStr("0000000")
35
m.myfunc()
46
print(m.name)
5-
m.keyLog()
7+
print(m.showalert("AreU","Quit"))
68
function max(num1, num2)
79

810
if (num1 > num2) then

0 commit comments

Comments
 (0)