mirror of
https://github.com/Hilbis/Hilbish
synced 2025-07-01 16:52:03 +00:00
fix: reimpl commander, fix bait build
This commit is contained in:
parent
4f4a836f05
commit
d01655e803
@ -262,7 +262,7 @@ end)
|
|||||||
#example
|
#example
|
||||||
*/
|
*/
|
||||||
func (b *Bait) bcatch(mlr *moonlight.Runtime, c *moonlight.GoCont) (moonlight.Cont, error) {
|
func (b *Bait) bcatch(mlr *moonlight.Runtime, c *moonlight.GoCont) (moonlight.Cont, error) {
|
||||||
name, catcher, err := util.HandleStrCallback(mlr, c)
|
name, catcher, err := util.HandleStrCallback(mlr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -54,11 +54,9 @@ func New(rtm *moonlight.Runtime) *Commander {
|
|||||||
|
|
||||||
func (c *Commander) Loader(rtm *moonlight.Runtime) moonlight.Value {
|
func (c *Commander) Loader(rtm *moonlight.Runtime) moonlight.Value {
|
||||||
exports := map[string]moonlight.Export{
|
exports := map[string]moonlight.Export{
|
||||||
/*
|
|
||||||
"register": {c.cregister, 2, false},
|
"register": {c.cregister, 2, false},
|
||||||
"deregister": {c.cderegister, 1, false},
|
"deregister": {c.cderegister, 1, false},
|
||||||
"registry": {c.cregistry, 0, false},
|
"registry": {c.cregistry, 0, false},
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
mod := moonlight.NewTable()
|
mod := moonlight.NewTable()
|
||||||
rtm.SetExports(mod, exports)
|
rtm.SetExports(mod, exports)
|
||||||
@ -83,21 +81,20 @@ commander.register('hello', function(args, sinks)
|
|||||||
end)
|
end)
|
||||||
#example
|
#example
|
||||||
*/
|
*/
|
||||||
func (c *Commander) cregister(mlr *moonlight.Runtime, ct *moonlight.GoCont) (moonlight.Cont, error) {
|
func (c *Commander) cregister(mlr *moonlight.Runtime) error {
|
||||||
cmdName, cmd, err := util.HandleStrCallback(mlr, ct)
|
cmdName, cmd, err := util.HandleStrCallback(mlr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Commands[cmdName] = cmd
|
c.Commands[cmdName] = cmd
|
||||||
|
|
||||||
return ct.Next(), err
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// deregister(name)
|
// deregister(name)
|
||||||
// Removes the named command. Note that this will only remove Commander-registered commands.
|
// Removes the named command. Note that this will only remove Commander-registered commands.
|
||||||
// #param name string Name of the command to remove.
|
// #param name string Name of the command to remove.
|
||||||
/*
|
|
||||||
func (c *Commander) cderegister(mlr *moonlight.Runtime) error {
|
func (c *Commander) cderegister(mlr *moonlight.Runtime) error {
|
||||||
if err := mlr.Check1Arg(); err != nil {
|
if err := mlr.Check1Arg(); err != nil {
|
||||||
return err
|
return err
|
||||||
@ -111,13 +108,12 @@ func (c *Commander) cderegister(mlr *moonlight.Runtime) error {
|
|||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
// registry() -> table
|
// registry() -> table
|
||||||
// Returns all registered commanders. Returns a list of tables with the following keys:
|
// Returns all registered commanders. Returns a list of tables with the following keys:
|
||||||
// - `exec`: The function used to run the commander. Commanders require args and sinks to be passed.
|
// - `exec`: The function used to run the commander. Commanders require args and sinks to be passed.
|
||||||
// #returns table
|
// #returns table
|
||||||
/*func (c *Commander) cregistry(mlr *moonlight.Runtime, ct *moonlight.GoCont) (moonlight.Cont, error) {
|
func (c *Commander) cregistry(mlr *moonlight.Runtime) error {
|
||||||
registryLua := moonlight.NewTable()
|
registryLua := moonlight.NewTable()
|
||||||
for cmdName, cmd := range c.Commands {
|
for cmdName, cmd := range c.Commands {
|
||||||
cmdTbl := moonlight.NewTable()
|
cmdTbl := moonlight.NewTable()
|
||||||
@ -128,5 +124,6 @@ func (c *Commander) cderegister(mlr *moonlight.Runtime) error {
|
|||||||
registryLua.SetField(cmdName, moonlight.TableValue(cmdTbl))
|
registryLua.SetField(cmdName, moonlight.TableValue(cmdTbl))
|
||||||
}
|
}
|
||||||
|
|
||||||
return mlr.PushNext1(ct, moonlight.TableValue(registryLua)), nil
|
mlr.PushNext1(moonlight.TableValue(registryLua))
|
||||||
}*/
|
return nil
|
||||||
|
}
|
||||||
|
@ -17,7 +17,7 @@ func SetField(module *rt.Table, field string, value rt.Value) {
|
|||||||
|
|
||||||
// HandleStrCallback handles function parameters for Go functions which take
|
// HandleStrCallback handles function parameters for Go functions which take
|
||||||
// a string and a closure.
|
// a string and a closure.
|
||||||
func HandleStrCallback(mlr *moonlight.Runtime, c *moonlight.GoCont) (string, *moonlight.Closure, error) {
|
func HandleStrCallback(mlr *moonlight.Runtime) (string, *moonlight.Closure, error) {
|
||||||
if err := mlr.CheckNArgs(2); err != nil {
|
if err := mlr.CheckNArgs(2); err != nil {
|
||||||
return "", nil, err
|
return "", nil, err
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user