explaingit

yuin/gopher-lua

6,897GoAudience · developerComplexity · 2/5Setup · moderate

TLDR

A complete Lua 5.1 interpreter written in pure Go with no C dependencies, letting you embed a user-scriptable language directly into your Go application so end users can write and run Lua scripts at runtime.

Mindmap

mindmap
  root((GopherLua))
    What it does
      Lua interpreter
      Embeds in Go apps
      No C dependencies
    Go API
      Call Lua from Go
      Expose Go to Lua
      Go channels in Lua
    Tuning
      Registry size limits
      Concurrent states
    Use cases
      Plugin systems
      User scripting
      Game logic
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Add a Lua scripting layer to a Go application so users or admins can write automation scripts without recompiling

USE CASE 2

Let players write Lua mods for a Go-based game that run inside the game's process safely

USE CASE 3

Embed a sandboxed scripting engine in a Go configuration tool so rules can be changed without redeploying

USE CASE 4

Run hundreds of concurrent per-user Lua sessions in a Go server with tuned memory limits per state

Tech stack

GoLua

Getting it running

Difficulty · moderate Time to first run · 30min

In plain English

GopherLua is a Lua interpreter built entirely in Go. It implements the Lua 5.1 language (plus the goto statement from Lua 5.2), meaning it can run Lua scripts, but it does so without any C code or external dependencies. The main purpose is to let Go programs embed a scripting language: you write your application in Go, and then you can let users or administrators write scripts in Lua that your application runs at runtime. The Go API is designed to be straightforward. You create a state, load a Lua file or string, call Lua functions from Go, and pass Go functions back into the Lua environment. Unlike the original Lua C library which uses a stack-based API (where you push and pop values to exchange data), GopherLua uses direct Go objects, which the README describes as more user-friendly even if slightly slower. Performance is roughly comparable to Python 3 on the micro-benchmarks the project has run. All Lua values are represented in Go through an interface called LValue. Numbers are float64, strings are Go strings, tables are Go structs, and so on. You can check what type a value is using type assertions or a Type() method. There are helper functions for handling Lua's rule that both nil and false count as false in conditionals. Go functions can be registered as Lua globals, allowing you to expose your application's functionality to scripts. The state's internal memory can be tuned: you can set the initial size and maximum size of the registry (the internal value stack), and configure whether the call stack grows automatically or stays at a fixed size. These options matter if you are running many concurrent Lua states, such as in a server application handling many simultaneous users, where memory efficiency becomes important. GopherLua also supports Go channels as a first-class Lua type, which allows Lua scripts to participate in Go's goroutine-based concurrency model. A collection of third-party libraries for GopherLua is listed in the README.

Copy-paste prompts

Prompt 1
Using GopherLua, embed a Lua interpreter in my Go HTTP server so incoming webhook payloads can be processed by user-defined Lua scripts.
Prompt 2
Show me how to expose a Go function to GopherLua so a Lua script can call my app's database query function and get results back as a Lua table.
Prompt 3
In GopherLua, how do I pass a Go struct into Lua as a table, let a Lua script modify its fields, and read the updated values back in Go?
Prompt 4
Set up GopherLua with a fixed-size call stack and registry limit so I can safely run 500 concurrent Lua states in a Go service without excessive memory use.
Prompt 5
How do I use Go channels from inside a GopherLua script so Lua code can participate in Go goroutine-based concurrency?
Open on GitHub → Explain another repo

← yuin on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.