本文整理汇总了Golang中github.com/stevedonovan/luar.Register函数的典型用法代码示例。如果您正苦于以下问题:Golang Register函数的具体用法?Golang Register怎么用?Golang Register使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Register函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: _push_funcs
//---------------------------------------------------------- funcs need be pushed in
func _push_funcs(conn net.Conn, L *lua.State) {
luar.Register(L, "", luar.Map{
"conn": conn,
"Print": Print,
})
luar.Register(L, "gsdb", luar.Map{
"ListAll": gsdb.ListAll,
"QueryOnline": gsdb.QueryOnline,
})
}
开发者ID:johntdyer,项目名称:golang-devops-stuff,代码行数:12,代码来源:inspector.go
示例2: seed
func (script *Script) seed() {
luar.Register(script.L, "uuid", luar.Map{
"new": uuid.New,
})
luar.Register(script.L, "web", luar.Map{
"get": http.Get,
"post": http.Post,
})
luar.Register(script.L, "ioutil", luar.Map{
"readall": ioutil.ReadAll,
"byte2string": byteSliceToString,
})
luar.Register(script.L, "crypto", luar.Map{
"hash": crypto.Hash,
"fnv": crypto.Fnv,
})
luar.Register(script.L, "strings", luar.Map{
"join": strings.Join,
"split": strings.Split,
"first": func(str string) string {
if len(str) > 0 {
return string(str[0])
} else {
return ""
}
},
"rest": func(str string) string {
if len(str) > 0 {
return str[1:]
} else {
return ""
}
},
"format": func(format string, args ...interface{}) string {
return fmt.Sprintf(format, args...)
},
"scan": fmt.Sscanf,
"shuck": func(victim string) string {
return victim[1 : len(victim)-1]
},
"hassuffix": func(s, pattern string) bool {
return strings.HasSuffix(s, pattern)
},
})
}
开发者ID:imvu,项目名称:Tetra,代码行数:49,代码来源:script.go
示例3: ExampleMap
func ExampleMap() {
const code = `
print(#M)
print(M.one)
print(M.two)
print(M.three)
`
L := luar.Init()
defer L.Close()
M := luar.Map{
"one": "ein",
"two": "zwei",
"three": "drei",
}
luar.Register(L, "", luar.Map{
"M": M,
"print": fmt.Println,
})
err := L.DoString(code)
if err != nil {
fmt.Println("error", err.Error())
}
// Output:
// 3
// ein
// zwei
// drei
}
开发者ID:stevedonovan,项目名称:luar,代码行数:32,代码来源:example_test.go
示例4: Example_pointers
func Example_pointers() {
const test = `
-- Pointers to structs and structs within pointers are automatically dereferenced.
local t = newRef()
Print(t.Index, t.Number, t.Title)
`
type Ref struct {
Index int
Number *int
Title *string
}
newRef := func() *Ref {
n := new(int)
*n = 10
t := new(string)
*t = "foo"
return &Ref{Index: 17, Number: n, Title: t}
}
L := luar.Init()
defer L.Close()
luar.Register(L, "", luar.Map{
"Print": fmt.Println,
"newRef": newRef,
})
L.DoString(test)
// Output:
// 17 10 foo
}
开发者ID:stevedonovan,项目名称:luar,代码行数:33,代码来源:example_test.go
示例5: initLua
func (PM *PluginManager) initLua() {
PM.L = luar.Init()
luar.RawRegister(PM.L, "", luar.Map{
"RegisterCommand": func(L *lua.State) int {
name := L.ToString(1)
fn := luar.NewLuaObject(L, 2)
PM.Commands[name] = Plugin{name, fn}
log.Printf(" %-10s command\n", name)
return 0
},
"RegisterEvent": func(L *lua.State) int {
name := L.ToString(1)
event := L.ToString(2)
fn := luar.NewLuaObject(L, 3)
if _, ok := PM.Events[event]; !ok {
PM.Events[event] = make(map[string]Plugin)
}
PM.Events[event][name] = Plugin{name, fn}
log.Printf(" %-10s event\n", name)
return 0
},
})
luar.Register(PM.L, "go", luar.Map{
"Split": strings.Split,
"SplitN": strings.SplitN,
"PrintTable": func(table interface{}) {
log.Printf("%#v\n", table)
},
})
}
开发者ID:patterns,项目名称:gomero,代码行数:31,代码来源:plugin.go
示例6: loadMoonScript
func loadMoonScript(script *Script) (*Script, error) {
contents, failed := ioutil.ReadFile("modules/" + script.Name + ".moon")
if failed != nil {
return script, errors.New("Could not read " + script.Name + ".moon")
}
luar.Register(script.L, "", luar.Map{
"moonscript_code_from_file": string(contents),
})
/*
moonscript = require "moonscript"
xpcall = unsafe_xpcall
pcall = unsafe_pcall
local func, err = moonscript.loadstring(moonscript_code_from_file)
if err ~= nil then
tetra.log.Printf("Moonscript error, %#v", err)
error(err)
end
func()
*/
err := script.L.DoString(`moonscript = require "moonscript" xpcall = unsafe_xpcall pcall = unsafe_pcall local func, err = moonscript.loadstring(moonscript_code_from_file) if err ~= nil then tetra.log.Printf("Moonscript error, %#v", err) error(err) end func()`)
if err != nil {
script.Log.Print(err)
return nil, err
}
script.Kind = "moonscript"
return script, nil
}
开发者ID:imvu,项目名称:Tetra,代码行数:32,代码来源:script.go
示例7: main
func main() {
L := luar.Init()
defer L.Close()
// arbitrary Go functions can be registered
// to be callable from Lua
luar.Register(L, "", luar.Map{
"GoFun": GoFun,
})
res := L.DoString(code)
if !res {
fmt.Println("Error:", L.ToString(-1))
os.Exit(1)
}
res = L.DoString(setup)
if !res {
fmt.Println("Error:", L.ToString(-1))
os.Exit(1)
} else {
// there will be a table on the stack!
fmt.Println("table?", L.IsTable(-1))
v := luar.CopyTableToMap(L, nil, -1)
fmt.Println("returned map", v)
m := v.(map[string]interface{})
for k, v := range m {
fmt.Println(k, v)
}
}
}
开发者ID:sanyaade-embedded-systems,项目名称:luar,代码行数:31,代码来源:luar2.go
示例8: main
func main() {
L := luar.Init()
defer L.Close()
M := luar.Map{
"one": "ein",
"two": "zwei",
"three": "drei",
}
S := []string{"alfred", "alice", "bob", "frodo"}
ST := &MyStruct{"Dolly", 46}
luar.Register(L, "", luar.Map{
"M": M,
"S": S,
"ST": ST,
})
err := L.DoString(code)
if err != nil {
fmt.Println("error", err.Error())
}
}
开发者ID:EncoreJiang,项目名称:luar,代码行数:26,代码来源:map.go
示例9: init
func init() {
piepan.Register("lua", &piepan.Plugin{
Name: "Lua (C)",
New: func(in *piepan.Instance) piepan.Environment {
s := luar.Init()
p := &Plugin{
instance: in,
state: s,
listeners: make(map[string][]*luar.LuaObject),
}
luar.Register(s, "piepan", luar.Map{
"On": p.apiOn,
"Disconnect": p.apiDisconnect,
})
s.GetGlobal("piepan")
s.NewTable()
luar.Register(s, "*", luar.Map{
"Play": p.apiAudioPlay,
"IsPlaying": p.apiAudioIsPlaying,
"Stop": p.apiAudioStop,
"NewTarget": p.apiAudioNewTarget,
"SetTarget": p.apiAudioSetTarget,
"Bitrate": p.apiAudioBitrate,
"SetBitrate": p.apiAudioSetBitrate,
"Volume": p.apiAudioVolume,
"SetVolume": p.apiAudioSetVolume,
})
s.SetField(-2, "Audio")
s.NewTable()
luar.Register(s, "*", luar.Map{
"New": p.apiTimerNew,
})
s.SetField(-2, "Timer")
s.NewTable()
luar.Register(s, "*", luar.Map{
"New": p.apiProcessNew,
})
s.SetField(-2, "Process")
s.SetTop(0)
return p
},
})
}
开发者ID:mgalvey,项目名称:piepan,代码行数:45,代码来源:plugin.go
示例10: mkstate
// mkstate constructs a new lua state with the appropriate functions binded
// for use in scripts.
// it also binds functions used for actions, which should probably go somewhere else.
func mkstate() *lua.State {
L := luar.Init()
luar.Register(L, "", luar.Map{
"connect": lconnect,
"http": lhttp,
})
return L
}
开发者ID:hackerlist,项目名称:monty,代码行数:13,代码来源:lua.go
示例11: InitPlugin
func (r Runtime) InitPlugin(name, source string, implements func(string)) error {
context := luar.Init()
luar.Register(context, "", luar.Map{
"implements": func(interfaceName string) {
implements(interfaceName)
},
})
context.DoString(source)
r.plugins[name] = context
return nil
}
开发者ID:progrium,项目名称:go-plugins-lua,代码行数:11,代码来源:luaplugins.go
示例12: BindLua
// TODO: move these bindings into another file
func (gs *GameServer) BindLua() {
luar.Register(gs.Lua, "", luar.Map{
"gs": gs,
})
// add our script path here..
pkgpathscript := `package.path = package.path .. ";" .. gs.GetScriptPath() --";../?.lua"`
if err := gs.Lua.DoString(pkgpathscript); err != nil {
}
Lua_OpenObjectLib(gs.Lua)
}
开发者ID:stephenbalaban,项目名称:goland,代码行数:13,代码来源:gameserver.go
示例13: main
func main() {
whj := "wang::hai::jun"
fmt.Println(strings.Split(whj, "::"))
TestCall("111")
L := luar.Init()
defer L.Close()
M := luar.Map{
"one": "ein",
"two": "zwei",
"three": "drei",
}
S := []string{"alfred", "alice", "bob", "frodo"}
ST := &MyStruct{"Dolly", 46}
luar.Register(L, "", luar.Map{
"Print": fmt.Println,
"testcall": TestCall,
"print": fmt.Println,
"MSG": "hello", // can also register constants
"M": M,
"S": S,
"ST": ST,
})
//L.DoString(test)
L.DoString(code)
L.GetGlobal("print")
print := luar.NewLuaObject(L, -1)
print.Call("one two", 12)
L.GetGlobal("package")
pack := luar.NewLuaObject(L, -1)
fmt.Println(pack.Get("path"))
lcopy := luar.NewLuaObjectFromValue
gsub := luar.NewLuaObjectFromName(L, "string.gsub")
rmap := lcopy(L, luar.Map{
"NAME": "Dolly",
"HOME": "where you belong",
})
res, err := gsub.Call("hello $NAME go $HOME", "%$(%u+)", rmap)
if res == nil {
fmt.Println("error", err)
} else {
fmt.Println("\033[0;31mresult\033[0m", res)
}
}
开发者ID:yc7369,项目名称:gostudy,代码行数:53,代码来源:luatest.go
示例14: registerCommands
func (c *Conf) registerCommands() {
luar.Register(c.l, "", luar.Map{
"Directory": Directory,
"File": File,
"AptGet": AptGet,
"HttpGet": HttpGet,
"TarGz": TarGz,
"UnTarGz": UnTarGz,
"Cron": Cron,
"Group": Group,
})
}
开发者ID:jeromer,项目名称:haiconf,代码行数:12,代码来源:main.go
示例15: main
func main() {
L := luar.Init()
defer L.Close()
luar.Register(L, "", luar.Map{
"Print": fmt.Println,
"MSG": "hello", // can also register constants
})
L.DoString(test)
}
开发者ID:EncoreJiang,项目名称:luar,代码行数:12,代码来源:example.go
示例16: register
func register() {
// Go functions or values you want to use interactively!
ST := &MyStruct{"Dolly", 46}
S := MyStruct{"Joe", 32}
luar.Register(L, "", luar.Map{
"regexp": regexp.Compile,
"println": fmt.Println,
"ST": ST,
"S": S,
"String": String,
})
}
开发者ID:EncoreJiang,项目名称:luar,代码行数:13,代码来源:luar.go
示例17: main
func main() {
L := luar.Init()
defer L.Close()
luar.Register(L, "", luar.Map{
"newT": newT,
})
res := L.DoString(setup)
if res != nil {
fmt.Println("Error:", res)
}
}
开发者ID:EncoreJiang,项目名称:luar,代码行数:14,代码来源:ptr-elem.go
示例18: main
func main() {
L := luar.Init()
defer L.Close()
// arbitrary Go functions can be registered
// to be callable from Lua
luar.Register(L, "", luar.Map{
"config": config,
})
res := L.DoString(setup)
if res != nil {
fmt.Println("Error:", res)
}
}
开发者ID:kdar,项目名称:luar,代码行数:16,代码来源:struct.go
示例19: ExampleRegister_sandbox
func ExampleRegister_sandbox() {
const code = `
Print("foo")
Print(io ~= nil)
Print(os == nil)
`
L := luar.Init()
defer L.Close()
res := L.LoadString(code)
if res != 0 {
msg := L.ToString(-1)
fmt.Println("could not compile", msg)
}
// Create a empty sandbox.
L.NewTable()
// "*" means "use table on top of the stack."
luar.Register(L, "*", luar.Map{
"Print": fmt.Println,
})
env := luar.NewLuaObject(L, -1)
G := luar.Global(L)
// We can copy any Lua object from "G" to env with 'Set', e.g.:
// env.Set("print", G.Get("print"))
// A more convenient and efficient way is to do a bulk copy with 'Setv':
env.Setv(G, "print", "io")
// Set up sandbox.
L.SetfEnv(-2)
// Run 'code' chunk.
err := L.Call(0, 0)
if err != nil {
fmt.Println("could not run", err)
}
// Output:
// foo
// true
// true
}
开发者ID:stevedonovan,项目名称:luar,代码行数:43,代码来源:example_test.go
示例20: ExampleMakeChan
func ExampleMakeChan() {
L1 := luar.Init()
defer L1.Close()
L2 := luar.Init()
defer L2.Close()
luar.MakeChan(L1)
L1.SetGlobal("c")
L1.GetGlobal("c")
c := luar.LuaToGo(L1, nil, -1)
luar.Register(L2, "", luar.Map{
"c": c,
"Print": fmt.Println,
})
const code1 = `
c.send(17)
`
const code2 = `
v = c.recv()
Print(v)
`
var wg sync.WaitGroup
wg.Add(1)
go func() {
err := L1.DoString(code1)
if err != nil {
fmt.Println(err)
}
wg.Done()
}()
err := L2.DoString(code2)
if err != nil {
fmt.Println(err)
}
wg.Wait()
// Output:
// 17
}
开发者ID:stevedonovan,项目名称:luar,代码行数:43,代码来源:example_test.go
注:本文中的github.com/stevedonovan/luar.Register函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论