-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat : display the print logs of the driver side #26
- Loading branch information
taotao
committed
May 17, 2024
1 parent
0f99849
commit ccfc876
Showing
10 changed files
with
227 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package script | ||
|
||
import ( | ||
"sync" | ||
|
||
lua "github.com/yuin/gopher-lua" | ||
) | ||
|
||
type LogModule struct { | ||
logs []string | ||
sync.Mutex | ||
} | ||
|
||
func (lm *LogModule) Loader(L *lua.LState) int { | ||
mod := L.SetFuncs(L.NewTable(), map[string]lua.LGFunction{ | ||
"info": lm.info, | ||
}) | ||
L.Push(mod) | ||
return 1 | ||
} | ||
|
||
// info - 脚本端添加一行日志 | ||
func (lm *LogModule) info(L *lua.LState) int { | ||
lm.Lock() | ||
defer lm.Unlock() | ||
|
||
info := L.ToString(1) | ||
lm.logs = append(lm.logs, info) | ||
|
||
return 0 | ||
} | ||
|
||
// Push - golang端添加一行日志 | ||
func (lm *LogModule) Push(log string) { | ||
lm.Lock() | ||
lm.logs = append(lm.logs, log) | ||
lm.Unlock() | ||
} | ||
|
||
func (lm *LogModule) Pop() string { | ||
lm.Lock() | ||
defer lm.Unlock() | ||
|
||
n := len(lm.logs) | ||
if n == 0 { | ||
return "" | ||
} | ||
x := lm.logs[n-1] | ||
lm.logs = lm.logs[0 : n-1] | ||
|
||
return x | ||
} | ||
|
||
func (lm *LogModule) Clean() { | ||
lm.Lock() | ||
lm.logs = []string{} | ||
lm.Unlock() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.