From e3db1ba0c573d78a7c7caa066a540aa7d178e9da Mon Sep 17 00:00:00 2001 From: Tim van Osch Date: Fri, 27 Dec 2024 20:44:07 +0100 Subject: [PATCH] docs: fix comment formatting --- _docgenerator/example.txt | 6 +- _docgenerator/main.go | 39 +-- lua/golua_c_lua51.go | 150 ++++++------ lua/golua_c_lua52.go | 110 ++++----- lua/golua_c_lua53.go | 110 ++++----- lua/golua_c_lua54.go | 110 ++++----- lua/lauxlib.go | 162 ++++++++++--- lua/lua.go | 482 +++++++++++++++++++------------------- 8 files changed, 641 insertions(+), 528 deletions(-) diff --git a/_docgenerator/example.txt b/_docgenerator/example.txt index 39c47e8..03257ff 100644 --- a/_docgenerator/example.txt +++ b/_docgenerator/example.txt @@ -1,8 +1,4 @@ -// lua_upvalueid -/* - * [-0, +0, –] - * Returns a unique identifier for the upvalue numbered n from the closure at index funcindex. -*/ +// lua_upvalueindex func (L *State) UpvalueIndex(n int) int { return int(C.clua_upvalueindex(C.int32_t(n))) } diff --git a/_docgenerator/main.go b/_docgenerator/main.go index ba81c37..5d2ad2d 100644 --- a/_docgenerator/main.go +++ b/_docgenerator/main.go @@ -45,7 +45,6 @@ func main() { if *flagClean { updatedCode = removeOldDocumentation(string(goCode)) } else { - // Fetch or load cached Lua documentation luadocs, err := getCachedLuaDocs() if err != nil { @@ -64,7 +63,7 @@ func main() { } if *flagDoWrite { - err := os.WriteFile(goFile, []byte(updatedCode), 0644) + err := os.WriteFile(goFile, []byte(updatedCode), 0o644) if err != nil { fmt.Println("Error writing annotated code to file:", err) os.Exit(1) @@ -82,7 +81,7 @@ func getCachedLuaDocs() (string, error) { // Ensure cache directory exists if _, err := os.Stat(cacheDir); os.IsNotExist(err) { - err := os.Mkdir(cacheDir, 0755) + err := os.Mkdir(cacheDir, 0o755) if err != nil { return "", err } @@ -98,7 +97,7 @@ func getCachedLuaDocs() (string, error) { body = string(cachedBody) } else { // Fetch Lua manual and cache it - url := fmt.Sprintf("https://www.lua.org/manual/%s/manual.html", *flagLuaVersion) // Change version as needed + url := luaManualURL("") resp, err := http.Get(url) if err != nil { return "", err @@ -115,7 +114,7 @@ func getCachedLuaDocs() (string, error) { } body = string(bodyBytes) - err = os.WriteFile(cacheFile, bodyBytes, 0644) + err = os.WriteFile(cacheFile, bodyBytes, 0o644) if err != nil { return "", err } @@ -130,6 +129,10 @@ type LuaFunction struct { Description string } +func luaManualURL(anchor string) string { + return fmt.Sprintf("https://www.lua.org/manual/%s/manual.html#%s", *flagLuaVersion, anchor) // Change version as needed +} + func parseLuaDocs(html string) (map[string]LuaFunction, error) { doc, err := goquery.NewDocumentFromReader(strings.NewReader(html)) if err != nil { @@ -138,7 +141,7 @@ func parseLuaDocs(html string) (map[string]LuaFunction, error) { functions := map[string]LuaFunction{} - doc.Find("hr + h3").Has("a[name^='lua_']").Each(func(i int, s *goquery.Selection) { + doc.Find("hr + h3").Has("a[name^='lua']").Each(func(i int, s *goquery.Selection) { var luaFunc LuaFunction // Extract name @@ -167,8 +170,8 @@ func parseLuaDocs(html string) (map[string]LuaFunction, error) { } func removeOldDocumentation(code string) string { - blockCommentRegex := regexp.MustCompile(`(?m)(// lua_.*$\n)/\*\n(?: \*.*$\n)+[ ]?\*/$\n`) - return blockCommentRegex.ReplaceAllString(code, "$1") + blockCommentRegex := regexp.MustCompile(`(?m)// \[(lua.*)\] -> .*$\n(// .*$\n)+`) + return blockCommentRegex.ReplaceAllString(code, "// $1\n") } // Add documentation comments to the Go code @@ -178,16 +181,22 @@ func addDocumentation(code string, luaFuncs map[string]LuaFunction) string { lines := strings.Split(code, "\n") var annotatedLines []string + matchComment := regexp.MustCompile(`// luaL?_.+`) + for _, line := range lines { - annotatedLines = append(annotatedLines, line) - if strings.HasPrefix(line, "// lua_") { + if matchComment.MatchString(line) { functionName := strings.TrimPrefix(line, "// ") - if doc, exists := luaFuncs[functionName]; exists { - annotatedLines = append(annotatedLines, "/*") - annotatedLines = append(annotatedLines, " * "+doc.StackEffect) - annotatedLines = append(annotatedLines, " * "+doc.Description) - annotatedLines = append(annotatedLines, " */") + if doc, exists := luaFuncs[strings.ToLower(functionName)]; exists { + annotatedLines = append(annotatedLines, fmt.Sprintf("// [%s] -> %s", doc.Name, doc.StackEffect)) + annotatedLines = append(annotatedLines, "//") + annotatedLines = append(annotatedLines, "// "+doc.Description) + annotatedLines = append(annotatedLines, "//") + annotatedLines = append(annotatedLines, fmt.Sprintf("// [%s]: %s", doc.Name, luaManualURL(strings.ToLower(doc.Name)))) + } else { + annotatedLines = append(annotatedLines, "// "+functionName) } + } else { + annotatedLines = append(annotatedLines, line) } } diff --git a/lua/golua_c_lua51.go b/lua/golua_c_lua51.go index 27b97ef..39a7cd0 100644 --- a/lua/golua_c_lua51.go +++ b/lua/golua_c_lua51.go @@ -123,38 +123,38 @@ func lualLoadFile(s *C.lua_State, filename *C.char) C.int { return C.luaL_loadfile(s, filename) } -// lua_equal -/* - * [-0, +0, e] - * Returns 1 if the two values in acceptable indices index1 and index2 are equal, following the semantics of the Lua == operator (that is, may call metamethods). Otherwise returns 0. Also returns 0 if any of the indices is non valid. - */ +// [lua_equal] -> [-0, +0, e] +// +// Returns 1 if the two values in acceptable indices index1 and index2 are equal, following the semantics of the Lua == operator (that is, may call metamethods). Otherwise returns 0. Also returns 0 if any of the indices is non valid. +// +// [lua_equal]: https://www.lua.org/manual/5.1/manual.html#lua_equal func (L *State) Equal(index1, index2 int) bool { return C.lua_equal(L.s, C.int(index1), C.int(index2)) == 1 } -// lua_getfenv -/* - * [-0, +1, -] - * Pushes onto the stack the environment table of the value at the given index. - */ +// [lua_getfenv] -> [-0, +1, -] +// +// Pushes onto the stack the environment table of the value at the given index. +// +// [lua_getfenv]: https://www.lua.org/manual/5.1/manual.html#lua_getfenv func (L *State) GetfEnv(index int) { C.lua_getfenv(L.s, C.int(index)) } -// lua_lessthan -/* - * [-0, +0, e] - * Returns 1 if the value at acceptable index index1 is smaller than the value at acceptable index index2, following the semantics of the Lua < operator (that is, may call metamethods). Otherwise returns 0. Also returns 0 if any of the indices is non valid. - */ +// [lua_lessthan] -> [-0, +0, e] +// +// Returns 1 if the value at acceptable index index1 is smaller than the value at acceptable index index2, following the semantics of the Lua < operator (that is, may call metamethods). Otherwise returns 0. Also returns 0 if any of the indices is non valid. +// +// [lua_lessthan]: https://www.lua.org/manual/5.1/manual.html#lua_lessthan func (L *State) LessThan(index1, index2 int) bool { return C.lua_lessthan(L.s, C.int(index1), C.int(index2)) == 1 } -// lua_setfenv -/* - * [-1, +0, -] - * Pops a table from the stack and sets it as the new environment for the value at the given index. If the value at the given index is neither a function nor a thread nor a userdata, lua_setfenv returns 0. Otherwise it returns 1. - */ +// [lua_setfenv] -> [-1, +0, -] +// +// Pops a table from the stack and sets it as the new environment for the value at the given index. If the value at the given index is neither a function nor a thread nor a userdata, lua_setfenv returns 0. Otherwise it returns 1. +// +// [lua_setfenv]: https://www.lua.org/manual/5.1/manual.html#lua_setfenv func (L *State) SetfEnv(index int) { C.lua_setfenv(L.s, C.int(index)) } @@ -163,29 +163,29 @@ func (L *State) ObjLen(index int) uint { return uint(C.lua_objlen(L.s, C.int(index))) } -// lua_tointeger -/* - * [-0, +0, -] - * Converts the Lua value at the given acceptable index to the signed integral type lua_Integer. The Lua value must be a number or a string convertible to a number (see §2.2.1); otherwise, lua_tointeger returns 0. - */ +// [lua_tointeger] -> [-0, +0, -] +// +// Converts the Lua value at the given acceptable index to the signed integral type lua_Integer. The Lua value must be a number or a string convertible to a number (see §2.2.1); otherwise, lua_tointeger returns 0. +// +// [lua_tointeger]: https://www.lua.org/manual/5.1/manual.html#lua_tointeger func (L *State) ToInteger(index int) int { return int(C.lua_tointeger(L.s, C.int(index))) } -// lua_tonumber -/* - * [-0, +0, -] - * Converts the Lua value at the given acceptable index to the C type lua_Number (see lua_Number). The Lua value must be a number or a string convertible to a number (see §2.2.1); otherwise, lua_tonumber returns 0. - */ +// [lua_tonumber] -> [-0, +0, -] +// +// Converts the Lua value at the given acceptable index to the C type lua_Number (see lua_Number). The Lua value must be a number or a string convertible to a number (see §2.2.1); otherwise, lua_tonumber returns 0. +// +// [lua_tonumber]: https://www.lua.org/manual/5.1/manual.html#lua_tonumber func (L *State) ToNumber(index int) float64 { return float64(C.lua_tonumber(L.s, C.int(index))) } -// lua_yield -/* - * [-?, +?, -] - * Yields a coroutine. - */ +// [lua_yield] -> [-?, +?, -] +// +// Yields a coroutine. +// +// [lua_yield]: https://www.lua.org/manual/5.1/manual.html#lua_yield func (L *State) Yield(nresults int) int { return int(C.lua_yield(L.s, C.int(nresults))) } @@ -197,74 +197,74 @@ func (L *State) pcall(nargs, nresults, errfunc int) int { // Pushes on the stack the value of a global variable (lua_getglobal) func (L *State) GetGlobal(name string) { L.GetField(LUA_GLOBALSINDEX, name) } -// lua_resume -/* - * [-?, +?, -] - * Starts and resumes a coroutine in a given thread. - */ +// [lua_resume] -> [-?, +?, -] +// +// Starts and resumes a coroutine in a given thread. +// +// [lua_resume]: https://www.lua.org/manual/5.1/manual.html#lua_resume func (L *State) Resume(narg int) int { return int(C.lua_resume(L.s, C.int(narg))) } -// lua_setglobal -/* - * [-1, +0, e] - * Pops a value from the stack and sets it as the new value of global name. It is defined as a macro: - */ +// [lua_setglobal] -> [-1, +0, e] +// +// Pops a value from the stack and sets it as the new value of global name. It is defined as a macro: +// +// [lua_setglobal]: https://www.lua.org/manual/5.1/manual.html#lua_setglobal func (L *State) SetGlobal(name string) { Cname := C.CString(name) defer C.free(unsafe.Pointer(Cname)) C.lua_setfield(L.s, C.int(LUA_GLOBALSINDEX), Cname) } -// lua_insert -/* - * [-1, +1, -] - * Moves the top element into the given valid index, shifting up the elements above this index to open space. Cannot be called with a pseudo-index, because a pseudo-index is not an actual stack position. - */ +// [lua_insert] -> [-1, +1, -] +// +// Moves the top element into the given valid index, shifting up the elements above this index to open space. Cannot be called with a pseudo-index, because a pseudo-index is not an actual stack position. +// +// [lua_insert]: https://www.lua.org/manual/5.1/manual.html#lua_insert func (L *State) Insert(index int) { C.lua_insert(L.s, C.int(index)) } -// lua_remove -/* - * [-1, +0, -] - * Removes the element at the given valid index, shifting down the elements above this index to fill the gap. Cannot be called with a pseudo-index, because a pseudo-index is not an actual stack position. - */ +// [lua_remove] -> [-1, +0, -] +// +// Removes the element at the given valid index, shifting down the elements above this index to fill the gap. Cannot be called with a pseudo-index, because a pseudo-index is not an actual stack position. +// +// [lua_remove]: https://www.lua.org/manual/5.1/manual.html#lua_remove func (L *State) Remove(index int) { C.lua_remove(L.s, C.int(index)) } -// lua_replace -/* - * [-1, +0, -] - * Moves the top element into the given position (and pops it), without shifting any element (therefore replacing the value at the given position). - */ +// [lua_replace] -> [-1, +0, -] +// +// Moves the top element into the given position (and pops it), without shifting any element (therefore replacing the value at the given position). +// +// [lua_replace]: https://www.lua.org/manual/5.1/manual.html#lua_replace func (L *State) Replace(index int) { C.lua_replace(L.s, C.int(index)) } -// lua_rawgeti -/* - * [-0, +1, -] - * Pushes onto the stack the value t[n], where t is the value at the given valid index. The access is raw; that is, it does not invoke metamethods. - */ +// [lua_rawgeti] -> [-0, +1, -] +// +// Pushes onto the stack the value t[n], where t is the value at the given valid index. The access is raw; that is, it does not invoke metamethods. +// +// [lua_rawgeti]: https://www.lua.org/manual/5.1/manual.html#lua_rawgeti func (L *State) RawGeti(index int, n int) { C.lua_rawgeti(L.s, C.int(index), C.int(n)) } -// lua_rawseti -/* - * [-1, +0, m] - * Does the equivalent of t[n] = v, where t is the value at the given valid index and v is the value at the top of the stack. - */ +// [lua_rawseti] -> [-1, +0, m] +// +// Does the equivalent of t[n] = v, where t is the value at the given valid index and v is the value at the top of the stack. +// +// [lua_rawseti]: https://www.lua.org/manual/5.1/manual.html#lua_rawseti func (L *State) RawSeti(index int, n int) { C.lua_rawseti(L.s, C.int(index), C.int(n)) } -// lua_gc -/* - * [-0, +0, e] - * Controls the garbage collector. - */ +// [lua_gc] -> [-0, +0, e] +// +// Controls the garbage collector. +// +// [lua_gc]: https://www.lua.org/manual/5.1/manual.html#lua_gc func (L *State) GC(what, data int) int { return int(C.lua_gc(L.s, C.int(what), C.int(data))) } diff --git a/lua/golua_c_lua52.go b/lua/golua_c_lua52.go index 17b93b2..87b10e3 100644 --- a/lua/golua_c_lua52.go +++ b/lua/golua_c_lua52.go @@ -149,29 +149,29 @@ func (L *State) ObjLen(index int) uint { return uint(C.lua_rawlen(L.s, C.int(index))) } -// lua_tointeger -/* - * [-0, +0, –] - * Equivalent to lua_tointegerx with isnum equal to NULL. - */ +// [lua_tointeger] -> [-0, +0, –] +// +// Equivalent to lua_tointegerx with isnum equal to NULL. +// +// [lua_tointeger]: https://www.lua.org/manual/5.2/manual.html#lua_tointeger func (L *State) ToInteger(index int) int { return int(C.lua_tointegerx(L.s, C.int(index), nil)) } -// lua_tonumber -/* - * [-0, +0, –] - * Equivalent to lua_tonumberx with isnum equal to NULL. - */ +// [lua_tonumber] -> [-0, +0, –] +// +// Equivalent to lua_tonumberx with isnum equal to NULL. +// +// [lua_tonumber]: https://www.lua.org/manual/5.2/manual.html#lua_tonumber func (L *State) ToNumber(index int) float64 { return float64(C.lua_tonumberx(L.s, C.int(index), nil)) } -// lua_yield -/* - * [-?, +?, –] - * This function is equivalent to lua_yieldk, but it has no continuation (see §4.7). Therefore, when the thread resumes, it returns to the function that called the function calling lua_yield. - */ +// [lua_yield] -> [-?, +?, –] +// +// This function is equivalent to lua_yieldk, but it has no continuation (see §4.7). Therefore, when the thread resumes, it returns to the function that called the function calling lua_yield. +// +// [lua_yield]: https://www.lua.org/manual/5.2/manual.html#lua_yield func (L *State) Yield(nresults int) int { return int(C.lua_yieldk(L.s, C.int(nresults), 0, nil)) } @@ -187,20 +187,20 @@ func (L *State) GetGlobal(name string) { C.lua_getglobal(L.s, Ck) } -// lua_resume -/* - * [-?, +?, –] - * Starts and resumes a coroutine in a given thread. - */ +// [lua_resume] -> [-?, +?, –] +// +// Starts and resumes a coroutine in a given thread. +// +// [lua_resume]: https://www.lua.org/manual/5.2/manual.html#lua_resume func (L *State) Resume(narg int) int { return int(C.lua_resume(L.s, nil, C.int(narg))) } -// lua_setglobal -/* - * [-1, +0, e] - * Pops a value from the stack and sets it as the new value of global name. - */ +// [lua_setglobal] -> [-1, +0, e] +// +// Pops a value from the stack and sets it as the new value of global name. +// +// [lua_setglobal]: https://www.lua.org/manual/5.2/manual.html#lua_setglobal func (L *State) SetGlobal(name string) { Cname := C.CString(name) defer C.free(unsafe.Pointer(Cname)) @@ -222,54 +222,54 @@ func (L *State) OpenCoroutine() { C.clua_opencoroutine(L.s) } -// lua_insert -/* - * [-1, +1, –] - * Moves the top element into the given valid index, shifting up the elements above this index to open space. This function cannot be called with a pseudo-index, because a pseudo-index is not an actual stack position. - */ +// [lua_insert] -> [-1, +1, –] +// +// Moves the top element into the given valid index, shifting up the elements above this index to open space. This function cannot be called with a pseudo-index, because a pseudo-index is not an actual stack position. +// +// [lua_insert]: https://www.lua.org/manual/5.2/manual.html#lua_insert func (L *State) Insert(index int) { C.lua_insert(L.s, C.int(index)) } -// lua_remove -/* - * [-1, +0, –] - * Removes the element at the given valid index, shifting down the elements above this index to fill the gap. This function cannot be called with a pseudo-index, because a pseudo-index is not an actual stack position. - */ +// [lua_remove] -> [-1, +0, –] +// +// Removes the element at the given valid index, shifting down the elements above this index to fill the gap. This function cannot be called with a pseudo-index, because a pseudo-index is not an actual stack position. +// +// [lua_remove]: https://www.lua.org/manual/5.2/manual.html#lua_remove func (L *State) Remove(index int) { C.lua_remove(L.s, C.int(index)) } -// lua_replace -/* - * [-1, +0, –] - * Moves the top element into the given valid index without shifting any element (therefore replacing the value at the given index), and then pops the top element. - */ +// [lua_replace] -> [-1, +0, –] +// +// Moves the top element into the given valid index without shifting any element (therefore replacing the value at the given index), and then pops the top element. +// +// [lua_replace]: https://www.lua.org/manual/5.2/manual.html#lua_replace func (L *State) Replace(index int) { C.lua_replace(L.s, C.int(index)) } -// lua_rawgeti -/* - * [-0, +1, –] - * Pushes onto the stack the value t[n], where t is the table at the given index. The access is raw; that is, it does not invoke metamethods. - */ +// [lua_rawgeti] -> [-0, +1, –] +// +// Pushes onto the stack the value t[n], where t is the table at the given index. The access is raw; that is, it does not invoke metamethods. +// +// [lua_rawgeti]: https://www.lua.org/manual/5.2/manual.html#lua_rawgeti func (L *State) RawGeti(index int, n int) { C.lua_rawgeti(L.s, C.int(index), C.int(n)) } -// lua_rawseti -/* - * [-1, +0, e] - * Does the equivalent of t[n] = v, where t is the table at the given index and v is the value at the top of the stack. - */ +// [lua_rawseti] -> [-1, +0, e] +// +// Does the equivalent of t[n] = v, where t is the table at the given index and v is the value at the top of the stack. +// +// [lua_rawseti]: https://www.lua.org/manual/5.2/manual.html#lua_rawseti func (L *State) RawSeti(index int, n int) { C.lua_rawseti(L.s, C.int(index), C.int(n)) } -// lua_gc -/* - * [-0, +0, e] - * Controls the garbage collector. - */ +// [lua_gc] -> [-0, +0, e] +// +// Controls the garbage collector. +// +// [lua_gc]: https://www.lua.org/manual/5.2/manual.html#lua_gc func (L *State) GC(what, data int) int { return int(C.lua_gc(L.s, C.int(what), C.int(data))) } diff --git a/lua/golua_c_lua53.go b/lua/golua_c_lua53.go index 993f97d..3b5ec18 100644 --- a/lua/golua_c_lua53.go +++ b/lua/golua_c_lua53.go @@ -149,29 +149,29 @@ func (L *State) ObjLen(index int) uint { return uint(C.lua_rawlen(L.s, C.int(index))) } -// lua_tointeger -/* - * [-0, +0, –] - * Equivalent to lua_tointegerx with isnum equal to NULL. - */ +// [lua_tointeger] -> [-0, +0, –] +// +// Equivalent to lua_tointegerx with isnum equal to NULL. +// +// [lua_tointeger]: https://www.lua.org/manual/5.3/manual.html#lua_tointeger func (L *State) ToInteger(index int) int { return int(C.lua_tointegerx(L.s, C.int(index), nil)) } -// lua_tonumber -/* - * [-0, +0, –] - * Equivalent to lua_tonumberx with isnum equal to NULL. - */ +// [lua_tonumber] -> [-0, +0, –] +// +// Equivalent to lua_tonumberx with isnum equal to NULL. +// +// [lua_tonumber]: https://www.lua.org/manual/5.3/manual.html#lua_tonumber func (L *State) ToNumber(index int) float64 { return float64(C.lua_tonumberx(L.s, C.int(index), nil)) } -// lua_yield -/* - * [-?, +?, e] - * This function is equivalent to lua_yieldk, but it has no continuation (see §4.7). Therefore, when the thread resumes, it continues the function that called the function calling lua_yield. - */ +// [lua_yield] -> [-?, +?, e] +// +// This function is equivalent to lua_yieldk, but it has no continuation (see §4.7). Therefore, when the thread resumes, it continues the function that called the function calling lua_yield. +// +// [lua_yield]: https://www.lua.org/manual/5.3/manual.html#lua_yield func (L *State) Yield(nresults int) int { return int(C.lua_yieldk(L.s, C.int(nresults), 0, nil)) } @@ -187,20 +187,20 @@ func (L *State) GetGlobal(name string) { C.lua_getglobal(L.s, Ck) } -// lua_resume -/* - * [-?, +?, –] - * Starts and resumes a coroutine in the given thread L. - */ +// [lua_resume] -> [-?, +?, –] +// +// Starts and resumes a coroutine in the given thread L. +// +// [lua_resume]: https://www.lua.org/manual/5.3/manual.html#lua_resume func (L *State) Resume(narg int) int { return int(C.lua_resume(L.s, nil, C.int(narg))) } -// lua_setglobal -/* - * [-1, +0, e] - * Pops a value from the stack and sets it as the new value of global name. - */ +// [lua_setglobal] -> [-1, +0, e] +// +// Pops a value from the stack and sets it as the new value of global name. +// +// [lua_setglobal]: https://www.lua.org/manual/5.3/manual.html#lua_setglobal func (L *State) SetGlobal(name string) { Cname := C.CString(name) defer C.free(unsafe.Pointer(Cname)) @@ -222,56 +222,56 @@ func (L *State) OpenCoroutine() { C.clua_opencoroutine(L.s) } -// lua_insert -/* - * [-1, +1, –] - * Moves the top element into the given valid index, shifting up the elements above this index to open space. This function cannot be called with a pseudo-index, because a pseudo-index is not an actual stack position. - */ +// [lua_insert] -> [-1, +1, –] +// +// Moves the top element into the given valid index, shifting up the elements above this index to open space. This function cannot be called with a pseudo-index, because a pseudo-index is not an actual stack position. +// +// [lua_insert]: https://www.lua.org/manual/5.3/manual.html#lua_insert func (L *State) Insert(index int) { C.lua_rotate(L.s, C.int(index), 1) } -// lua_remove -/* - * [-1, +0, –] - * Removes the element at the given valid index, shifting down the elements above this index to fill the gap. This function cannot be called with a pseudo-index, because a pseudo-index is not an actual stack position. - */ +// [lua_remove] -> [-1, +0, –] +// +// Removes the element at the given valid index, shifting down the elements above this index to fill the gap. This function cannot be called with a pseudo-index, because a pseudo-index is not an actual stack position. +// +// [lua_remove]: https://www.lua.org/manual/5.3/manual.html#lua_remove func (L *State) Remove(index int) { C.lua_rotate(L.s, C.int(index), -1) C.lua_settop(L.s, C.int(-2)) } -// lua_replace -/* - * [-1, +0, –] - * Moves the top element into the given valid index without shifting any element (therefore replacing the value at that given index), and then pops the top element. - */ +// [lua_replace] -> [-1, +0, –] +// +// Moves the top element into the given valid index without shifting any element (therefore replacing the value at that given index), and then pops the top element. +// +// [lua_replace]: https://www.lua.org/manual/5.3/manual.html#lua_replace func (L *State) Replace(index int) { C.lua_copy(L.s, -1, C.int(index)) C.lua_settop(L.s, -2) } -// lua_rawgeti -/* - * [-0, +1, –] - * Pushes onto the stack the value t[n], where t is the table at the given index. The access is raw, that is, it does not invoke the __index metamethod. - */ +// [lua_rawgeti] -> [-0, +1, –] +// +// Pushes onto the stack the value t[n], where t is the table at the given index. The access is raw, that is, it does not invoke the __index metamethod. +// +// [lua_rawgeti]: https://www.lua.org/manual/5.3/manual.html#lua_rawgeti func (L *State) RawGeti(index int, n int) { C.lua_rawgeti(L.s, C.int(index), C.longlong(n)) } -// lua_rawseti -/* - * [-1, +0, m] - * Does the equivalent of t[i] = v, where t is the table at the given index and v is the value at the top of the stack. - */ +// [lua_rawseti] -> [-1, +0, m] +// +// Does the equivalent of t[i] = v, where t is the table at the given index and v is the value at the top of the stack. +// +// [lua_rawseti]: https://www.lua.org/manual/5.3/manual.html#lua_rawseti func (L *State) RawSeti(index int, n int) { C.lua_rawseti(L.s, C.int(index), C.longlong(n)) } -// lua_gc -/* - * [-0, +0, m] - * Controls the garbage collector. - */ +// [lua_gc] -> [-0, +0, m] +// +// Controls the garbage collector. +// +// [lua_gc]: https://www.lua.org/manual/5.3/manual.html#lua_gc func (L *State) GC(what, data int) int { return int(C.lua_gc(L.s, C.int(what), C.int(data))) } diff --git a/lua/golua_c_lua54.go b/lua/golua_c_lua54.go index 10f4fec..f39aae2 100644 --- a/lua/golua_c_lua54.go +++ b/lua/golua_c_lua54.go @@ -151,29 +151,29 @@ func (L *State) ObjLen(index int) uint { return uint(C.lua_rawlen(L.s, C.int(index))) } -// lua_tointeger -/* - * [-0, +0, –] - * Equivalent to lua_tointegerx with isnum equal to NULL. - */ +// [lua_tointeger] -> [-0, +0, –] +// +// Equivalent to lua_tointegerx with isnum equal to NULL. +// +// [lua_tointeger]: https://www.lua.org/manual/5.4/manual.html#lua_tointeger func (L *State) ToInteger(index int) int { return int(C.lua_tointegerx(L.s, C.int(index), nil)) } -// lua_tonumber -/* - * [-0, +0, –] - * Equivalent to lua_tonumberx with isnum equal to NULL. - */ +// [lua_tonumber] -> [-0, +0, –] +// +// Equivalent to lua_tonumberx with isnum equal to NULL. +// +// [lua_tonumber]: https://www.lua.org/manual/5.4/manual.html#lua_tonumber func (L *State) ToNumber(index int) float64 { return float64(C.lua_tonumberx(L.s, C.int(index), nil)) } -// lua_yield -/* - * [-?, +?, v] - * This function is equivalent to lua_yieldk, but it has no continuation (see §4.5). Therefore, when the thread resumes, it continues the function that called the function calling lua_yield. To avoid surprises, this function should be called only in a tail call. - */ +// [lua_yield] -> [-?, +?, v] +// +// This function is equivalent to lua_yieldk, but it has no continuation (see §4.5). Therefore, when the thread resumes, it continues the function that called the function calling lua_yield. To avoid surprises, this function should be called only in a tail call. +// +// [lua_yield]: https://www.lua.org/manual/5.4/manual.html#lua_yield func (L *State) Yield(nresults int) int { return int(C.lua_yieldk(L.s, C.int(nresults), 0, nil)) } @@ -189,20 +189,20 @@ func (L *State) GetGlobal(name string) { C.lua_getglobal(L.s, Ck) } -// lua_resume -/* - * [-?, +?, –] - * Starts and resumes a coroutine in the given thread L. - */ +// [lua_resume] -> [-?, +?, –] +// +// Starts and resumes a coroutine in the given thread L. +// +// [lua_resume]: https://www.lua.org/manual/5.4/manual.html#lua_resume func (L *State) Resume(narg int) int { return int(C.lua_resume(L.s, nil, C.int(narg), nil)) } -// lua_setglobal -/* - * [-1, +0, e] - * Pops a value from the stack and sets it as the new value of global name. - */ +// [lua_setglobal] -> [-1, +0, e] +// +// Pops a value from the stack and sets it as the new value of global name. +// +// [lua_setglobal]: https://www.lua.org/manual/5.4/manual.html#lua_setglobal func (L *State) SetGlobal(name string) { Cname := C.CString(name) defer C.free(unsafe.Pointer(Cname)) @@ -219,56 +219,56 @@ func (L *State) OpenCoroutine() { C.clua_opencoroutine(L.s) } -// lua_insert -/* - * [-1, +1, –] - * Moves the top element into the given valid index, shifting up the elements above this index to open space. This function cannot be called with a pseudo-index, because a pseudo-index is not an actual stack position. - */ +// [lua_insert] -> [-1, +1, –] +// +// Moves the top element into the given valid index, shifting up the elements above this index to open space. This function cannot be called with a pseudo-index, because a pseudo-index is not an actual stack position. +// +// [lua_insert]: https://www.lua.org/manual/5.4/manual.html#lua_insert func (L *State) Insert(index int) { C.lua_rotate(L.s, C.int(index), 1) } -// lua_remove -/* - * [-1, +0, –] - * Removes the element at the given valid index, shifting down the elements above this index to fill the gap. This function cannot be called with a pseudo-index, because a pseudo-index is not an actual stack position. - */ +// [lua_remove] -> [-1, +0, –] +// +// Removes the element at the given valid index, shifting down the elements above this index to fill the gap. This function cannot be called with a pseudo-index, because a pseudo-index is not an actual stack position. +// +// [lua_remove]: https://www.lua.org/manual/5.4/manual.html#lua_remove func (L *State) Remove(index int) { C.lua_rotate(L.s, C.int(index), -1) C.lua_settop(L.s, C.int(-2)) } -// lua_replace -/* - * [-1, +0, –] - * Moves the top element into the given valid index without shifting any element (therefore replacing the value at that given index), and then pops the top element. - */ +// [lua_replace] -> [-1, +0, –] +// +// Moves the top element into the given valid index without shifting any element (therefore replacing the value at that given index), and then pops the top element. +// +// [lua_replace]: https://www.lua.org/manual/5.4/manual.html#lua_replace func (L *State) Replace(index int) { C.lua_copy(L.s, -1, C.int(index)) C.lua_settop(L.s, -2) } -// lua_rawgeti -/* - * [-0, +1, –] - * Pushes onto the stack the value t[n], where t is the table at the given index. The access is raw, that is, it does not use the __index metavalue. - */ +// [lua_rawgeti] -> [-0, +1, –] +// +// Pushes onto the stack the value t[n], where t is the table at the given index. The access is raw, that is, it does not use the __index metavalue. +// +// [lua_rawgeti]: https://www.lua.org/manual/5.4/manual.html#lua_rawgeti func (L *State) RawGeti(index int, n int) { C.lua_rawgeti(L.s, C.int(index), C.longlong(n)) } -// lua_rawseti -/* - * [-1, +0, m] - * Does the equivalent of t[i] = v, where t is the table at the given index and v is the value on the top of the stack. - */ +// [lua_rawseti] -> [-1, +0, m] +// +// Does the equivalent of t[i] = v, where t is the table at the given index and v is the value on the top of the stack. +// +// [lua_rawseti]: https://www.lua.org/manual/5.4/manual.html#lua_rawseti func (L *State) RawSeti(index int, n int) { C.lua_rawseti(L.s, C.int(index), C.longlong(n)) } -// lua_gc -/* - * [-0, +0, –] - * Controls the garbage collector. - */ +// [lua_gc] -> [-0, +0, –] +// +// Controls the garbage collector. +// +// [lua_gc]: https://www.lua.org/manual/5.4/manual.html#lua_gc func (L *State) GC(what, data int) int { return int(C.lua_gc_compat(L.s, C.int(what), C.int(data))) } diff --git a/lua/lauxlib.go b/lua/lauxlib.go index 282187f..25b0d31 100644 --- a/lua/lauxlib.go +++ b/lua/lauxlib.go @@ -30,7 +30,11 @@ func (err *LuaError) StackTrace() []LuaStackEntry { return err.stackTrace } -// luaL_argcheck +// [luaL_argcheck] -> [-0, +0, v] +// +// Checks whether cond is true. If not, raises an error with the following message, where func is retrieved from the call stack: +// +// [luaL_argcheck]: https://www.lua.org/manual/5.1/manual.html#lual_argcheck // WARNING: before b30b2c62c6712c6683a9d22ff0abfa54c8267863 the function ArgCheck had the opposite behaviour func (L *State) Argcheck(cond bool, narg int, extramsg string) { if !cond { @@ -40,42 +44,70 @@ func (L *State) Argcheck(cond bool, narg int, extramsg string) { } } -// luaL_argerror +// [luaL_argerror] -> [-0, +0, v] +// +// Raises an error with the following message, where func is retrieved from the call stack: +// +// [luaL_argerror]: https://www.lua.org/manual/5.1/manual.html#lual_argerror func (L *State) ArgError(narg int, extramsg string) int { Cextramsg := C.CString(extramsg) defer C.free(unsafe.Pointer(Cextramsg)) return int(C.luaL_argerror(L.s, C.int(narg), Cextramsg)) } -// luaL_callmeta +// [luaL_callmeta] -> [-0, +(0|1), e] +// +// Calls a metamethod. +// +// [luaL_callmeta]: https://www.lua.org/manual/5.1/manual.html#lual_callmeta func (L *State) CallMeta(obj int, e string) int { Ce := C.CString(e) defer C.free(unsafe.Pointer(Ce)) return int(C.luaL_callmeta(L.s, C.int(obj), Ce)) } -// luaL_checkany +// [luaL_checkany] -> [-0, +0, v] +// +// Checks whether the function has an argument of any type (including nil) at position narg. +// +// [luaL_checkany]: https://www.lua.org/manual/5.1/manual.html#lual_checkany func (L *State) CheckAny(narg int) { C.luaL_checkany(L.s, C.int(narg)) } -// luaL_checkinteger +// [luaL_checkinteger] -> [-0, +0, v] +// +// Checks whether the function argument narg is a number and returns this number cast to a lua_Integer. +// +// [luaL_checkinteger]: https://www.lua.org/manual/5.1/manual.html#lual_checkinteger func (L *State) CheckInteger(narg int) int { return int(C.luaL_checkinteger(L.s, C.int(narg))) } -// luaL_checknumber +// [luaL_checknumber] -> [-0, +0, v] +// +// Checks whether the function argument narg is a number and returns this number. +// +// [luaL_checknumber]: https://www.lua.org/manual/5.1/manual.html#lual_checknumber func (L *State) CheckNumber(narg int) float64 { return float64(C.luaL_checknumber(L.s, C.int(narg))) } -// luaL_checkstring +// [luaL_checkstring] -> [-0, +0, v] +// +// Checks whether the function argument narg is a string and returns this string. +// +// [luaL_checkstring]: https://www.lua.org/manual/5.1/manual.html#lual_checkstring func (L *State) CheckString(narg int) string { var length C.size_t return C.GoString(C.luaL_checklstring(L.s, C.int(narg), &length)) } -// luaL_checkoption +// [luaL_checkoption] -> [-0, +0, v] +// +// Checks whether the function argument narg is a string and searches for this string in the array lst (which must be NULL-terminated). Returns the index in the array where the string was found. Raises an error if the argument is not a string or if the string cannot be found. +// +// [luaL_checkoption]: https://www.lua.org/manual/5.1/manual.html#lual_checkoption // // BUG(everyone_involved): not implemented func (L *State) CheckOption(narg int, def string, lst []string) int { @@ -83,12 +115,20 @@ func (L *State) CheckOption(narg int, def string, lst []string) int { return 0 } -// luaL_checktype +// [luaL_checktype] -> [-0, +0, v] +// +// Checks whether the function argument narg has type t. See lua_type for the encoding of types for t. +// +// [luaL_checktype]: https://www.lua.org/manual/5.1/manual.html#lual_checktype func (L *State) CheckType(narg int, t LuaValType) { C.luaL_checktype(L.s, C.int(narg), C.int(t)) } -// luaL_checkudata +// [luaL_checkudata] -> [-0, +0, v] +// +// Checks whether the function argument narg is a userdata of the type tname (see luaL_newmetatable). +// +// [luaL_checkudata]: https://www.lua.org/manual/5.1/manual.html#lual_checkudata func (L *State) CheckUdata(narg int, tname string) unsafe.Pointer { Ctname := C.CString(tname) defer C.free(unsafe.Pointer(Ctname)) @@ -118,21 +158,33 @@ func (L *State) MustDoString(str string) { } } -// luaL_getmetafield +// [luaL_getmetafield] -> [-0, +(0|1), m] +// +// Pushes onto the stack the field e from the metatable of the object at index obj. If the object does not have a metatable, or if the metatable does not have this field, returns 0 and pushes nothing. +// +// [luaL_getmetafield]: https://www.lua.org/manual/5.1/manual.html#lual_getmetafield func (L *State) GetMetaField(obj int, e string) bool { Ce := C.CString(e) defer C.free(unsafe.Pointer(Ce)) return C.luaL_getmetafield(L.s, C.int(obj), Ce) != 0 } -// luaL_getmetatable +// [luaL_getmetatable] -> [-0, +1, -] +// +// Pushes onto the stack the metatable associated with name tname in the registry (see luaL_newmetatable). +// +// [luaL_getmetatable]: https://www.lua.org/manual/5.1/manual.html#lual_getmetatable func (L *State) LGetMetaTable(tname string) { Ctname := C.CString(tname) defer C.free(unsafe.Pointer(Ctname)) C.lua_getfield(L.s, LUA_REGISTRYINDEX, Ctname) } -// luaL_gsub +// [luaL_gsub] -> [-0, +1, m] +// +// Creates a copy of string s by replacing any occurrence of the string p with the string r. Pushes the resulting string on the stack and returns it. +// +// [luaL_gsub]: https://www.lua.org/manual/5.1/manual.html#lual_gsub func (L *State) GSub(s string, p string, r string) string { Cs := C.CString(s) Cp := C.CString(p) @@ -146,27 +198,43 @@ func (L *State) GSub(s string, p string, r string) string { return C.GoString(C.luaL_gsub(L.s, Cs, Cp, Cr)) } -// luaL_loadfile +// [luaL_loadfile] -> [-0, +1, m] +// +// Loads a file as a Lua chunk. This function uses lua_load to load the chunk in the file named filename. If filename is NULL, then it loads from the standard input. The first line in the file is ignored if it starts with a #. +// +// [luaL_loadfile]: https://www.lua.org/manual/5.1/manual.html#lual_loadfile func (L *State) LoadFile(filename string) int { Cfilename := C.CString(filename) defer C.free(unsafe.Pointer(Cfilename)) return int(lualLoadFile(L.s, Cfilename)) } -// luaL_loadstring +// [luaL_loadstring] -> [-0, +1, m] +// +// Loads a string as a Lua chunk. This function uses lua_load to load the chunk in the zero-terminated string s. +// +// [luaL_loadstring]: https://www.lua.org/manual/5.1/manual.html#lual_loadstring func (L *State) LoadString(s string) int { Cs := C.CString(s) defer C.free(unsafe.Pointer(Cs)) return int(C.luaL_loadstring(L.s, Cs)) } -// lua_dump +// [lua_dump] -> [-0, +0, m] +// +// Dumps a function as a binary chunk. Receives a Lua function on the top of the stack and produces a binary chunk that, if loaded again, results in a function equivalent to the one dumped. As it produces parts of the chunk, lua_dump calls function writer (see lua_Writer) with the given data to write them. +// +// [lua_dump]: https://www.lua.org/manual/5.1/manual.html#lua_dump func (L *State) Dump() int { ret := int(C.dump_chunk(L.s)) return ret } -// lua_load +// [lua_load] -> [-0, +1, -] +// +// Loads a Lua chunk. If there are no errors, lua_load pushes the compiled chunk as a Lua function on top of the stack. Otherwise, it pushes an error message. The return values of lua_load are: +// +// [lua_load]: https://www.lua.org/manual/5.1/manual.html#lua_load func (L *State) Load(bs []byte, name string) int { chunk := C.CString(string(bs)) ckname := C.CString(name) @@ -179,14 +247,22 @@ func (L *State) Load(bs []byte, name string) int { return 0 } -// luaL_newmetatable +// [luaL_newmetatable] -> [-0, +1, m] +// +// If the registry already has the key tname, returns 0. Otherwise, creates a new table to be used as a metatable for userdata, adds it to the registry with key tname, and returns 1. +// +// [luaL_newmetatable]: https://www.lua.org/manual/5.1/manual.html#lual_newmetatable func (L *State) NewMetaTable(tname string) bool { Ctname := C.CString(tname) defer C.free(unsafe.Pointer(Ctname)) return C.luaL_newmetatable(L.s, Ctname) != 0 } -// luaL_newstate +// [luaL_newstate] -> [-0, +0, -] +// +// Creates a new Lua state. It calls lua_newstate with an allocator based on the standard C realloc function and then sets a panic function (see lua_atpanic) that prints an error message to the standard error output in case of fatal errors. +// +// [luaL_newstate]: https://www.lua.org/manual/5.1/manual.html#lual_newstate func NewState() *State { ls := (C.luaL_newstate()) if ls == nil { @@ -206,23 +282,39 @@ func (L *State) Context() context.Context { return L.ctx } -// luaL_openlibs +// [luaL_openlibs] -> [-0, +0, m] +// +// Opens all standard Lua libraries into the given state. +// +// [luaL_openlibs]: https://www.lua.org/manual/5.1/manual.html#lual_openlibs func (L *State) OpenLibs() { C.luaL_openlibs(L.s) C.clua_hide_pcall(L.s) } -// luaL_optinteger +// [luaL_optinteger] -> [-0, +0, v] +// +// If the function argument narg is a number, returns this number cast to a lua_Integer. If this argument is absent or is nil, returns d. Otherwise, raises an error. +// +// [luaL_optinteger]: https://www.lua.org/manual/5.1/manual.html#lual_optinteger func (L *State) OptInteger(narg int, d int) int { return int(C.luaL_optinteger(L.s, C.int(narg), C.lua_Integer(d))) } -// luaL_optnumber +// [luaL_optnumber] -> [-0, +0, v] +// +// If the function argument narg is a number, returns this number. If this argument is absent or is nil, returns d. Otherwise, raises an error. +// +// [luaL_optnumber]: https://www.lua.org/manual/5.1/manual.html#lual_optnumber func (L *State) OptNumber(narg int, d float64) float64 { return float64(C.luaL_optnumber(L.s, C.int(narg), C.lua_Number(d))) } -// luaL_optstring +// [luaL_optstring] -> [-0, +0, v] +// +// If the function argument narg is a string, returns this string. If this argument is absent or is nil, returns d. Otherwise, raises an error. +// +// [luaL_optstring]: https://www.lua.org/manual/5.1/manual.html#lual_optstring func (L *State) OptString(narg int, d string) string { var length C.size_t Cd := C.CString(d) @@ -230,22 +322,38 @@ func (L *State) OptString(narg int, d string) string { return C.GoString(C.luaL_optlstring(L.s, C.int(narg), Cd, &length)) } -// luaL_ref +// [luaL_ref] -> [-1, +0, m] +// +// Creates and returns a reference, in the table at index t, for the object at the top of the stack (and pops the object). +// +// [luaL_ref]: https://www.lua.org/manual/5.1/manual.html#lual_ref func (L *State) Ref(t int) int { return int(C.luaL_ref(L.s, C.int(t))) } -// luaL_typename +// [luaL_typename] -> [-0, +0, -] +// +// Returns the name of the type of the value at the given index. +// +// [luaL_typename]: https://www.lua.org/manual/5.1/manual.html#lual_typename func (L *State) LTypename(index int) string { return C.GoString(C.lua_typename(L.s, C.lua_type(L.s, C.int(index)))) } -// luaL_unref +// [luaL_unref] -> [-0, +0, -] +// +// Releases reference ref from the table at index t (see luaL_ref). The entry is removed from the table, so that the referred object can be collected. The reference ref is also freed to be used again. +// +// [luaL_unref]: https://www.lua.org/manual/5.1/manual.html#lual_unref func (L *State) Unref(t int, ref int) { C.luaL_unref(L.s, C.int(t), C.int(ref)) } -// luaL_where +// [luaL_where] -> [-0, +1, m] +// +// Pushes onto the stack a string identifying the current position of the control at level lvl in the call stack. Typically this string has the following format: +// +// [luaL_where]: https://www.lua.org/manual/5.1/manual.html#lual_where func (L *State) Where(lvl int) { C.luaL_where(L.s, C.int(lvl)) } diff --git a/lua/lua.go b/lua/lua.go index dc273be..0762ba6 100644 --- a/lua/lua.go +++ b/lua/lua.go @@ -156,25 +156,25 @@ func (L *State) PushGoClosureWithUpvalues(f LuaGoFunction, nup uint) { C.clua_pushcallback(L.s, C.uint(nup)) // wraps the userdata object with a closure making it into a function } -// lua_upvalueid +// lua_upvalueindex func (L *State) UpvalueIndex(n int) int { return int(C.clua_upvalueindex(C.int32_t(n))) } -// lua_setupvalue -/* - * [-(0|1), +0, -] - * Sets the value of a closure's upvalue. It assigns the value at the top of the stack to the upvalue and returns its name. It also pops the value from the stack. Parameters funcindex and n are as in the lua_getupvalue (see lua_getupvalue). - */ +// [lua_setupvalue] -> [-(0|1), +0, -] +// +// Sets the value of a closure's upvalue. It assigns the value at the top of the stack to the upvalue and returns its name. It also pops the value from the stack. Parameters funcindex and n are as in the lua_getupvalue (see lua_getupvalue). +// +// [lua_setupvalue]: https://www.lua.org/manual/5.1/manual.html#lua_setupvalue func (L *State) SetUpvalue(funcindex, n int) bool { return C.lua_setupvalue(L.s, C.int(funcindex), C.int(n)) != nil } -// lua_getupvalue -/* - * [-0, +(0|1), -] - * Gets information about a closure's upvalue. (For Lua functions, upvalues are the external local variables that the function uses, and that are consequently included in its closure.) lua_getupvalue gets the index n of an upvalue, pushes the upvalue's value onto the stack, and returns its name. funcindex points to the closure in the stack. (Upvalues have no particular order, as they are active through the whole function. So, they are numbered in an arbitrary order.) - */ +// [lua_getupvalue] -> [-0, +(0|1), -] +// +// Gets information about a closure's upvalue. (For Lua functions, upvalues are the external local variables that the function uses, and that are consequently included in its closure.) lua_getupvalue gets the index n of an upvalue, pushes the upvalue's value onto the stack, and returns its name. funcindex points to the closure in the stack. (Upvalues have no particular order, as they are active through the whole function. So, they are numbered in an arbitrary order.) +// +// [lua_getupvalue]: https://www.lua.org/manual/5.1/manual.html#lua_getupvalue func (L *State) GetUpvalue(funcindex, n int) { C.lua_getupvalue(L.s, C.int(funcindex), C.int(n)) } @@ -272,11 +272,11 @@ func (L *State) callEx(nargs, nresults int, catch bool) (err error) { return } -// lua_call -/* - * [-(nargs + 1), +nresults, e] - * Calls a function. - */ +// [lua_call] -> [-(nargs + 1), +nresults, e] +// +// Calls a function. +// +// [lua_call]: https://www.lua.org/manual/5.1/manual.html#lua_call func (L *State) Call(nargs, nresults int) (err error) { return L.callEx(nargs, nresults, true) } @@ -286,75 +286,75 @@ func (L *State) MustCall(nargs, nresults int) { L.callEx(nargs, nresults, false) } -// lua_checkstack -/* - * [-0, +0, m] - * Ensures that there are at least extra free stack slots in the stack. It returns false if it cannot grow the stack to that size. This function never shrinks the stack; if the stack is already larger than the new size, it is left unchanged. - */ +// [lua_checkstack] -> [-0, +0, m] +// +// Ensures that there are at least extra free stack slots in the stack. It returns false if it cannot grow the stack to that size. This function never shrinks the stack; if the stack is already larger than the new size, it is left unchanged. +// +// [lua_checkstack]: https://www.lua.org/manual/5.1/manual.html#lua_checkstack func (L *State) CheckStack(extra int) bool { return C.lua_checkstack(L.s, C.int(extra)) != 0 } -// lua_close -/* - * [-0, +0, -] - * Destroys all objects in the given Lua state (calling the corresponding garbage-collection metamethods, if any) and frees all dynamic memory used by this state. On several platforms, you may not need to call this function, because all resources are naturally released when the host program ends. On the other hand, long-running programs, such as a daemon or a web server, might need to release states as soon as they are not needed, to avoid growing too large. - */ +// [lua_close] -> [-0, +0, -] +// +// Destroys all objects in the given Lua state (calling the corresponding garbage-collection metamethods, if any) and frees all dynamic memory used by this state. On several platforms, you may not need to call this function, because all resources are naturally released when the host program ends. On the other hand, long-running programs, such as a daemon or a web server, might need to release states as soon as they are not needed, to avoid growing too large. +// +// [lua_close]: https://www.lua.org/manual/5.1/manual.html#lua_close func (L *State) Close() { C.lua_close(L.s) unregisterGoState(L) } -// lua_concat -/* - * [-n, +1, e] - * Concatenates the n values at the top of the stack, pops them, and leaves the result at the top. If n is 1, the result is the single value on the stack (that is, the function does nothing); if n is 0, the result is the empty string. Concatenation is performed following the usual semantics of Lua (see §2.5.4). - */ +// [lua_concat] -> [-n, +1, e] +// +// Concatenates the n values at the top of the stack, pops them, and leaves the result at the top. If n is 1, the result is the single value on the stack (that is, the function does nothing); if n is 0, the result is the empty string. Concatenation is performed following the usual semantics of Lua (see §2.5.4). +// +// [lua_concat]: https://www.lua.org/manual/5.1/manual.html#lua_concat func (L *State) Concat(n int) { C.lua_concat(L.s, C.int(n)) } -// lua_createtable -/* - * [-0, +1, m] - * Creates a new empty table and pushes it onto the stack. The new table has space pre-allocated for narr array elements and nrec non-array elements. This pre-allocation is useful when you know exactly how many elements the table will have. Otherwise you can use the function lua_newtable. - */ +// [lua_createtable] -> [-0, +1, m] +// +// Creates a new empty table and pushes it onto the stack. The new table has space pre-allocated for narr array elements and nrec non-array elements. This pre-allocation is useful when you know exactly how many elements the table will have. Otherwise you can use the function lua_newtable. +// +// [lua_createtable]: https://www.lua.org/manual/5.1/manual.html#lua_createtable func (L *State) CreateTable(narr int, nrec int) { C.lua_createtable(L.s, C.int(narr), C.int(nrec)) } -// lua_getfield -/* - * [-0, +1, e] - * Pushes onto the stack the value t[k], where t is the value at the given valid index. As in Lua, this function may trigger a metamethod for the "index" event (see §2.8). - */ +// [lua_getfield] -> [-0, +1, e] +// +// Pushes onto the stack the value t[k], where t is the value at the given valid index. As in Lua, this function may trigger a metamethod for the "index" event (see §2.8). +// +// [lua_getfield]: https://www.lua.org/manual/5.1/manual.html#lua_getfield func (L *State) GetField(index int, k string) { Ck := C.CString(k) defer C.free(unsafe.Pointer(Ck)) C.lua_getfield(L.s, C.int(index), Ck) } -// lua_getmetatable -/* - * [-0, +(0|1), -] - * Pushes onto the stack the metatable of the value at the given acceptable index. If the index is not valid, or if the value does not have a metatable, the function returns 0 and pushes nothing on the stack. - */ +// [lua_getmetatable] -> [-0, +(0|1), -] +// +// Pushes onto the stack the metatable of the value at the given acceptable index. If the index is not valid, or if the value does not have a metatable, the function returns 0 and pushes nothing on the stack. +// +// [lua_getmetatable]: https://www.lua.org/manual/5.1/manual.html#lua_getmetatable func (L *State) GetMetaTable(index int) bool { return C.lua_getmetatable(L.s, C.int(index)) != 0 } -// lua_gettable -/* - * [-1, +1, e] - * Pushes onto the stack the value t[k], where t is the value at the given valid index and k is the value at the top of the stack. - */ +// [lua_gettable] -> [-1, +1, e] +// +// Pushes onto the stack the value t[k], where t is the value at the given valid index and k is the value at the top of the stack. +// +// [lua_gettable]: https://www.lua.org/manual/5.1/manual.html#lua_gettable func (L *State) GetTable(index int) { C.lua_gettable(L.s, C.int(index)) } -// lua_gettop -/* - * [-0, +0, -] - * Returns the index of the top element in the stack. Because indices start at 1, this result is equal to the number of elements in the stack (and so 0 means an empty stack). - */ +// [lua_gettop] -> [-0, +0, -] +// +// Returns the index of the top element in the stack. Because indices start at 1, this result is equal to the number of elements in the stack (and so 0 means an empty stack). +// +// [lua_gettop]: https://www.lua.org/manual/5.1/manual.html#lua_gettop func (L *State) GetTop() int { return int(C.lua_gettop(L.s)) } // Returns true if lua_type == LUA_TBOOLEAN @@ -382,64 +382,64 @@ func (L *State) IsLightUserdata(index int) bool { return LuaValType(C.lua_type(L.s, C.int(index))) == LUA_TLIGHTUSERDATA } -// lua_isnil -/* - * [-0, +0, -] - * Returns 1 if the value at the given acceptable index is nil, and 0 otherwise. - */ +// [lua_isnil] -> [-0, +0, -] +// +// Returns 1 if the value at the given acceptable index is nil, and 0 otherwise. +// +// [lua_isnil]: https://www.lua.org/manual/5.1/manual.html#lua_isnil func (L *State) IsNil(index int) bool { return LuaValType(C.lua_type(L.s, C.int(index))) == LUA_TNIL } -// lua_isnone -/* - * [-0, +0, -] - * Returns 1 if the given acceptable index is not valid (that is, it refers to an element outside the current stack), and 0 otherwise. - */ +// [lua_isnone] -> [-0, +0, -] +// +// Returns 1 if the given acceptable index is not valid (that is, it refers to an element outside the current stack), and 0 otherwise. +// +// [lua_isnone]: https://www.lua.org/manual/5.1/manual.html#lua_isnone func (L *State) IsNone(index int) bool { return LuaValType(C.lua_type(L.s, C.int(index))) == LUA_TNONE } -// lua_isnoneornil -/* - * [-0, +0, -] - * Returns 1 if the given acceptable index is not valid (that is, it refers to an element outside the current stack) or if the value at this index is nil, and 0 otherwise. - */ +// [lua_isnoneornil] -> [-0, +0, -] +// +// Returns 1 if the given acceptable index is not valid (that is, it refers to an element outside the current stack) or if the value at this index is nil, and 0 otherwise. +// +// [lua_isnoneornil]: https://www.lua.org/manual/5.1/manual.html#lua_isnoneornil func (L *State) IsNoneOrNil(index int) bool { return int(C.lua_type(L.s, C.int(index))) <= 0 } -// lua_isnumber -/* - * [-0, +0, -] - * Returns 1 if the value at the given acceptable index is a number or a string convertible to a number, and 0 otherwise. - */ +// [lua_isnumber] -> [-0, +0, -] +// +// Returns 1 if the value at the given acceptable index is a number or a string convertible to a number, and 0 otherwise. +// +// [lua_isnumber]: https://www.lua.org/manual/5.1/manual.html#lua_isnumber func (L *State) IsNumber(index int) bool { return C.lua_isnumber(L.s, C.int(index)) == 1 } -// lua_isstring -/* - * [-0, +0, -] - * Returns 1 if the value at the given acceptable index is a string or a number (which is always convertible to a string), and 0 otherwise. - */ +// [lua_isstring] -> [-0, +0, -] +// +// Returns 1 if the value at the given acceptable index is a string or a number (which is always convertible to a string), and 0 otherwise. +// +// [lua_isstring]: https://www.lua.org/manual/5.1/manual.html#lua_isstring func (L *State) IsString(index int) bool { return C.lua_isstring(L.s, C.int(index)) == 1 } -// lua_istable -/* - * [-0, +0, -] - * Returns 1 if the value at the given acceptable index is a table, and 0 otherwise. - */ +// [lua_istable] -> [-0, +0, -] +// +// Returns 1 if the value at the given acceptable index is a table, and 0 otherwise. +// +// [lua_istable]: https://www.lua.org/manual/5.1/manual.html#lua_istable func (L *State) IsTable(index int) bool { return LuaValType(C.lua_type(L.s, C.int(index))) == LUA_TTABLE } -// lua_isthread -/* - * [-0, +0, -] - * Returns 1 if the value at the given acceptable index is a thread, and 0 otherwise. - */ +// [lua_isthread] -> [-0, +0, -] +// +// Returns 1 if the value at the given acceptable index is a thread, and 0 otherwise. +// +// [lua_isthread]: https://www.lua.org/manual/5.1/manual.html#lua_isthread func (L *State) IsThread(index int) bool { return LuaValType(C.lua_type(L.s, C.int(index))) == LUA_TTHREAD } -// lua_isuserdata -/* - * [-0, +0, -] - * Returns 1 if the value at the given acceptable index is a userdata (either full or light), and 0 otherwise. - */ +// [lua_isuserdata] -> [-0, +0, -] +// +// Returns 1 if the value at the given acceptable index is a userdata (either full or light), and 0 otherwise. +// +// [lua_isuserdata]: https://www.lua.org/manual/5.1/manual.html#lua_isuserdata func (L *State) IsUserdata(index int) bool { return C.lua_isuserdata(L.s, C.int(index)) == 1 } // Creates a new lua interpreter state with the given allocation function @@ -450,20 +450,20 @@ func NewStateAlloc(f Alloc) *State { return L } -// lua_newtable -/* - * [-0, +1, m] - * Creates a new empty table and pushes it onto the stack. It is equivalent to lua_createtable(L, 0, 0). - */ +// [lua_newtable] -> [-0, +1, m] +// +// Creates a new empty table and pushes it onto the stack. It is equivalent to lua_createtable(L, 0, 0). +// +// [lua_newtable]: https://www.lua.org/manual/5.1/manual.html#lua_newtable func (L *State) NewTable() { C.lua_createtable(L.s, 0, 0) } -// lua_newthread -/* - * [-0, +1, m] - * Creates a new thread, pushes it on the stack, and returns a pointer to a lua_State that represents this new thread. The new state returned by this function shares with the original state all global objects (such as tables), but has an independent execution stack. - */ +// [lua_newthread] -> [-0, +1, m] +// +// Creates a new thread, pushes it on the stack, and returns a pointer to a lua_State that represents this new thread. The new state returned by this function shares with the original state all global objects (such as tables), but has an independent execution stack. +// +// [lua_newthread]: https://www.lua.org/manual/5.1/manual.html#lua_newthread func (L *State) NewThread() *State { // TODO: call newState with result from C.lua_newthread and return it // TODO: should have same lists as parent @@ -472,36 +472,36 @@ func (L *State) NewThread() *State { return &State{s, 0, nil, nil, nil, nil, nil} } -// lua_next -/* - * [-1, +(2|0), e] - * Pops a key from the stack, and pushes a key-value pair from the table at the given index (the "next" pair after the given key). If there are no more elements in the table, then lua_next returns 0 (and pushes nothing). - */ +// [lua_next] -> [-1, +(2|0), e] +// +// Pops a key from the stack, and pushes a key-value pair from the table at the given index (the "next" pair after the given key). If there are no more elements in the table, then lua_next returns 0 (and pushes nothing). +// +// [lua_next]: https://www.lua.org/manual/5.1/manual.html#lua_next func (L *State) Next(index int) int { return int(C.lua_next(L.s, C.int(index))) } -// lua_objlen -/* - * [-0, +0, -] - * Returns the "length" of the value at the given acceptable index: for strings, this is the string length; for tables, this is the result of the length operator ('#'); for userdata, this is the size of the block of memory allocated for the userdata; for other values, it is 0. - */ -// lua_pop -/* - * [-n, +0, -] - * Pops n elements from the stack. - */ +// [lua_objlen] -> [-0, +0, -] +// +// Returns the "length" of the value at the given acceptable index: for strings, this is the string length; for tables, this is the result of the length operator ('#'); for userdata, this is the size of the block of memory allocated for the userdata; for other values, it is 0. +// +// [lua_objlen]: https://www.lua.org/manual/5.1/manual.html#lua_objlen +// [lua_pop] -> [-n, +0, -] +// +// Pops n elements from the stack. +// +// [lua_pop]: https://www.lua.org/manual/5.1/manual.html#lua_pop func (L *State) Pop(n int) { // Why is this implemented this way? I don't get it... // C.lua_pop(L.s, C.int(n)); C.lua_settop(L.s, C.int(-n-1)) } -// lua_pushboolean -/* - * [-0, +1, -] - * Pushes a boolean value with value b onto the stack. - */ +// [lua_pushboolean] -> [-0, +1, -] +// +// Pushes a boolean value with value b onto the stack. +// +// [lua_pushboolean]: https://www.lua.org/manual/5.1/manual.html#lua_pushboolean func (L *State) PushBoolean(b bool) { var bint int if b { @@ -512,11 +512,11 @@ func (L *State) PushBoolean(b bool) { C.lua_pushboolean(L.s, C.int(bint)) } -// lua_pushstring -/* - * [-0, +1, m] - * Pushes the zero-terminated string pointed to by s onto the stack. Lua makes (or reuses) an internal copy of the given string, so the memory at s can be freed or reused immediately after the function returns. The string cannot contain embedded zeros; it is assumed to end at the first zero. - */ +// [lua_pushstring] -> [-0, +1, m] +// +// Pushes the zero-terminated string pointed to by s onto the stack. Lua makes (or reuses) an internal copy of the given string, so the memory at s can be freed or reused immediately after the function returns. The string cannot contain embedded zeros; it is assumed to end at the first zero. +// +// [lua_pushstring]: https://www.lua.org/manual/5.1/manual.html#lua_pushstring func (L *State) PushString(str string) { Cstr := C.CString(str) defer C.free(unsafe.Pointer(Cstr)) @@ -527,74 +527,74 @@ func (L *State) PushBytes(b []byte) { C.lua_pushlstring(L.s, (*C.char)(unsafe.Pointer(&b[0])), C.size_t(len(b))) } -// lua_pushinteger -/* - * [-0, +1, -] - * Pushes a number with value n onto the stack. - */ +// [lua_pushinteger] -> [-0, +1, -] +// +// Pushes a number with value n onto the stack. +// +// [lua_pushinteger]: https://www.lua.org/manual/5.1/manual.html#lua_pushinteger func (L *State) PushInteger(n int64) { C.lua_pushinteger(L.s, C.lua_Integer(n)) } -// lua_pushnil -/* - * [-0, +1, -] - * Pushes a nil value onto the stack. - */ +// [lua_pushnil] -> [-0, +1, -] +// +// Pushes a nil value onto the stack. +// +// [lua_pushnil]: https://www.lua.org/manual/5.1/manual.html#lua_pushnil func (L *State) PushNil() { C.lua_pushnil(L.s) } -// lua_pushnumber -/* - * [-0, +1, -] - * Pushes a number with value n onto the stack. - */ +// [lua_pushnumber] -> [-0, +1, -] +// +// Pushes a number with value n onto the stack. +// +// [lua_pushnumber]: https://www.lua.org/manual/5.1/manual.html#lua_pushnumber func (L *State) PushNumber(n float64) { C.lua_pushnumber(L.s, C.lua_Number(n)) } -// lua_pushthread -/* - * [-0, +1, -] - * Pushes the thread represented by L onto the stack. Returns 1 if this thread is the main thread of its state. - */ +// [lua_pushthread] -> [-0, +1, -] +// +// Pushes the thread represented by L onto the stack. Returns 1 if this thread is the main thread of its state. +// +// [lua_pushthread]: https://www.lua.org/manual/5.1/manual.html#lua_pushthread func (L *State) PushThread() (isMain bool) { return C.lua_pushthread(L.s) != 0 } -// lua_pushvalue -/* - * [-0, +1, -] - * Pushes a copy of the element at the given valid index onto the stack. - */ +// [lua_pushvalue] -> [-0, +1, -] +// +// Pushes a copy of the element at the given valid index onto the stack. +// +// [lua_pushvalue]: https://www.lua.org/manual/5.1/manual.html#lua_pushvalue func (L *State) PushValue(index int) { C.lua_pushvalue(L.s, C.int(index)) } -// lua_rawequal -/* - * [-0, +0, -] - * Returns 1 if the two values in acceptable indices index1 and index2 are primitively equal (that is, without calling metamethods). Otherwise returns 0. Also returns 0 if any of the indices are non valid. - */ +// [lua_rawequal] -> [-0, +0, -] +// +// Returns 1 if the two values in acceptable indices index1 and index2 are primitively equal (that is, without calling metamethods). Otherwise returns 0. Also returns 0 if any of the indices are non valid. +// +// [lua_rawequal]: https://www.lua.org/manual/5.1/manual.html#lua_rawequal func (L *State) RawEqual(index1 int, index2 int) bool { return C.lua_rawequal(L.s, C.int(index1), C.int(index2)) != 0 } -// lua_rawget -/* - * [-1, +1, -] - * Similar to lua_gettable, but does a raw access (i.e., without metamethods). - */ +// [lua_rawget] -> [-1, +1, -] +// +// Similar to lua_gettable, but does a raw access (i.e., without metamethods). +// +// [lua_rawget]: https://www.lua.org/manual/5.1/manual.html#lua_rawget func (L *State) RawGet(index int) { C.lua_rawget(L.s, C.int(index)) } -// lua_rawset -/* - * [-2, +0, m] - * Similar to lua_settable, but does a raw assignment (i.e., without metamethods). - */ +// [lua_rawset] -> [-2, +0, m] +// +// Similar to lua_settable, but does a raw assignment (i.e., without metamethods). +// +// [lua_rawset]: https://www.lua.org/manual/5.1/manual.html#lua_rawset func (L *State) RawSet(index int) { C.lua_rawset(L.s, C.int(index)) } @@ -628,68 +628,68 @@ func (L *State) RegisterLibrary(name string, funcs map[string]LuaGoFunction) { } } -// lua_setallocf -/* - * [-0, +0, -] - * Changes the allocator function of a given state to f with user data ud. - */ +// [lua_setallocf] -> [-0, +0, -] +// +// Changes the allocator function of a given state to f with user data ud. +// +// [lua_setallocf]: https://www.lua.org/manual/5.1/manual.html#lua_setallocf func (L *State) SetAllocf(f Alloc) { L.allocfn = &f C.clua_setallocf(L.s, unsafe.Pointer(L.allocfn)) } -// lua_setfield -/* - * [-1, +0, e] - * Does the equivalent to t[k] = v, where t is the value at the given valid index and v is the value at the top of the stack. - */ +// [lua_setfield] -> [-1, +0, e] +// +// Does the equivalent to t[k] = v, where t is the value at the given valid index and v is the value at the top of the stack. +// +// [lua_setfield]: https://www.lua.org/manual/5.1/manual.html#lua_setfield func (L *State) SetField(index int, k string) { Ck := C.CString(k) defer C.free(unsafe.Pointer(Ck)) C.lua_setfield(L.s, C.int(index), Ck) } -// lua_setmetatable -/* - * [-1, +0, -] - * Pops a table from the stack and sets it as the new metatable for the value at the given acceptable index. - */ +// [lua_setmetatable] -> [-1, +0, -] +// +// Pops a table from the stack and sets it as the new metatable for the value at the given acceptable index. +// +// [lua_setmetatable]: https://www.lua.org/manual/5.1/manual.html#lua_setmetatable func (L *State) SetMetaTable(index int) { C.lua_setmetatable(L.s, C.int(index)) } -// lua_settable -/* - * [-2, +0, e] - * Does the equivalent to t[k] = v, where t is the value at the given valid index, v is the value at the top of the stack, and k is the value just below the top. - */ +// [lua_settable] -> [-2, +0, e] +// +// Does the equivalent to t[k] = v, where t is the value at the given valid index, v is the value at the top of the stack, and k is the value just below the top. +// +// [lua_settable]: https://www.lua.org/manual/5.1/manual.html#lua_settable func (L *State) SetTable(index int) { C.lua_settable(L.s, C.int(index)) } -// lua_settop -/* - * [-?, +?, -] - * Accepts any acceptable index, or 0, and sets the stack top to this index. If the new top is larger than the old one, then the new elements are filled with nil. If index is 0, then all stack elements are removed. - */ +// [lua_settop] -> [-?, +?, -] +// +// Accepts any acceptable index, or 0, and sets the stack top to this index. If the new top is larger than the old one, then the new elements are filled with nil. If index is 0, then all stack elements are removed. +// +// [lua_settop]: https://www.lua.org/manual/5.1/manual.html#lua_settop func (L *State) SetTop(index int) { C.lua_settop(L.s, C.int(index)) } -// lua_status -/* - * [-0, +0, -] - * Returns the status of the thread L. - */ +// [lua_status] -> [-0, +0, -] +// +// Returns the status of the thread L. +// +// [lua_status]: https://www.lua.org/manual/5.1/manual.html#lua_status func (L *State) Status() int { return int(C.lua_status(L.s)) } -// lua_toboolean -/* - * [-0, +0, -] - * Converts the Lua value at the given acceptable index to a C boolean value (0 or 1). Like all tests in Lua, lua_toboolean returns 1 for any Lua value different from false and nil; otherwise it returns 0. It also returns 0 when called with a non-valid index. (If you want to accept only actual boolean values, use lua_isboolean to test the value's type.) - */ +// [lua_toboolean] -> [-0, +0, -] +// +// Converts the Lua value at the given acceptable index to a C boolean value (0 or 1). Like all tests in Lua, lua_toboolean returns 1 for any Lua value different from false and nil; otherwise it returns 0. It also returns 0 when called with a non-valid index. (If you want to accept only actual boolean values, use lua_isboolean to test the value's type.) +// +// [lua_toboolean]: https://www.lua.org/manual/5.1/manual.html#lua_toboolean func (L *State) ToBoolean(index int) bool { return C.lua_toboolean(L.s, C.int(index)) != 0 } @@ -718,11 +718,11 @@ func (L *State) ToGoStruct(index int) (f interface{}) { return L.registry[fid] } -// lua_tostring -/* - * [-0, +0, m] - * Equivalent to lua_tolstring with len equal to NULL. - */ +// [lua_tostring] -> [-0, +0, m] +// +// Equivalent to lua_tolstring with len equal to NULL. +// +// [lua_tostring]: https://www.lua.org/manual/5.1/manual.html#lua_tostring func (L *State) ToString(index int) string { var size C.size_t r := C.lua_tolstring(L.s, C.int(index), &size) @@ -735,57 +735,57 @@ func (L *State) ToBytes(index int) []byte { return C.GoBytes(unsafe.Pointer(b), C.int(size)) } -// lua_topointer -/* - * [-0, +0, -] - * Converts the value at the given acceptable index to a generic C pointer (void*). The value can be a userdata, a table, a thread, or a function; otherwise, lua_topointer returns NULL. Different objects will give different pointers. There is no way to convert the pointer back to its original value. - */ +// [lua_topointer] -> [-0, +0, -] +// +// Converts the value at the given acceptable index to a generic C pointer (void*). The value can be a userdata, a table, a thread, or a function; otherwise, lua_topointer returns NULL. Different objects will give different pointers. There is no way to convert the pointer back to its original value. +// +// [lua_topointer]: https://www.lua.org/manual/5.1/manual.html#lua_topointer func (L *State) ToPointer(index int) uintptr { return uintptr(C.lua_topointer(L.s, C.int(index))) } -// lua_tothread -/* - * [-0, +0, -] - * Converts the value at the given acceptable index to a Lua thread (represented as lua_State*). This value must be a thread; otherwise, the function returns NULL. - */ +// [lua_tothread] -> [-0, +0, -] +// +// Converts the value at the given acceptable index to a Lua thread (represented as lua_State*). This value must be a thread; otherwise, the function returns NULL. +// +// [lua_tothread]: https://www.lua.org/manual/5.1/manual.html#lua_tothread func (L *State) ToThread(index int) *State { // TODO: find a way to link lua_State* to existing *State, return that return &State{} } -// lua_touserdata -/* - * [-0, +0, -] - * If the value at the given acceptable index is a full userdata, returns its block address. If the value is a light userdata, returns its pointer. Otherwise, returns NULL. - */ +// [lua_touserdata] -> [-0, +0, -] +// +// If the value at the given acceptable index is a full userdata, returns its block address. If the value is a light userdata, returns its pointer. Otherwise, returns NULL. +// +// [lua_touserdata]: https://www.lua.org/manual/5.1/manual.html#lua_touserdata func (L *State) ToUserdata(index int) unsafe.Pointer { return unsafe.Pointer(C.lua_touserdata(L.s, C.int(index))) } -// lua_type -/* - * [-0, +0, -] - * Returns the type of the value in the given acceptable index, or LUA_TNONE for a non-valid index (that is, an index to an "empty" stack position). The types returned by lua_type are coded by the following constants defined in lua.h: LUA_TNIL, LUA_TNUMBER, LUA_TBOOLEAN, LUA_TSTRING, LUA_TTABLE, LUA_TFUNCTION, LUA_TUSERDATA, LUA_TTHREAD, and LUA_TLIGHTUSERDATA. - */ +// [lua_type] -> [-0, +0, -] +// +// Returns the type of the value in the given acceptable index, or LUA_TNONE for a non-valid index (that is, an index to an "empty" stack position). The types returned by lua_type are coded by the following constants defined in lua.h: LUA_TNIL, LUA_TNUMBER, LUA_TBOOLEAN, LUA_TSTRING, LUA_TTABLE, LUA_TFUNCTION, LUA_TUSERDATA, LUA_TTHREAD, and LUA_TLIGHTUSERDATA. +// +// [lua_type]: https://www.lua.org/manual/5.1/manual.html#lua_type func (L *State) Type(index int) LuaValType { return LuaValType(C.lua_type(L.s, C.int(index))) } -// lua_typename -/* - * [-0, +0, -] - * Returns the name of the type encoded by the value tp, which must be one the values returned by lua_type. - */ +// [lua_typename] -> [-0, +0, -] +// +// Returns the name of the type encoded by the value tp, which must be one the values returned by lua_type. +// +// [lua_typename]: https://www.lua.org/manual/5.1/manual.html#lua_typename func (L *State) Typename(tp int) string { return C.GoString(C.lua_typename(L.s, C.int(tp))) } -// lua_xmove -/* - * [-?, +?, -] - * Exchange values between different threads of the same global state. - */ +// [lua_xmove] -> [-?, +?, -] +// +// Exchange values between different threads of the same global state. +// +// [lua_xmove]: https://www.lua.org/manual/5.1/manual.html#lua_xmove func XMove(from *State, to *State, n int) { C.lua_xmove(from.s, to.s, C.int(n)) }