GLOS is a fun experiment in lightweight userland toy OS development that blends Go and Lua, providing a simple yet flexible platform for script execution and file manipulation. It features an in-memory filesystem, environment variables, and a Lua-based command API for seamless interaction.
- Lua Execution: Run Lua scripts interactively.
- In-Memory Filesystem: Store and manage files without persistent disk usage.
- Environment Variables: Set and retrieve key-value pairs within the session.
- Command REPL: A simple shell interface for executing scripts and managing files.
- Sandboxed Execution: Restricted Lua environment for safety.
- Go 1.18+
- GopherLua
Clone the repository and build the project:
git clone https://github.com/yourusername/glos.git
cd glos
go mod tidy
go build .
Run the REPL:
./glos
Lua Function | Description | Example |
---|---|---|
read_file(filename) |
Reads and returns the contents of a file. | content = read_file("test.txt") |
write_file(filename, content) |
Writes content to a file. | write_file("test.txt", "Hello, GLOS!") |
delete_file(filename) |
Deletes a file. | delete_file("test.txt") |
list_files() |
Returns a table of all stored files. | files = list_files() |
Lua Function | Description | Example |
---|---|---|
set_env(name, value) |
Sets an environment variable. | set_env("username", "Alice") |
get_env(name) |
Retrieves an environment variable's value. | print(get_env("username")) |
Lua Function | Description | Example |
---|---|---|
clear_screen() |
Clears the terminal screen. | clear_screen() |
read_multiline_input() |
Reads multiple lines until :exit . |
content = read_multiline_input() |
Several example scripts demonstrate the API usage:
cat.lua
: Reads and prints file contents.ls.lua
: Lists all stored files.rm.lua
: Deletes a specified file.write.lua
: Interactive text input for file writing.clear.lua
: Clears the terminal.help.lua
: Displays basic REPL commands.
Run scripts using the REPL:
glos> run ls.lua
Files in memory:
- test.txt
- script.lua
glos> run write.lua example.txt
Enter content line by line. Type ':exit' to finish.
Hello, world!
:exit
glos> run cat.lua example.txt
Hello, world!
glos> exit
Feel free to fork and improve the project! Contributions, bug reports, and suggestions are welcome.