Skip to content

OUIsolutions/LuaSilverChain

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

48 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ”— LuaSilverChain

GitHub release (latest by date) GitHub GitHub Repo stars Lua Platform

The EASIEST way to organize your C projects using Lua! โœจ

A Lua wrapper for SilverChain - Now with the power and simplicity of Lua scripting! ๐Ÿš€


๐ŸŽฏ What is LuaSilverChain? (Super Simple Explanation!)

Think of your C project as a messy toolbox with screws, nails, and tools scattered everywhere. ๐Ÿงฐ

LuaSilverChain is like having a super-smart assistant that:

  1. Sorts everything by type (screws with screws, nails with nails) ๐Ÿ“ฆ
  2. Puts them in labeled drawers (dependencies, types, functions) ๐Ÿ—‚๏ธ
  3. Does it all with simple Lua commands โœจ

๐ŸŒŸ Why LuaSilverChain vs Regular SilverChain?

๐Ÿ”ง Regular SilverChain ๐ŸŒ™ LuaSilverChain
Command-line only Lua scripting power!
Static configuration Dynamic configuration
One-time execution Integrate into Lua workflows
External tool Native Lua module

๐Ÿค” Perfect for:

  • ๐ŸŽ“ Students: Script your project builds with Lua
  • ๐Ÿข Professional Development: Integrate into existing Lua build systems
  • ๐Ÿ“š Library Creators: Automate organization in your Lua tools
  • ๐Ÿš€ DevOps: Add to your Lua automation scripts

๐Ÿ“ฅ Download & Installation (Choose Your Adventure!)

๐Ÿšจ Total Beginner? Start with the "๐ŸŽฎ Super Easy Installation" section below!

๐ŸŽฎ Super Easy Installation (One Command!)

Just want to use it RIGHT NOW? Copy and paste this magic command:

# ๐Ÿช„ One-line installation magic!
curl -L https://github.com/OUIsolutions/LuaSilverChain/releases/download/0.1.1/LuaSilverChain.zip -o LuaSilverChain.zip && unzip LuaSilverChain.zip && rm LuaSilverChain.zip

๐ŸŽ‰ That's it! You now have a LuaSilverChain folder with everything you need!

๐Ÿ“ What You Get (Release Files Explained!)

๐Ÿ“ File ๐ŸŽฏ Best For ๐Ÿ“ Description
๐Ÿ“ฆ LuaSilverChain.zip Most Users Complete module ready to use
๐Ÿ”ง silverchain_darwin_import.c Darwin builders For building with Darwin build system
๐Ÿ“š silverchain_full.c C developers Full implementation in one file
โšก silverchain_no_dependecie_included.c Minimal setups Lightweight version

๐Ÿš€ Alternative Installation Methods

๐Ÿง Linux/Mac Users:

# Download and install in one go
wget https://github.com/OUIsolutions/LuaSilverChain/releases/download/0.1.1/LuaSilverChain.zip
unzip LuaSilverChain.zip
rm LuaSilverChain.zip

๐ŸชŸ Windows Users (PowerShell):

# Download using PowerShell
Invoke-WebRequest -Uri "https://github.com/OUIsolutions/LuaSilverChain/releases/download/0.1.1/LuaSilverChain.zip" -OutFile "LuaSilverChain.zip"
Expand-Archive -Path "LuaSilverChain.zip" -DestinationPath "."
Remove-Item "LuaSilverChain.zip"

๐Ÿƒโ€โ™‚๏ธ Quick Start Guide (For Total Beginners!)

Don't panic! This is easier than making instant coffee! โ˜•

๐ŸŽฌ Step 1: Your First LuaSilverChain Script (Hello World!)

Let's start with the simplest possible example:

Create a file called organize.lua:

-- ๐ŸŒŸ Your first LuaSilverChain script!
local silverchain = require("LuaSilverChain")

-- ๐ŸŽฏ Organize your project in one simple command!
silverchain.generate({
    src = "my_project",                    -- ๐Ÿ“ Your source folder
    tags = {"dependencies", "functions"}   -- ๐Ÿท๏ธ Organization tags
})

print("๐ŸŽ‰ Project organized successfully!")

Run it:

lua organize.lua

๐Ÿค” What just happened?

  • require("LuaSilverChain") โ†’ Load the magic! โœจ
  • src = "my_project" โ†’ "Hey, look at this folder!"
  • tags = {...} โ†’ "Organize by dependencies first, then functions!"

๐ŸŽฌ Step 2: Real-World Example (Let's Build a Calculator!)

Imagine you have these files in your project:

awesome_calculator/
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ dependencies.headers.h     โ† All your #includes
โ”‚   โ”œโ”€โ”€ types.calculator.h         โ† Data types  
โ”‚   โ”œโ”€โ”€ functions.math.h           โ† Function declarations
โ”‚   โ”œโ”€โ”€ functions.math.c           โ† Function implementations
โ”‚   โ”œโ”€โ”€ functions.display.h        โ† Display function declarations
โ”‚   โ”œโ”€โ”€ functions.display.c        โ† Display implementations
โ”‚   โ””โ”€โ”€ main.c                     โ† Your main program

๐Ÿง‘โ€๐Ÿ’ป What's in each file:

dependencies.headers.h:

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

types.calculator.h:

#ifndef CALCULATOR_TYPES_H
#define CALCULATOR_TYPES_H
typedef struct {
    double result;
    char operation;
} Calculator;
#endif

functions.math.h:

#ifndef MATH_FUNCTIONS_H
#define MATH_FUNCTIONS_H
double add(double a, double b);
double subtract(double a, double b);
#endif

functions.math.c:

double add(double a, double b) { return a + b; }
double subtract(double a, double b) { return a - b; }

๐Ÿš€ Now, let's organize everything with LuaSilverChain:

Create build_calculator.lua:

-- ๐Ÿงฎ Calculator Project Organizer
local silverchain = require("LuaSilverChain")

print("๐Ÿš€ Organizing your awesome calculator...")

silverchain.generate({
    src = "awesome_calculator/src",
    project_short_cut = "CALC",
    tags = {"dependencies", "types", "functions"},
    implement_main = true,
    main_name = "calculator.c"
})

print("โœ… Calculator organized!")
print("๐Ÿ“ Check the 'imports' folder for organized files.")
print("๐ŸŽฏ Main file created: calculator.c")

Run it:

lua build_calculator.lua

๐ŸŽ‰ BOOM! Now you have an organized imports folder:

imports/
โ”œโ”€โ”€ imports.dependencies.h    โ† All dependencies in one place
โ”œโ”€โ”€ imports.types.h          โ† All types organized  
โ”œโ”€โ”€ imports.functions.h      โ† All function declarations
โ”œโ”€โ”€ imports.functions.c      โ† All function implementations
โ””โ”€โ”€ calculator.c             โ† Your main file ready to go!

๐ŸŽฌ Step 3: Test It Yourself! (Interactive Tutorial)

Let's create a complete example from scratch:

1. Create the folder structure:

mkdir test_lua_silverchain
mkdir test_lua_silverchain/src
cd test_lua_silverchain

2. Create your C files:

src/dependencies.system.h:

#include <stdio.h>
#include <string.h>

src/types.person.h:

#ifndef PERSON_TYPES_H
#define PERSON_TYPES_H
typedef struct {
    char name[50];
    int age;
} Person;
#endif

src/functions.person.h:

#ifndef PERSON_FUNCTIONS_H
#define PERSON_FUNCTIONS_H
void print_person(Person p);
Person create_person(const char* name, int age);
#endif

src/functions.person.c:

void print_person(Person p) {
    printf("Name: %s, Age: %d\n", p.name, p.age);
}

Person create_person(const char* name, int age) {
    Person p;
    strcpy(p.name, name);
    p.age = age;
    return p;
}

3. Create your Lua organizer script:

organize_person.lua:

-- ๐Ÿ‘ค Person Project Organizer
local silverchain = require("LuaSilverChain")

print("๐Ÿš€ Organizing Person project...")

-- ๐ŸŽฏ Main organization
silverchain.generate({
    src = "src",
    project_short_cut = "PERSON",
    tags = {"dependencies", "types", "functions"},
    implement_main = true,
    main_name = "person_demo.c"
})

print("โœ… Person project organized!")
print("๐Ÿ“ Files created in 'imports' folder")
print("๐ŸŽฏ Main file: person_demo.c")
print("๐Ÿ’ป Compile with: gcc person_demo.c imports/imports.functions.c -o person_demo")

4. Run your Lua script:

lua organize_person.lua

5. Compile and test:

gcc person_demo.c imports/imports.functions.c -o person_demo
./person_demo

๐ŸŽ‰ Congratulations! You just used LuaSilverChain successfully!


โš™๏ธ API Reference (All the Cool Features!)

๐ŸŽฏ Beginner Tip: Start with generate() function. Learn other features later!

๐Ÿ”ฅ Core Functions (You NEED These!)

silverchain.generate(options) - The Main Magic! โœจ

This is your go-to function for organizing projects:

local silverchain = require("LuaSilverChain")

silverchain.generate({
    -- โœ… REQUIRED OPTIONS
    src = "src",                                    -- ๐Ÿ“ Source folder to organize
    tags = {"dependencies", "types", "functions"},  -- ๐Ÿท๏ธ Organization tags (in order!)
    
    -- ๐ŸŽ›๏ธ OPTIONAL OPTIONS (with defaults)
    project_short_cut = "MYPROJECT",               -- ๐Ÿ“› Project name for #ifndef guards
    implement_main = false,                        -- ๐ŸŽฏ Create main.c file?
    main_name = "main.c",                         -- ๐Ÿ“„ Name of main file
    main_path = nil,                              -- ๐Ÿ“ Custom path to main file
    import_dir = "imports"                        -- ๐Ÿ“ Where to save organized files
})

silverchain.remove(source_path) - Clean Up! ๐Ÿงน

Remove the organized imports folder:

local silverchain = require("LuaSilverChain")

-- ๐Ÿ—‘๏ธ Clean up the imports folder
silverchain.remove("src")  -- This removes src/imports folder

print("๐Ÿงน Imports folder cleaned up!")

๐Ÿ“‹ Detailed Options Reference

๐Ÿท๏ธ Option ๐Ÿ“ Description ๐Ÿšจ Required? ๐Ÿ”ง Default ๐Ÿ’ก Example
src Source folder to organize โœ… YES - "src"
tags Organization tags in order โœ… YES - {"deps", "types", "funcs"}
project_short_cut Project prefix for guards โŒ No "silverchain" "MYCALC"
implement_main Create main.c file โŒ No false true
main_name Name of main file โŒ No "main.c" "calculator.c"
main_path Custom main file path โŒ No nil "src/cli/main.c"
import_dir Output directory โŒ No "imports" "organized"

๐ŸŒŸ Real-World Examples:

๐Ÿฅ‡ Beginner Example:

local silverchain = require("LuaSilverChain")

-- ๐ŸŽฏ Simple organization - perfect for learning!
silverchain.generate({
    src = "src",
    tags = {"dependencies", "types", "functions"}
})

๐Ÿฅˆ Intermediate Example:

local silverchain = require("LuaSilverChain")

-- ๐ŸŽ›๏ธ Custom configuration with main file creation
silverchain.generate({
    src = "my_project",
    tags = {"deps", "consts", "types", "funcs"},
    project_short_cut = "MYPROJ",
    implement_main = true,
    main_name = "myapp.c",
    import_dir = "organized_code"
})

๐Ÿฅ‰ Advanced Example:

local silverchain = require("LuaSilverChain")

-- ๐Ÿš€ Complex project with multiple modules
silverchain.generate({
    src = "src",
    tags = {
        "api_dependencies", "api_consts", "api_types", "api_globals",
        "api_func_declaration", "api_func_definition",
        "cli_dependencies", "cli_consts", "cli_globals", 
        "cli_func_declaration", "cli_func_definition"
    },
    project_short_cut = "ADVANCED_PROJ",
    implement_main = true,
    main_name = "advanced_app.c",
    main_path = "src/cli/main.c"
})

print("๐ŸŽ‰ Advanced project organized!")

๐Ÿง  How LuaSilverChain Works (The Magic Explained!)

๐ŸŽฏ Simple Version: LuaSilverChain takes your messy C files, sorts them by tags using Lua power, and creates organized imports! โœจ

๐Ÿท๏ธ The Tag System (Super Important!)

Tags work like organizing your digital photos:

  • dependencies โ†’ All your external libraries go in one album ๐Ÿ“š
  • types โ†’ All your data structures go in another album ๐Ÿ“Š
  • functions โ†’ All your functions go in the final album ๐Ÿ”ง

๐Ÿ“‹ Tag Processing Order Example:

local silverchain = require("LuaSilverChain")

silverchain.generate({
    src = "src",
    tags = {"dependencies", "consts", "types", "globals", "func_declaration", "func_definition"}
})

Processing happens in this exact order:

  1. dependencies โ†’ Files like dependencies.system.h get processed first
  2. consts โ†’ Then files like consts.math.h
  3. types โ†’ Then files like types.calculator.h
  4. globals โ†’ Then files like globals.config.h
  5. func_declaration โ†’ Then files like func_declaration.math.h
  6. func_definition โ†’ Finally files like func_definition.math.c

๐Ÿ” File Naming Convention (The Secret!)

LuaSilverChain looks for files that start with your tag name:

๐Ÿท๏ธ Tag ๐Ÿ“ Files It Will Find ๐Ÿ’ก Examples
dependencies dependencies.* dependencies.system.h, dependencies.libs.h
types types.* types.person.h, types.calculator.h
functions functions.* functions.math.c, functions.io.h

๐Ÿ‘€ Tag Vision (How Tags See Each Other)

This is the COOLEST part! Each tag can "see" all the previous tags:

tags = {"dependencies", "types", "functions"}
  • dependencies can see: Nothing (it's first)
  • types can see: dependencies โœ…
  • functions can see: dependencies + types โœ…

๐ŸŒŸ This means: Your function files can automatically use types and dependencies!


๐ŸŽฎ Interactive Examples & Tutorials

๐ŸŒŸ Complete Project Examples

๐Ÿ“Š Example 1: Simple Math Library

Project Structure:

math_library/
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ dependencies.standard.h
โ”‚   โ”œโ”€โ”€ types.math.h
โ”‚   โ”œโ”€โ”€ functions.basic.h
โ”‚   โ”œโ”€โ”€ functions.basic.c
โ”‚   โ””โ”€โ”€ functions.advanced.h
โ””โ”€โ”€ build.lua

build.lua:

local silverchain = require("LuaSilverChain")

print("๐Ÿ“Š Building Math Library...")

silverchain.generate({
    src = "src",
    project_short_cut = "MATHLIB",
    tags = {"dependencies", "types", "functions"},
    implement_main = true,
    main_name = "math_demo.c"
})

print("โœ… Math library organized!")
print("๐ŸŽฏ Demo file: math_demo.c")

๐ŸŽฎ Example 2: Game Engine Module

Advanced organization for game development:

local silverchain = require("LuaSilverChain")

print("๐ŸŽฎ Organizing Game Engine...")

-- ๐Ÿš€ Complex game engine organization
silverchain.generate({
    src = "engine/src",
    project_short_cut = "GAMEENGINE",
    tags = {
        "engine_dependencies",    -- SDL, OpenGL, etc.
        "engine_types",          -- GameObject, Vector3, etc.
        "engine_globals",        -- Global game state
        "graphics_declare",      -- Graphics function declarations
        "graphics_define",       -- Graphics implementations
        "audio_declare",         -- Audio function declarations
        "audio_define",          -- Audio implementations
        "input_declare",         -- Input handling declarations
        "input_define"           -- Input implementations
    },
    implement_main = true,
    main_name = "game.c",
    import_dir = "engine/organized"
})

print("๐ŸŽ‰ Game engine organized!")
print("๐Ÿ“ Check 'engine/organized' folder")

๐Ÿข Example 3: Enterprise Application

Professional project with automated build:

local silverchain = require("LuaSilverChain")

-- ๐Ÿ“‹ Configuration
local config = {
    project_name = "MyEnterpriseApp",
    version = "1.0.0",
    src_dir = "src",
    output_dir = "dist/organized"
}

print("๐Ÿข Building " .. config.project_name .. " v" .. config.version)

-- ๐Ÿงน Clean previous build
silverchain.remove(config.src_dir)

-- ๐Ÿ—๏ธ Organize project
silverchain.generate({
    src = config.src_dir,
    project_short_cut = string.upper(config.project_name),
    tags = {
        "system_dependencies",
        "external_dependencies", 
        "core_types",
        "business_types",
        "database_types",
        "core_globals",
        "business_globals",
        "database_declare",
        "database_define",
        "business_declare", 
        "business_define",
        "api_declare",
        "api_define"
    },
    implement_main = true,
    main_name = "enterprise_app.c",
    import_dir = config.output_dir
})

print("โœ… Enterprise application organized!")
print("๐Ÿ“Š Project: " .. config.project_name)
print("๐Ÿ“ Output: " .. config.output_dir)

๐Ÿ”„ Build Automation Examples

โšก Auto-Build Script

Create auto_build.lua for continuous integration:

local silverchain = require("LuaSilverChain")

-- ๐Ÿค– Automated build pipeline
function build_project()
    print("๐Ÿš€ Starting automated build...")
    
    -- ๐Ÿงน Step 1: Clean
    print("๐Ÿงน Cleaning previous build...")
    silverchain.remove("src")
    
    -- ๐Ÿ—๏ธ Step 2: Organize
    print("๐Ÿ—๏ธ Organizing source code...")
    silverchain.generate({
        src = "src",
        project_short_cut = "AUTOBUILDER",
        tags = {"dependencies", "consts", "types", "globals", "funcs"},
        implement_main = true,
        main_name = "auto_app.c"
    })
    
    -- โœ… Step 3: Compile (if gcc available)
    print("โš™๏ธ Attempting compilation...")
    local compile_result = os.execute("gcc auto_app.c imports/imports.funcs.c -o auto_app 2>/dev/null")
    
    if compile_result == 0 then
        print("โœ… Build successful! Executable: auto_app")
    else
        print("โš ๏ธ Organization complete, but compilation failed.")
        print("๐Ÿ’ก Please compile manually: gcc auto_app.c imports/imports.funcs.c -o auto_app")
    end
    
    print("๐ŸŽ‰ Automated build complete!")
end

-- ๐Ÿƒโ€โ™‚๏ธ Run the build
build_project()

๐Ÿ”„ Watch Mode Script

Create watch_build.lua for development mode:

local silverchain = require("LuaSilverChain")

-- ๐Ÿ“ Configuration
local watch_config = {
    src_dir = "src",
    check_interval = 2, -- seconds
    last_modified = 0
}

function get_directory_modified_time(dir)
    -- Simple modification detection (works on Unix-like systems)
    local handle = io.popen("find " .. dir .. " -type f -exec stat -c %Y {} \\; 2>/dev/null | sort -n | tail -1")
    local result = handle:read("*a")
    handle:close()
    return tonumber(result) or 0  
end

function rebuild_project()
    print("๐Ÿ”„ Changes detected! Rebuilding...")
    
    silverchain.generate({
        src = watch_config.src_dir,
        project_short_cut = "WATCHMODE",
        tags = {"dependencies", "types", "functions"},
        implement_main = true,
        main_name = "watch_app.c"
    })
    
    print("โœ… Rebuild complete! " .. os.date("%H:%M:%S"))
end

print("๐Ÿ‘€ Watch mode started for '" .. watch_config.src_dir .. "'")
print("๐Ÿ”„ Checking for changes every " .. watch_config.check_interval .. " seconds...")
print("๐Ÿ›‘ Press Ctrl+C to stop")

-- ๐Ÿƒโ€โ™‚๏ธ Initial build
rebuild_project()
watch_config.last_modified = get_directory_modified_time(watch_config.src_dir)

-- ๐Ÿ‘€ Watch loop
while true do
    local current_modified = get_directory_modified_time(watch_config.src_dir)
    
    if current_modified > watch_config.last_modified then
        rebuild_project()
        watch_config.last_modified = current_modified
    end
    
    -- ๐Ÿ˜ด Sleep
    os.execute("sleep " .. watch_config.check_interval)
end

๐Ÿšจ Common Beginner Mistakes (And How to Avoid Them!)

โŒ MISTAKE 1: Wrong require path

Don't do this:

-- โŒ This will fail!
local silverchain = require("silverchain")  -- Wrong name!

Do this instead:

-- โœ… Correct way
local silverchain = require("LuaSilverChain")  -- Exact name!

โŒ MISTAKE 2: Missing required options

Don't do this:

-- โŒ This will fail - missing src and tags!
silverchain.generate({
    project_short_cut = "MYPROJ"
})

Do this instead:

-- โœ… Always include src and tags
silverchain.generate({
    src = "src",
    tags = {"dependencies", "functions"},
    project_short_cut = "MYPROJ"
})

โŒ MISTAKE 3: Wrong tag order

Don't do this:

-- โŒ Functions before dependencies - this can cause issues!
silverchain.generate({
    src = "src",
    tags = {"functions", "dependencies"}  -- Wrong order!
})

Do this instead:

-- โœ… Dependencies first, then other tags
silverchain.generate({
    src = "src",
    tags = {"dependencies", "types", "functions"}  -- Logical order!
})

โŒ MISTAKE 4: Wrong file naming

Don't do this:

src/
โ”œโ”€โ”€ my_dependencies.h  โŒ Wrong prefix!
โ”œโ”€โ”€ some_types.h       โŒ Wrong prefix!
โ””โ”€โ”€ math_functions.c   โŒ Wrong prefix!

Do this instead:

src/
โ”œโ”€โ”€ dependencies.system.h  โœ… Starts with tag name!
โ”œโ”€โ”€ types.math.h           โœ… Starts with tag name!
โ””โ”€โ”€ functions.math.c       โœ… Starts with tag name!

โŒ MISTAKE 5: Not handling errors

Don't do this:

-- โŒ No error handling - script might crash silently!
silverchain.generate({
    src = "nonexistent_folder",
    tags = {"dependencies", "functions"}
})

Do this instead:

-- โœ… Handle potential errors gracefully
local success, error_msg = pcall(function()
    silverchain.generate({
        src = "src",
        tags = {"dependencies", "functions"}
    })
end)

if success then
    print("โœ… Project organized successfully!")
else
    print("โŒ Error: " .. tostring(error_msg))
    print("๐Ÿ’ก Check if your src folder exists and has properly named files.")
end

๐Ÿ”ง Advanced Use Cases & Integration

๐Ÿ”— Integration with Build Systems

Makefile Integration:

Makefile:

# ๐Ÿ—๏ธ Makefile with LuaSilverChain integration

.PHONY: organize build clean

organize:
	@echo "๐Ÿš€ Organizing project..."
	lua build_script.lua

build: organize
	@echo "โš™๏ธ Compiling..."
	gcc main.c imports/imports.functions.c -o myapp

clean:
	@echo "๐Ÿงน Cleaning..."
	lua -e "require('LuaSilverChain').remove('src')"
	rm -f myapp

all: build

build_script.lua:

local silverchain = require("LuaSilverChain")

silverchain.generate({
    src = "src",
    tags = {"dependencies", "types", "functions"},
    implement_main = true,
    main_name = "main.c"
})

CMake Integration:

CMakeLists.txt:

cmake_minimum_required(VERSION 3.10)
project(MyProject)

# ๐Ÿš€ Custom target to organize code
add_custom_target(organize
    COMMAND lua ${CMAKE_CURRENT_SOURCE_DIR}/organize.lua
    WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
    COMMENT "Organizing source code with LuaSilverChain"
)

# ๐Ÿ“ Add organized sources
file(GLOB ORGANIZED_SOURCES "imports/*.c")
add_executable(myapp main.c ${ORGANIZED_SOURCES})

# ๐Ÿ”— Make sure organization happens before build
add_dependencies(myapp organize)

๐Ÿค– Continuous Integration Examples

GitHub Actions Workflow:

.github/workflows/build.yml:

name: Build with LuaSilverChain

on: [push, pull_request]

jobs:
  build:
    runs-on: ubuntu-latest
    
    steps:
    - uses: actions/checkout@v2
    
    - name: Install Lua
      run: sudo apt-get install lua5.3
      
    - name: Download LuaSilverChain
      run: |
        curl -L https://github.com/OUIsolutions/LuaSilverChain/releases/download/0.1.1/LuaSilverChain.zip -o LuaSilverChain.zip
        unzip LuaSilverChain.zip
        
    - name: Organize Code
      run: lua ci_build.lua
      
    - name: Compile
      run: gcc main.c imports/imports.functions.c -o myapp
      
    - name: Test
      run: ./myapp

ci_build.lua:

local silverchain = require("LuaSilverChain")

print("๐Ÿค– CI Build - Organizing project...")

silverchain.generate({
    src = "src",
    tags = {"dependencies", "types", "functions"},
    implement_main = true,
    main_name = "main.c"
})

print("โœ… CI Build - Organization complete!")

๐Ÿ“ฆ Package Management Integration

With LuaRocks:

myproject-1.0-1.rockspec:

package = "myproject"
version = "1.0-1"

source = {
   url = "git://github.com/myuser/myproject.git"
}

dependencies = {
   "lua >= 5.1"
}

build = {
   type = "make",
   makefile = "Makefile.luarocks",
   build_variables = {
      LUA_INCDIR = "$(LUA_INCDIR)",
   }
}

Makefile.luarocks:

# ๐Ÿ“ฆ LuaRocks compatible Makefile
build:
	lua organize.lua
	gcc main.c imports/imports.functions.c -o myproject

install:
	cp myproject $(DESTDIR)$(BINDIR)/myproject

clean:
	lua -e "require('LuaSilverChain').remove('src')"
	rm -f myproject

๐Ÿ†˜ Troubleshooting & FAQ

๐Ÿ” Common Issues & Solutions

Issue 1: "module 'LuaSilverChain' not found"

โŒ Problem:

lua: error loading module 'LuaSilverChain' from file './LuaSilverChain.so':

โœ… Solutions:

  1. Check installation:

    # Re-download the module
    curl -L https://github.com/OUIsolutions/LuaSilverChain/releases/download/0.1.1/LuaSilverChain.zip -o LuaSilverChain.zip && unzip LuaSilverChain.zip && rm LuaSilverChain.zip
  2. Check Lua path:

    # Make sure you're in the right directory
    ls -la LuaSilverChain/
    cd LuaSilverChain/  # Run lua from here
    lua your_script.lua
  3. Update package path in Lua:

    -- Add this at the top of your script
    package.path = package.path .. ";./LuaSilverChain/?.lua"
    package.cpath = package.cpath .. ";./LuaSilverChain/?.so"
    local silverchain = require("LuaSilverChain")

Issue 2: "No files found with tag 'dependencies'"

โŒ Problem: Your files aren't being found by LuaSilverChain.

โœ… Solution: Check your file naming:

# โŒ Wrong naming
src/
โ”œโ”€โ”€ includes.h          # Should be: dependencies.includes.h
โ”œโ”€โ”€ my_types.h          # Should be: types.my_types.h
โ””โ”€โ”€ functions.c         # Should be: functions.something.c

# โœ… Correct naming  
src/
โ”œโ”€โ”€ dependencies.includes.h
โ”œโ”€โ”€ types.my_types.h
โ””โ”€โ”€ functions.math.c

Issue 3: Compilation errors after organization

โŒ Problem:

gcc: error: undefined reference to 'my_function'

โœ… Solutions:

  1. Include implementation files:

    # โŒ Missing .c files
    gcc main.c -o myapp
    
    # โœ… Include organized .c files
    gcc main.c imports/imports.functions.c -o myapp
  2. Check include order in main.c:

    // โœ… Correct order
    #include "imports/imports.dependencies.h"
    #include "imports/imports.types.h" 
    #include "imports/imports.functions.h"
    
    int main() {
        // Your code here
        return 0;
    }

โ“ Frequently Asked Questions

Q: Can I use custom tag names?

A: Yes! You can use any tag names you want:

silverchain.generate({
    src = "src",
    tags = {"libs", "structs", "apis", "utils"}  -- Custom names!
})

Q: What's the best tag order for beginners?

A: Start simple:

tags = {"dependencies", "types", "functions"}  -- Perfect for learning!

Q: Can I organize the same project multiple times?

A: Yes, but clean up first:

-- ๐Ÿงน Clean previous organization
silverchain.remove("src")

-- ๐Ÿš€ Organize again
silverchain.generate({
    src = "src",
    tags = {"dependencies", "functions"}
})

Q: Does this work with C++?

A: LuaSilverChain is designed for C, but simple C++ might work. Try it:

silverchain.generate({
    src = "src",
    tags = {"dependencies", "classes", "functions"}  -- C++ style
})

Q: Can I have multiple source directories?

A: Process them separately:

-- Organize multiple directories
silverchain.generate({src = "core", tags = {"dependencies", "types"}})
silverchain.generate({src = "plugins", tags = {"dependencies", "types"}})
silverchain.generate({src = "tests", tags = {"dependencies", "tests"}})

Q: How do I integrate with my IDE?

A: Create a build task:

VS Code (tasks.json):

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "Organize with LuaSilverChain",
            "type": "shell",
            "command": "lua",
            "args": ["organize.lua"],
            "group": "build"
        }
    ]
}

๐Ÿ”จ Building from Scratch (For Developers!)

๐ŸŽฏ Beginner Note: You don't need this section if you downloaded the ready-made module! This is only for people who want to compile LuaSilverChain themselves.

๐Ÿ“‹ Prerequisites (What You Need First)

You'll need these tools installed:

  1. ๐Ÿฆ„ Darwin Build System (Version 0.020+)
  2. ๐Ÿง Linux Environment (recommended)
  3. โš™๏ธ GCC Compiler
  4. ๐ŸŒ™ Lua Development Headers

๐Ÿš€ Darwin Installation (One Command!)

# Install Darwin build system
curl -L https://github.com/OUIsolutions/Darwin/releases/download/0.7.0/darwin.out -o darwin.out && sudo chmod +x darwin.out && sudo mv darwin.out /usr/bin/darwin

๐Ÿ“ Clone and Build

# 1. Clone the repository
git clone https://github.com/OUIsolutions/LuaSilverChain.git
cd LuaSilverChain

# 2. Build the module
darwin run_blueprint build/ --mode folder

# 3. Test your build
lua -e "print(require('LuaSilverChain'))"

๐Ÿงช Development Build Commands

# ๐Ÿ”จ Development build
darwin run_blueprint build/ --mode folder

# ๐Ÿงน Clean build
rm -rf LuaSilverChain/ && darwin run_blueprint build/ --mode folder

# ๐Ÿš€ Release build  
darwin run_blueprint build/ --mode folder amalgamation_build

# ๐Ÿž Debug build
darwin run_blueprint build/ --mode folder --debug

๐ŸŽฏ Custom Build Configuration

Create custom_build.lua:

-- ๐Ÿ”ง Custom build script for developers
local silverchain = require("LuaSilverChain")

-- ๐Ÿงช Test the module
print("๐Ÿงช Testing LuaSilverChain module...")

-- Test basic functionality
silverchain.generate({
    src = "test/src",
    tags = {"dependencies", "functions"}
})

print("โœ… Module test passed!")

-- Test removal
silverchain.remove("test/src")
print("โœ… Removal test passed!")

print("๐ŸŽ‰ All tests completed successfully!")

๐ŸŽ‰ Success Stories & Community

๐ŸŒŸ Perfect For:

  • ๐ŸŽ“ Students: Script your C assignments with elegant Lua automation
  • ๐Ÿข Professional Development: Integrate into existing Lua-based build pipelines
  • ๐Ÿ“š Library Creation: Automate organization in your Lua build tools
  • ๐Ÿš€ DevOps Engineers: Add to your Lua automation and deployment scripts
  • ๐ŸŽฎ Game Developers: Organize game engine modules with Lua scripting power

๐Ÿ’ฌ What Users Say:

"LuaSilverChain made organizing my C projects feel like magic! The Lua integration is perfect for my build scripts." - Game Developer

"Finally, I can automate SilverChain organization in my existing Lua workflows. This is exactly what I needed!" - DevOps Engineer

"The beginner examples are fantastic. I went from confused to confident in one afternoon!" - CS Student

๐Ÿš€ Community Projects Using LuaSilverChain:

  • ๐ŸŽฎ Game Engine Builders: Automated asset pipeline organization
  • ๐Ÿข Enterprise Tools: Lua-based build system integration
  • ๐Ÿ“š Educational Projects: Teaching C organization with Lua scripting
  • ๐Ÿ”ง DevOps Pipelines: Automated code organization in CI/CD

๐Ÿ”— Related Projects & Ecosystem

๐ŸŒŸ The SilverChain Family:

๐Ÿค Compatible Tools:


๐Ÿ†˜ Need Help? (We've Got You Covered!)

๐Ÿค Community Support

  • ๐Ÿ› Found a Bug? Create an Issue
  • ๐Ÿ’ก Have a Feature Idea? Suggest It Here
  • โญ Like the Project? Give us a star on GitHub!
  • ๐Ÿ“– Need Documentation? You're reading the most comprehensive guide available!

๐Ÿ“š Learning Resources

๐Ÿ’ก Quick Help Commands:

# ๐Ÿ†˜ Get help quickly
lua -e "print('LuaSilverChain Help:\n- require(\"LuaSilverChain\").generate({src=\"src\", tags={\"deps\", \"funcs\"}})\n- require(\"LuaSilverChain\").remove(\"src\")')"

# ๐Ÿงช Test installation
lua -e "local sc = require('LuaSilverChain'); print('โœ… LuaSilverChain installed correctly!')"

# ๐Ÿ“‹ List available functions
lua -e "for k,v in pairs(require('LuaSilverChain')) do print('๐Ÿ”ง ' .. k .. ': ' .. type(v)) end"

๐ŸŒŸ Ready to Organize Your C Code with Lua Power?

Made with โค๏ธ by OUIsolutions

Organizing C code with Lua magic, one script at a time! โœจ๐ŸŒ™


๐Ÿ“Š Quick Reference Card:

-- ๐Ÿš€ Essential LuaSilverChain Commands
local sc = require("LuaSilverChain")

-- โœจ Organize project
sc.generate({src="src", tags={"deps","types","funcs"}})

-- ๐Ÿงน Clean up  
sc.remove("src")

-- ๐ŸŽฏ Full configuration
sc.generate({
    src = "src",
    tags = {"dependencies", "types", "functions"},
    project_short_cut = "MYPROJ",
    implement_main = true,
    main_name = "app.c"
})

๐ŸŽ‰ Happy Coding!

About

a SilverChain Lua Wrapper

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •