13 KiB
luaforth
Source: https://github.com/vifino/luaforth
GitHub - vifino/luaforth: A simple Forth in Lua for embedded usage.
Navigation Menu
Toggle navigation
Appearance settings
-
Platform
- AI CODE CREATION
- DEVELOPER WORKFLOWS
- APPLICATION SECURITY
- EXPLORE
-
Solutions
- BY COMPANY SIZE
- BY USE CASE
- BY INDUSTRY
-
Resources
- EXPLORE BY TOPIC
- EXPLORE BY TYPE
- SUPPORT & SERVICES
-
Open Source
- COMMUNITY
- PROGRAMS
- REPOSITORIES
-
Enterprise
Search or jump to...
Search code, repositories, users, issues, pull requests...
Search
Clear
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.
Cancel Create saved search
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 }}
- Notifications You must be signed in to change notification settings
- Fork 2
- Star 6
A simple Forth in Lua for embedded usage.
License
6 stars 2 forks Branches Tags Activity
Notifications You must be signed in to change notification settings
Additional navigation options
vifino/luaforth
master
Go to file
Code
Open more actions menu
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
| Latest commit History27 Commits 27 Commits | ||||
| bin | bin | |||
| tests | tests | |||
| .travis.yml | .travis.yml | |||
| LICENSE | LICENSE | |||
| Makefile | Makefile | |||
| README.md | README.md | |||
| app.lua | app.lua | |||
| auto-run-tests-on-change.sh | auto-run-tests-on-change.sh | |||
| luaforth.lua | luaforth.lua | |||
| View all files |
Repository files navigation
luaforth
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
require/load luaforth.- Create an environment.
- Call
new_stack, new_environment = luaforth.eval(program_source, environment[, stack, program_source_start_position]).
Tada!
Example
See luaforth.simple_env here 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
Resources
License
Uh oh!
There was an error while loading. Please reload this page.
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published
Contributors 2
Uh oh!
There was an error while loading. Please reload this page.
Languages
- Lua 95.7%
- Forth 3.0%
- Other 1.3%
Footer
© 2026 GitHub, Inc.
Footer navigation
- Terms
- Privacy
- Security
- Status
- Community
- Docs
- Contact
- Manage cookies
- Do not share my personal information
You can’t perform that action at this time.