diff --git a/c/lua/_demo/coroutine-cfunc/coroutine.go b/c/lua/_demo/coroutine-cfunc/coroutine.go index 676a5bfc..8be4e405 100644 --- a/c/lua/_demo/coroutine-cfunc/coroutine.go +++ b/c/lua/_demo/coroutine-cfunc/coroutine.go @@ -13,7 +13,7 @@ func coroutineFunc(L *lua.State) c.Int { } func main() { - L := lua.Newstate() + L := lua.Newstate__1() defer L.Close() L.Openlibs() diff --git a/c/lua/_demo/coroutine/coroutine.go b/c/lua/_demo/coroutine/coroutine.go index ed05d98b..7d5e9c69 100644 --- a/c/lua/_demo/coroutine/coroutine.go +++ b/c/lua/_demo/coroutine/coroutine.go @@ -18,7 +18,7 @@ func coroutineFunc(L *lua.State) { } func main() { - L := lua.Newstate() + L := lua.Newstate__1() defer L.Close() L.Openlibs() diff --git a/c/lua/_demo/crroutine-continue/corroutine.go b/c/lua/_demo/crroutine-continue/corroutine.go index 4fe9f8c5..8070cb94 100644 --- a/c/lua/_demo/crroutine-continue/corroutine.go +++ b/c/lua/_demo/crroutine-continue/corroutine.go @@ -29,7 +29,7 @@ func createCountdown(L *lua.State) c.Int { } func main() { - L := lua.Newstate() + L := lua.Newstate__1() L.Openlibs() defer L.Close() L.Register(c.Str("create_countdown"), createCountdown) diff --git a/c/lua/_demo/custom-panic/panic.go b/c/lua/_demo/custom-panic/panic.go index e0e732bf..6c22dbb5 100644 --- a/c/lua/_demo/custom-panic/panic.go +++ b/c/lua/_demo/custom-panic/panic.go @@ -24,7 +24,7 @@ func customPanic(L *lua.State) c.Int { } func main() { - L := lua.Newstate() + L := lua.Newstate__1() defer L.Close() L.Openlibs() diff --git a/c/lua/_demo/dump/load/load.go b/c/lua/_demo/dump/load/load.go index 32d9cd61..f86ee32c 100644 --- a/c/lua/_demo/dump/load/load.go +++ b/c/lua/_demo/dump/load/load.go @@ -33,7 +33,7 @@ func reader(L *lua.State, data c.Pointer, size *c.Ulong) *c.Char { } func main() { - L := lua.Newstate() + L := lua.Newstate__1() defer L.Close() L.Openlibs() diff --git a/c/lua/_demo/dump/save/save.go b/c/lua/_demo/dump/save/save.go index e94cc2e5..0e6b61b2 100644 --- a/c/lua/_demo/dump/save/save.go +++ b/c/lua/_demo/dump/save/save.go @@ -21,7 +21,7 @@ func writer(L *lua.State, p c.Pointer, sz c.Ulong, ud c.Pointer) c.Int { } func main() { - L := lua.Newstate() + L := lua.Newstate__1() defer L.Close() L.Openlibs() diff --git a/c/lua/_demo/error/error.go b/c/lua/_demo/error/error.go index ed518f98..3ca86754 100644 --- a/c/lua/_demo/error/error.go +++ b/c/lua/_demo/error/error.go @@ -8,7 +8,7 @@ import ( ) func main() { - L := lua.Newstate() + L := lua.Newstate__1() defer L.Close() L.Openlibs() if res := L.Loadstring(c.Str("function doubleNumber(x) ! return x * 2 end")); res != lua.OK { diff --git a/c/lua/_demo/funccall-concat/funccall.go b/c/lua/_demo/funccall-concat/funccall.go index b9c0d0b5..4168425d 100644 --- a/c/lua/_demo/funccall-concat/funccall.go +++ b/c/lua/_demo/funccall-concat/funccall.go @@ -8,7 +8,7 @@ import ( ) func main() { - L := lua.Newstate() + L := lua.Newstate__1() defer L.Close() L.Openlibs() diff --git a/c/lua/_demo/funccall-number/funccall.go b/c/lua/_demo/funccall-number/funccall.go index 8cb34d5a..9db886f7 100644 --- a/c/lua/_demo/funccall-number/funccall.go +++ b/c/lua/_demo/funccall-number/funccall.go @@ -8,7 +8,7 @@ import ( ) func main() { - L := lua.Newstate() + L := lua.Newstate__1() defer L.Close() L.Openlibs() diff --git a/c/lua/_demo/funccall-string/funccall.go b/c/lua/_demo/funccall-string/funccall.go index 14b76479..066ce601 100644 --- a/c/lua/_demo/funccall-string/funccall.go +++ b/c/lua/_demo/funccall-string/funccall.go @@ -8,7 +8,7 @@ import ( ) func main() { - L := lua.Newstate() + L := lua.Newstate__1() defer L.Close() L.Openlibs() diff --git a/c/lua/_demo/hello/hello.go b/c/lua/_demo/hello/hello.go index 71ee8592..e640e78b 100644 --- a/c/lua/_demo/hello/hello.go +++ b/c/lua/_demo/hello/hello.go @@ -8,7 +8,7 @@ import ( ) func main() { - L := lua.Newstate() + L := lua.Newstate__1() defer L.Close() L.Openlibs() if res := L.Dostring(c.Str("print('hello world')")); res != lua.OK { diff --git a/c/lua/_demo/loadcall/loadcall.go b/c/lua/_demo/loadcall/loadcall.go index 02886227..8b3247a3 100644 --- a/c/lua/_demo/loadcall/loadcall.go +++ b/c/lua/_demo/loadcall/loadcall.go @@ -8,7 +8,7 @@ import ( ) func main() { - L := lua.Newstate() + L := lua.Newstate__1() defer L.Close() L.Openlibs() diff --git a/c/lua/_demo/metatable/metatable.go b/c/lua/_demo/metatable/metatable.go index 424fd5ed..f952f72c 100644 --- a/c/lua/_demo/metatable/metatable.go +++ b/c/lua/_demo/metatable/metatable.go @@ -29,7 +29,7 @@ func printStack(L *lua.State, message string) { } func main() { - L := lua.Newstate() + L := lua.Newstate__1() defer L.Close() L.Openlibs() diff --git a/c/lua/_demo/stack/stack.go b/c/lua/_demo/stack/stack.go index fed39e7f..a7e13f1d 100644 --- a/c/lua/_demo/stack/stack.go +++ b/c/lua/_demo/stack/stack.go @@ -17,7 +17,7 @@ func printStack(L *lua.State, stateName *c.Char) { func main() { // Create a new Lua state and open libraries - L := lua.Newstate() + L := lua.Newstate__1() defer L.Close() L.Openlibs() @@ -68,7 +68,7 @@ func main() { printStack(L, c.Str("L1")) // Create a second Lua state - L1 := lua.Newstate() + L1 := lua.Newstate__1() defer L1.Close() // Move two elements to the new state diff --git a/c/lua/_demo/table/table.go b/c/lua/_demo/table/table.go index b9da2bfa..14407617 100644 --- a/c/lua/_demo/table/table.go +++ b/c/lua/_demo/table/table.go @@ -29,7 +29,7 @@ func printTable(L *lua.State) { } func main() { - L := lua.Newstate() + L := lua.Newstate__1() defer L.Close() L.Openlibs() diff --git a/c/lua/_demo/thread/thread.go b/c/lua/_demo/thread/thread.go index e5c74b02..f4a25d5c 100644 --- a/c/lua/_demo/thread/thread.go +++ b/c/lua/_demo/thread/thread.go @@ -15,7 +15,7 @@ func pushThread(state *lua.State, name string) { } func main() { - L := lua.Newstate() + L := lua.Newstate__1() defer L.Close() L.Openlibs() diff --git a/c/lua/_demo/userdata/userdata.go b/c/lua/_demo/userdata/userdata.go index f5872e34..3d2c2c35 100644 --- a/c/lua/_demo/userdata/userdata.go +++ b/c/lua/_demo/userdata/userdata.go @@ -12,7 +12,7 @@ type lightdata struct { } func main() { - L := lua.Newstate() + L := lua.Newstate__1() defer L.Close() L.Openlibs() diff --git a/c/lua/lauxlib.go b/c/lua/lauxlib.go index 5b3a54b8..df7aac0d 100644 --- a/c/lua/lauxlib.go +++ b/c/lua/lauxlib.go @@ -33,8 +33,8 @@ func (L *State) Loadfile(filename *c.Char) c.Int { return L.Loadfilex(filename, // llgo:link (*State).Loadstring C.luaL_loadstring func (L *State) Loadstring(s *c.Char) c.Int { return 0 } -//go:linkname Newstate C.luaL_newstate -func Newstate() *State +//go:linkname Newstate__1 C.luaL_newstate +func Newstate__1() *State { return nil } // /* // ** =============================================================== diff --git a/c/lua/lua.go b/c/lua/lua.go index 207ae10f..6c64b5b9 100644 --- a/c/lua/lua.go +++ b/c/lua/lua.go @@ -114,7 +114,8 @@ type Writer func(L *State, p c.Pointer, sz c.Ulong, ud c.Pointer) c.Int * Type for memory-allocation functions */ -// typedef void * (*lua_Alloc) (void *ud, void *ptr, size_t osize, size_t nsize); +// llgo:type C +type Alloc func(ud c.Pointer, ptr c.Pointer, osize c.Ulong, nsize c.Ulong) c.Pointer /* * Type for warning functions @@ -155,7 +156,8 @@ type Writer func(L *State, p c.Pointer, sz c.Ulong, ud c.Pointer) c.Int // llgo:link (*State).Close C.lua_close func (L *State) Close() {} -// State *(lua_newstate) (lua_Alloc f, void *ud); +// llgo:link Newstate__0 C.lua_newstate +func Newstate__0(f Alloc, ud c.Pointer) *State { return nil } // llgo:link (*State).Newthread C.lua_newthread func (L *State) Newthread() *State { return nil } @@ -248,7 +250,8 @@ func (L *State) Touserdata(idx c.Int) c.Pointer { return nil } // llgo:link (*State).Tothread C.lua_tothread func (L *State) Tothread(idx c.Int) *State { return nil } -// LUA_API const void *(lua_topointer) (State *L, int idx); +// llgo:link (*State).Topointer C.lua_topointer +func (L *State) Topointer(idx c.Int) c.Pointer { return nil } /* * Comparison and arithmetic functions @@ -322,7 +325,8 @@ func (L *State) Newuserdatauv(sz uintptr, nuvalue c.Int) c.Pointer { return nil // llgo:link (*State).Getmetatable C.lua_getmetatable func (L *State) Getmetatable(objindex c.Int) c.Int { return 0 } -// LUA_API int (lua_getiuservalue) (State *L, int idx, int n); +// llgo:link (*State).Getiuservalue C.lua_getiuservalue +func (L *State) Getiuservalue(idx c.Int, n c.Int) c.Int { return 0 } /* * set functions (stack -> Lua) @@ -352,7 +356,8 @@ func (L *State) Rawsetp(idx c.Int, p c.Pointer) {} // llgo:link (*State).Setmetatable C.lua_setmetatable func (L *State) Setmetatable(objindex c.Int) c.Int { return 0 } -//int (lua_setiuservalue) (State *L, int idx, int n); +// llgo:link (*State).Setiuservalue C.lua_setiuservalue +func (L *State) Setiuservalue(idx c.Int, n c.Int) c.Int { return 0 } /* * 'load' and 'call' functions (load and run Lua code) @@ -436,16 +441,26 @@ func (L *State) Next(idx c.Int) c.Int { return 0 } // llgo:link (*State).Error C.lua_error func (L *State) Error() c.Int { return 0 } -// LUA_API void (lua_concat) (State *L, int n); -// LUA_API void (lua_len) (State *L, int idx); +// llgo:link (*State).Concat C.lua_concat +func (L *State) Concat(n c.Int) {} -// LUA_API size_t (lua_stringtonumber) (State *L, const char *s); +// llgo:link (*State).Len C.lua_len +func (L *State) Len(idx c.Int) {} -// LUA_API lua_Alloc (lua_getallocf) (State *L, void **ud); -// LUA_API void (lua_setallocf) (State *L, lua_Alloc f, void *ud); +// llgo:link (*State).Stringtonumber C.lua_stringtonumber +func (L *State) Stringtonumber(s *c.Char) c.Ulong { return 0 } -// LUA_API void (lua_toclose) (State *L, int idx); -// LUA_API void (lua_closeslot) (State *L, int idx); +// llgo:link (*State).Getallocf C.lua_getallocf +func (L *State) Getallocf(ud *c.Pointer) Alloc { return nil } + +// llgo:link (*State).Setallocf C.lua_setallocf +func (L *State) Setallocf(f Alloc, ud c.Pointer) Alloc { return nil } + +// llgo:link (*State).Toclose C.lua_toclose +func (L *State) Toclose(idx c.Int) {} + +// llgo:link (*State).Closeslot C.lua_closeslot +func (L *State) Closeslot(idx c.Int) {} /* ** {============================================================== @@ -454,7 +469,6 @@ func (L *State) Error() c.Int { return 0 } */ // #define lua_getextraspace(L) ((void *)((char *)(L) - LUA_EXTRASPACE)) - func (L *State) Tonumber(idx c.Int) Number { return L.Tonumberx(idx, nil) } func (L *State) Tostring(idx c.Int) *c.Char { return L.Tolstring(idx, nil) } func (L *State) Tointeger(idx c.Int) Integer { return L.Tointegerx(idx, nil) } @@ -475,9 +489,13 @@ func (L *State) Isboolean(n c.Int) bool { return L.Type(n) == c.Int(BOOLEA func (L *State) Isthread(n c.Int) bool { return L.Type(n) == c.Int(THREAD) } func (L *State) Isnone(n c.Int) bool { return L.Type(n) == c.Int(NONE) } func (L *State) Isnoneornil(n c.Int) bool { return L.Type(n) <= 0 } +func (L *State) Pushliteral(s *c.Char) *c.Char { + return L.Pushstring(s) +} -// #define lua_pushliteral(L, s) lua_pushstring(L, "" s) -// #define lua_pushglobaltable(L) ((void)lua_rawgeti(L, LUA_REGISTRYINDEX, LUA_RIDX_GLOBALS)) +func (L *State) Pushglobaltable() c.Int { + return L.Rawgeti(REGISTRYINDEX, RIDX_GLOBALS) +} func (L *State) Insert(idx c.Int) { L.Rotate(idx, 1) @@ -505,8 +523,13 @@ func (L *State) Newuserdata(sz uintptr) c.Pointer { return L.Newuserdatauv(sz, 1) } -// #define lua_getuservalue(L,idx) lua_getiuservalue(L,idx,1) -// #define lua_setuservalue(L,idx) lua_setiuservalue(L,idx,1) +func (L *State) Getuservalue(idx c.Int) c.Int { + return L.Getiuservalue(idx, 1) +} + +func (L *State) Setuservalue(idx c.Int) c.Int { + return L.Setiuservalue(idx, 1) +} // #define LUA_NUMTAGS LUA_NUMTYPES