Magpie Stuff
  • Getting Lua working with Pico

    Moved
    Lua Pedal
    1 2 15

    replicatR
    20
    1

    Compile Lua for pico

    • Cross compile for pico
    • Ensure that all unneeded libs are removed
      • I think all we really need is math

    Example Lua code

    #include <stdio.h>
    #include "pico/stdlib.h"
    #include "lua.h"
    #include "lauxlib.h"
    #include "lualib.h"
    
    void run_lua_script() {
        lua_State *L = luaL_newstate();  // Create a new Lua state
        luaL_openlibs(L);               // Open Lua standard libraries
    
        // Lua script as a string
        const char *lua_script = "print('Hello from Lua on Pico!')";
    
        // Execute the Lua script
        if (luaL_dostring(L, lua_script)) {
            printf("Error: %s\n", lua_tostring(L, -1));
        }
    
        lua_close(L);  // Close the Lua state
    }
    
    int main() {
        stdio_init_all();
        printf("Starting Lua on Raspberry Pi Pico...\n");
    
        run_lua_script();
    
        while (true) {
            // Keep the program running
            sleep_ms(1000);
        }
    
        return 0;
    }
    

    Potential CMake example

    cmake_minimum_required(VERSION 3.13)
    include(pico_sdk_import.cmake)
    
    project(lua_pico_project)
    
    pico_sdk_init()
    
    add_executable(lua_pico
        main.c
        lua.c       # Add all Lua source files here
        lapi.c
        lcode.c
        ldebug.c
        ldo.c
        ldump.c
        lfunc.c
        lgc.c
        llex.c
        lmem.c
        lobject.c
        lopcodes.c
        lparser.c
        lstate.c
        lstring.c
        ltable.c
        ltm.c
        lundump.c
        lvm.c
        lzio.c
        lauxlib.c
        lbaselib.c
        lbitlib.c
        lcorolib.c
        ldblib.c
        liolib.c
        lmathlib.c
        loslib.c
        lstrlib.c
        ltablib.c
        lutf8lib.c
        loadlib.c
        linit.c
    )
    
    target_link_libraries(lua_pico pico_stdlib)
    
    pico_add_extra_outputs(lua_pico)
    
  • AnalogWeaponA AnalogWeapon moved this topic from on