c/lua:register

This commit is contained in:
luoliwoshang
2024-08-25 12:32:31 +08:00
parent 54ce1d8d2f
commit cf8a170133
2 changed files with 7 additions and 6 deletions

View File

@@ -31,10 +31,8 @@ func main() {
L.Atpanic(customPanic) L.Atpanic(customPanic)
L.Pushcfunction(triggerError) L.Register(c.Str("trigger_error"), triggerError)
L.Setglobal(c.Str("trigger_error")) L.Register(c.Str("trigger_format_error"), triggerFormatError)
L.Pushcfunction(triggerFormatError)
L.Setglobal(c.Str("trigger_format_error"))
c.Printf(c.Str("1. error (protected):\n")) c.Printf(c.Str("1. error (protected):\n"))
L.Getglobal(c.Str("trigger_error")) L.Getglobal(c.Str("trigger_error"))

View File

@@ -91,7 +91,7 @@ type CFunction func(L *State) c.Int
// ** Type for continuation functions // ** Type for continuation functions
// */ // */
// TODO(zzy): KFunction does not currently support // llgo:type C
type KFunction func(L *State, status c.Int, ctx KContext) c.Int type KFunction func(L *State, status c.Int, ctx KContext) c.Int
// /* // /*
@@ -420,7 +420,10 @@ func (L *State) Tointeger(idx c.Int) Integer { return L.Tointegerx(idx, nil) }
func (L *State) Pop(n c.Int) { L.Settop(-(n) - 1) } func (L *State) Pop(n c.Int) { L.Settop(-(n) - 1) }
func (L *State) Newtable() { L.Createtable(0, 0) } func (L *State) Newtable() { L.Createtable(0, 0) }
// #define lua_register(L,n,f) (lua_pushcfunction(L, (f)), lua_setglobal(L, (n))) func (L *State) Register(name *c.Char, f CFunction) {
L.Pushcfunction(f)
L.Setglobal(name)
}
func (L *State) Pushcfunction(f CFunction) { L.Pushcclosure(f, 0) } func (L *State) Pushcfunction(f CFunction) { L.Pushcclosure(f, 0) }
func (L *State) Isfunction(n c.Int) bool { return L.Type(n) == c.Int(FUNCTION) } func (L *State) Isfunction(n c.Int) bool { return L.Type(n) == c.Int(FUNCTION) }