Skip to content

nullidea2602/glos

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GLOS (Go/Lua OS)

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.

Features

  • 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.

Getting Started

Prerequisites

Installation

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

API Reference

File Operations

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()

Environment Variables

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"))

Utility Functions

Lua Function Description Example
clear_screen() Clears the terminal screen. clear_screen()
read_multiline_input() Reads multiple lines until :exit. content = read_multiline_input()

Example Lua Scripts

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.

Usage

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

Contribution

Feel free to fork and improve the project! Contributions, bug reports, and suggestions are welcome.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published