luadoc

package module
v0.3.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 18, 2026 License: Unlicense Imports: 6 Imported by: 3 modules, 26 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

gopher-luadoc

Go Reference

Self-documenting libraries for gopher-lua: describe the functions, variables and classes of a library once, then load it into a Lua state and generate its LuaLS annotations (@class, @param, @return, ...) for editor completion.

Warning

The API is not stable and may change at any time.

Note: This is a fork of mangalorg/gopher-luadoc. Used by luaprovider and mangal.

Usage

package main

import (
	"fmt"
	"strings"

	luadoc "github.com/luevano/gopher-luadoc"
	lua "github.com/yuin/gopher-lua"
)

func main() {
	text := &luadoc.Lib{
		Name:        "text",
		Description: "Text helpers.",
		Funcs: []*luadoc.Func{{
			Name:        "upper",
			Description: "Uppercase a string.",
			Value: func(L *lua.LState) int {
				L.Push(lua.LString(strings.ToUpper(L.CheckString(1))))
				return 1
			},
			Params:  []*luadoc.Param{{Name: "s", Type: luadoc.String}},
			Returns: []*luadoc.Param{{Name: "upper", Type: luadoc.String}},
		}},
	}
	// the root lib can have its own members too: require("mylib").text.upper("hi")
	lib := &luadoc.Lib{Name: "mylib", Libs: []*luadoc.Lib{text}}

	L := lua.NewState()
	defer L.Close()
	L.PreloadModule(lib.Name, lib.Loader())

	// the annotations, e.g. to save as mylib.lua
	fmt.Println(lib.LuaDoc())
}

Documentation

Index

Constants

View Source
const (
	String  = "string"
	Number  = "number"
	Boolean = "boolean"
	Table   = "table"
	Any     = "any"
)

Variables

This section is empty.

Functions

func Enum

func Enum(members ...string) string

func List

func List(of string) string

func Map

func Map(keys string, values string) string

func TableLiteral

func TableLiteral(keysAndValues ...string) string

Types

type Class

type Class struct {
	Name        string
	Description string
	Methods     []*Method
}

type Func

type Func struct {
	Name        string
	Description string
	Value       lua.LGFunction
	Generics    []string
	Params      []*Param
	Returns     []*Param
}

func (Func) AsType

func (f Func) AsType() string

type Lib

type Lib struct {
	Name        string
	Description string
	Vars        []*Var
	Funcs       []*Func
	Classes     []*Class
	Libs        []*Lib
}

func (*Lib) Loader

func (l *Lib) Loader() lua.LGFunction

Loader is the module loader of the lib (for PreloadModule): its own members and its libs.

func (*Lib) LuaDoc

func (l *Lib) LuaDoc() string

func (*Lib) Value

func (l *Lib) Value(state *lua.LState) *lua.LTable

type Method

type Method struct {
	Name        string
	Description string
	Value       lua.LGFunction
	Generics    []string
	Params      []*Param
	Returns     []*Param
}

type Param

type Param struct {
	Name        string
	Description string
	Type        string
	Optional    bool
}

func (*Param) String

func (p *Param) String() string

type Var

type Var struct {
	Name        string
	Description string
	Value       lua.LValue
	Type        string
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址