# luaforth

**Source:** https://github.com/vifino/luaforth

GitHub - vifino/luaforth: A simple Forth in Lua for embedded usage.



[Skip to content](#start-of-content)













## Navigation Menu

Toggle navigation

[Sign in](/login?return_to=https%3A%2F%2Fgithub.com%2Fvifino%2Fluaforth)

Appearance settings

* Platform

  + AI CODE CREATION
    - [GitHub CopilotWrite better code with AI](https://github.com/features/copilot)
    - [GitHub SparkBuild and deploy intelligent apps](https://github.com/features/spark)
    - [GitHub ModelsManage and compare prompts](https://github.com/features/models)
    - [MCP RegistryNewIntegrate external tools](https://github.com/mcp)
  + DEVELOPER WORKFLOWS
    - [ActionsAutomate any workflow](https://github.com/features/actions)
    - [CodespacesInstant dev environments](https://github.com/features/codespaces)
    - [IssuesPlan and track work](https://github.com/features/issues)
    - [Code ReviewManage code changes](https://github.com/features/code-review)
  + APPLICATION SECURITY
    - [GitHub Advanced SecurityFind and fix vulnerabilities](https://github.com/security/advanced-security)
    - [Code securitySecure your code as you build](https://github.com/security/advanced-security/code-security)
    - [Secret protectionStop leaks before they start](https://github.com/security/advanced-security/secret-protection)
  + EXPLORE
    - [Why GitHub](https://github.com/why-github)
    - [Documentation](https://docs.github.com)
    - [Blog](https://github.blog)
    - [Changelog](https://github.blog/changelog)
    - [Marketplace](https://github.com/marketplace)

  [View all features](https://github.com/features)
* Solutions

  + BY COMPANY SIZE
    - [Enterprises](https://github.com/enterprise)
    - [Small and medium teams](https://github.com/team)
    - [Startups](https://github.com/enterprise/startups)
    - [Nonprofits](https://github.com/solutions/industry/nonprofits)
  + BY USE CASE
    - [App Modernization](https://github.com/solutions/use-case/app-modernization)
    - [DevSecOps](https://github.com/solutions/use-case/devsecops)
    - [DevOps](https://github.com/solutions/use-case/devops)
    - [CI/CD](https://github.com/solutions/use-case/ci-cd)
    - [View all use cases](https://github.com/solutions/use-case)
  + BY INDUSTRY
    - [Healthcare](https://github.com/solutions/industry/healthcare)
    - [Financial services](https://github.com/solutions/industry/financial-services)
    - [Manufacturing](https://github.com/solutions/industry/manufacturing)
    - [Government](https://github.com/solutions/industry/government)
    - [View all industries](https://github.com/solutions/industry)

  [View all solutions](https://github.com/solutions)
* Resources

  + EXPLORE BY TOPIC
    - [AI](https://github.com/resources/articles?topic=ai)
    - [Software Development](https://github.com/resources/articles?topic=software-development)
    - [DevOps](https://github.com/resources/articles?topic=devops)
    - [Security](https://github.com/resources/articles?topic=security)
    - [View all topics](https://github.com/resources/articles)
  + EXPLORE BY TYPE
    - [Customer stories](https://github.com/customer-stories)
    - [Events & webinars](https://github.com/resources/events)
    - [Ebooks & reports](https://github.com/resources/whitepapers)
    - [Business insights](https://github.com/solutions/executive-insights)
    - [GitHub Skills](https://skills.github.com)
  + SUPPORT & SERVICES
    - [Documentation](https://docs.github.com)
    - [Customer support](https://support.github.com)
    - [Community forum](https://github.com/orgs/community/discussions)
    - [Trust center](https://github.com/trust-center)
    - [Partners](https://github.com/partners)
* Open Source

  + COMMUNITY
    - [GitHub SponsorsFund open source developers](https://github.com/sponsors)
  + PROGRAMS
    - [Security Lab](https://securitylab.github.com)
    - [Maintainer Community](https://maintainers.github.com)
    - [Accelerator](https://github.com/accelerator)
    - [Archive Program](https://archiveprogram.github.com)
  + REPOSITORIES
    - [Topics](https://github.com/topics)
    - [Trending](https://github.com/trending)
    - [Collections](https://github.com/collections)
* Enterprise

  + ENTERPRISE SOLUTIONS
    - [Enterprise platformAI-powered developer platform](https://github.com/enterprise)
  + AVAILABLE ADD-ONS
    - [GitHub Advanced SecurityEnterprise-grade security features](https://github.com/security/advanced-security)
    - [Copilot for BusinessEnterprise-grade AI features](https://github.com/features/copilot/copilot-business)
    - [Premium SupportEnterprise-grade 24/7 support](https://github.com/premium-support)
* [Pricing](https://github.com/pricing)

Search or jump to...


# Search code, repositories, users, issues, pull requests...

Search

Clear

[Search syntax tips](https://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax)

# Provide feedback

We read every piece of feedback, and take your input very seriously.


Include my email address so I can be contacted

Cancel
 Submit feedback





# Saved searches

## Use saved searches to filter your results more quickly

Name

Query

To see all available qualifiers, see our [documentation](https://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax).

Cancel
 Create saved search

[Sign in](/login?return_to=https%3A%2F%2Fgithub.com%2Fvifino%2Fluaforth)

[Sign up](/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E&source=header-repo&source_repo=vifino%2Fluaforth)

Appearance settings

Resetting focus

You signed in with another tab or window. Reload to refresh your session.
You signed out in another tab or window. Reload to refresh your session.
You switched accounts on another tab or window. Reload to refresh your session.
 


Dismiss alert

{{ message }}

[vifino](/vifino) 
/
**[luaforth](/vifino/luaforth)**
Public

* [Notifications](/login?return_to=%2Fvifino%2Fluaforth) You must be signed in to change notification settings
* [Fork
  2](/login?return_to=%2Fvifino%2Fluaforth)
* [Star
   6](/login?return_to=%2Fvifino%2Fluaforth)

A simple Forth in Lua for embedded usage.

### License

[MIT license](/vifino/luaforth/blob/master/LICENSE)

[6
stars](/vifino/luaforth/stargazers) [2
forks](/vifino/luaforth/forks) [Branches](/vifino/luaforth/branches) [Tags](/vifino/luaforth/tags) [Activity](/vifino/luaforth/activity)

[Star](/login?return_to=%2Fvifino%2Fluaforth)

[Notifications](/login?return_to=%2Fvifino%2Fluaforth) You must be signed in to change notification settings

* [Code](/vifino/luaforth)
* [Issues
  0](/vifino/luaforth/issues)
* [Pull requests
  0](/vifino/luaforth/pulls)
* [Actions](/vifino/luaforth/actions)
* [Projects
  0](/vifino/luaforth/projects)
* [Security
  0](/vifino/luaforth/security)
* [Insights](/vifino/luaforth/pulse)

Additional navigation options


* [Code](/vifino/luaforth)
* [Issues](/vifino/luaforth/issues)
* [Pull requests](/vifino/luaforth/pulls)
* [Actions](/vifino/luaforth/actions)
* [Projects](/vifino/luaforth/projects)
* [Security](/vifino/luaforth/security)
* [Insights](/vifino/luaforth/pulse)

# vifino/luaforth

master

[Branches](/vifino/luaforth/branches)[Tags](/vifino/luaforth/tags)

Go to file

Code

Open more actions menu

## Folders and files

| Name | | Name | Last commit message | Last commit date |
| --- | --- | --- | --- | --- |
| Latest commit   History[27 Commits](/vifino/luaforth/commits/master/)   27 Commits | | |
| [bin](/vifino/luaforth/tree/master/bin "bin") | | [bin](/vifino/luaforth/tree/master/bin "bin") |  |  |
| [tests](/vifino/luaforth/tree/master/tests "tests") | | [tests](/vifino/luaforth/tree/master/tests "tests") |  |  |
| [.travis.yml](/vifino/luaforth/blob/master/.travis.yml ".travis.yml") | | [.travis.yml](/vifino/luaforth/blob/master/.travis.yml ".travis.yml") |  |  |
| [LICENSE](/vifino/luaforth/blob/master/LICENSE "LICENSE") | | [LICENSE](/vifino/luaforth/blob/master/LICENSE "LICENSE") |  |  |
| [Makefile](/vifino/luaforth/blob/master/Makefile "Makefile") | | [Makefile](/vifino/luaforth/blob/master/Makefile "Makefile") |  |  |
| [README.md](/vifino/luaforth/blob/master/README.md "README.md") | | [README.md](/vifino/luaforth/blob/master/README.md "README.md") |  |  |
| [app.lua](/vifino/luaforth/blob/master/app.lua "app.lua") | | [app.lua](/vifino/luaforth/blob/master/app.lua "app.lua") |  |  |
| [auto-run-tests-on-change.sh](/vifino/luaforth/blob/master/auto-run-tests-on-change.sh "auto-run-tests-on-change.sh") | | [auto-run-tests-on-change.sh](/vifino/luaforth/blob/master/auto-run-tests-on-change.sh "auto-run-tests-on-change.sh") |  |  |
| [luaforth.lua](/vifino/luaforth/blob/master/luaforth.lua "luaforth.lua") | | [luaforth.lua](/vifino/luaforth/blob/master/luaforth.lua "luaforth.lua") |  |  |
| View all files | | |

## Repository files navigation

* [README](#)
* [MIT license](#)

# luaforth

[![Build Status](https://camo.githubusercontent.com/f84f1765e4dc206c95e842195c97624b2fc6309edb929d618d902c914ae3de0e/68747470733a2f2f7472617669732d63692e6f72672f766966696e6f2f6c7561666f7274682e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/vifino/luaforth) [![Coverage Status](https://camo.githubusercontent.com/92a923f80497d3e929dddec4c3199009e5b54f47d881a20b0aad9e406593c60b/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f766966696e6f2f6c7561666f7274682f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/vifino/luaforth?branch=master)

A simplistic and decently fast base implementation of a Forth parser.

If you expect a fully featured forth here, you're wrong.

This is made for people who want to embed a Forth-like into their project.

# Usage

1. `require`/load luaforth.
2. Create an environment.
3. Call `new_stack, new_environment = luaforth.eval(program_source, environment[, stack, program_source_start_position])`.

Tada!

# Example

See `luaforth.simple_env` [here](https://github.com/vifino/luaforth/blob/master/luaforth.lua#L246-L253) or below.

```
-- Example env that has %L to evaluate the line and [L L] pairs to evaluate a small block of Lua code.
local simple_env = {
	["%L"] = {
		_fn=function(stack, env, str)
			local f, err = loadstring("return " .. str)
			if err then
				f, err = loadstring(str)
				if err then
					error(err, 0)
				end
			end
			return f()
		end,
		_parse = "line"
	},
	["[L"] = {
		_fn=function(stack, env, str)
			local f, err = loadstring("return " .. str)
			if err then
				f, err = loadstring(str)
				if err then
					error(err, 0)
				end
			end
			return f()
		end,
		_parse = "endsign",
		_endsign = "L]"
	}
}

-- Function creation.
luaforth.simple_env[":"] = {
	_fn = function(stack, env, fn)
		local nme, prg = string.match(fn, "^(.-) (.-)$")
		luaforth.simple_env[nme] = {
			_fn = function(stack, env)
				return luaforth.eval(prg, env, stack)
			end,
			_fnret = "newstack"
		}
	end,
	_parse = "endsign",
	_endsign = ";"
}
```

# Environment

Contains words, strings, booleans, numbers and other things that the forth instance will be able to use.

## Word Structure

Words are Forth jargon for functions.

Look here or below to see how they are structured in this implementation.

```
-- Word structure:
-- env[name] = {
--  _fn = func -- function that runs the logic
--  _fnret = ["pushtostack", "newstack"] -- wether the function's return values should be added to the stack or _be_ the stack. Defaults to pushtostack.
--  _args = n -- number of arguments which are pop'd from the stack, defaults to 0
--  _parse = ["line"|"word"|"endsign"|"pattern"] -- optional advanced parsing, line passes the whole line to the word, word only the next word, pattern parses given pattern, endsign until...
--  _endsign = string -- the given endsign appears.
--  _pattern = pattern -- pattern for parse option
-- }
```

# License

MIT

## About

A simple Forth in Lua for embedded usage.

### Topics

[lua-library](/topics/lua-library "Topic: lua-library")
[lua](/topics/lua "Topic: lua")
[forth](/topics/forth "Topic: forth")

### Resources

[Readme](#readme-ov-file)

### License

[MIT license](#MIT-1-ov-file)

### Uh oh!

There was an error while loading. Please reload this page.

[Activity](/vifino/luaforth/activity)

### Stars

[**6**
stars](/vifino/luaforth/stargazers)

### Watchers

[**2**
watching](/vifino/luaforth/watchers)

### Forks

[**2**
forks](/vifino/luaforth/forks)

[Report repository](/contact/report-content?content_url=https%3A%2F%2Fgithub.com%2Fvifino%2Fluaforth&report=vifino+%28user%29)

## [Releases](/vifino/luaforth/releases)

No releases published

## [Packages 0](/users/vifino/packages?repo_name=luaforth)

No packages published

## [Contributors 2](/vifino/luaforth/graphs/contributors)

### Uh oh!

There was an error while loading. Please reload this page.

## Languages

* [Lua
  95.7%](/vifino/luaforth/search?l=lua)
* [Forth
  3.0%](/vifino/luaforth/search?l=forth)
* Other
  1.3%

## Footer

© 2026 GitHub, Inc.

### Footer navigation

* [Terms](https://docs.github.com/site-policy/github-terms/github-terms-of-service)
* [Privacy](https://docs.github.com/site-policy/privacy-policies/github-privacy-statement)
* [Security](https://github.com/security)
* [Status](https://www.githubstatus.com/)
* [Community](https://github.community/)
* [Docs](https://docs.github.com/)
* [Contact](https://support.github.com?tags=dotcom-footer)
* Manage cookies
* Do not share my personal information



You can’t perform that action at this time.