Skip to content
Amrit Bhogal edited this page May 30, 2022 · 10 revisions

Welcome to the LuaOS wiki!

Check out Proposal for Study for a general manifesto.

This wiki contains documentation about the LuaOS kernel, as well as research, purpose and discussion of the project, in line with the Science 10E fair guidelines

Introduction

LuaOS is an idea I had on a whim one day. What if an operating system could be (partially) programmed in a higher level scripting language, with tedious parts abstracted away by the lower level part of the OS? And with that, LuaOS was born.

Why Lua?

I chose Lua as the language of choice for this OS because of it's immense qualities over the competition of scripting languages. Embedding Lua into any project is extremely simple, requiring < 10 lines of C code.

 #include <stdio.h>
 #include <lua.h>
 #include <lualib.h>
 #include <lauxlib.h>
 
 int main()
 {
    /* Create VM state */
    lua_State *lua = luaL_newstate();
    if (!lua) return 1;
    luaL_openlibs(lua); /* Open standard libraries */
    char *script = "print(\"Hello, world!\");";
    //Through loading and then execution
    if(luaL_loadstring(lua, script) == LUA_OK)
    {
        //Call the code, and if it was ok, push the code off of the stack
        if (lua_pcall(lua, 0, 0, 0) == LUA_OK) {
            lua_pop(lua, lua_gettop(lua));
        }
    }
    //or through direct
    luaL_dostring(lua, script);
    lua_close(lua);
    return 0;
 }

Furthermore, it is very simple for adding special objects and data structures to the Lua state, which makes it very easy too add extra APIs and integration with your program.

On top of all this, Lua is unbelievably fast, reaching speeds as fast as native code sometimes.

Lua is perfect for this project, being easy to implement, fast, and well supported, having being used all across the industry for any scripting needs.

Why Limine?

For this project I had originally planned to program my own bootloader which I did successfully complete, which let me set the CPU from 16 bit "Real Mode" into 32 bit "Protected Mode". This let me use up to 4gb of memory, rather than the 32 bytes which was only allowed for booting the machine. My bootloader was poorly documented, with little comments, and very unmaintainable, as it was written in x86 Assembly (Intel > AT&T syntax don't @ me). I had also wanted for this operating system to be in native 64 bits, as that is, and should be, the golden standard for any software these days. Alas, after going mentally insane after my assembler reported an error where there was literally no instructions, I decided to use a 3rd party bootloader. That is when I discovered Stivale2/Limine. Stivale2 is the standard, the protocols to implement a proper 64 bit, stable bootloader, whilst Limine is the implementation of the standard. Limine provides many utilities such as console printing, keyboard and other peripherals management, memory mapping, and much others. Not having to write all of this myself cuts my development time (and increases my sanity) by half.

The Main Idea

The main point of LuaOS is for the development of low level parts of the kernel and operating system to be simple and easy. The tedious parts of accessing the low level APIs that are provided by the kernel are abstracted away into a simple and efficient interface for Lua scripts. Instead of having to deal with interrupts, memory management and pointers, you will have an easy to use and very understandable script which will aim to do the equivalent.

diagram

This project was inspired by CraftOS for ComputerCraft.

Clone this wiki locally