Skip to content

Instantly share code, notes, and snippets.

@leeonix
leeonix / csv.lua
Created July 5, 2026 23:32
工业级全功能 LPeg CSV 解析与面向对象操作库
-- =====================================================================================
-- Filename: csv.lua
-- Description: 工业级全功能 LPeg CSV 解析与面向对象操作库 (终极无懈可击版)
-- Architecture: 基于 Parsing Expression Grammars (LPeg) 的纯 Lua 极速解析引擎
--
-- 核心工业级特性:
-- 1. 极致性能优化:将常用全局函数全面局部变量化 (Localize Globals),消除虚拟机高频查找开销。
-- 2. 强力防静默截断:在 LPeg 主文法尾部引入严格的 EOF (* -1) 锚定,杜绝语法畸变时静默产出残缺数据。
-- 3. 幽灵空行斩断:采用负向前瞻断言 -(nl + -1) 与空行海绵 nl^1,从文法底层斩断 {""} 幽灵行。
-- 4. 防死循环编译保护:标准行强制绑定 nl^1,静态保证 ^0 循环至少消耗 1 字符,彻底杜绝 LPeg 编译报错。
@leeonix
leeonix / ini.lua
Created July 5, 2026 23:31
工业级全功能 LPeg INI 配置解析、修改与序列化引擎
-- =====================================================================================
-- Filename: ini.lua
-- Description: 工业级全功能 LPeg INI 配置解析、修改与序列化引擎 (终极无懈可击版)
-- Architecture: 基于 Parsing Expression Grammars (LPeg) 的纯 Lua 极速状态机
--
-- 核心工业级特性:
-- 1. 极致性能优化:全局常用函数与标准库全部局部化 (Localize Globals),零虚拟机查找开销。
-- 2. 强力防静默截断:文法尾部强制绑定 EOF (* -1) 锚定,遇到语法畸变立刻报错,绝不输出半截脏数据。
-- 3. 双形态防碰撞:采用 _data 隔离与 __call 混合代理,杜绝 [write]、[get] 等配置节覆盖成员方法。
-- 4. 智能转义与行内注释:原生支持单/双引号脱壳 ("val" -> val),完美过滤行尾注释 (;/##) 且不误伤引号内字符。
@leeonix
leeonix / Premake5.lua
Created June 28, 2015 06:41
Premake5.lua for Stormlib
solution 'StormLib'
location 'build'
language 'C++'
configurations { 'Debug', 'Release', }
platforms { 'x32', 'x64' }
targetdir 'bin'
objdir 'bin'
@leeonix
leeonix / extract_winrar.lua
Last active March 4, 2017 15:33
Use lua to extract rar file for Total Commander
--
-- FILE: extract_winrar.lua
-- AUTHOR: LeeoNix
-- DESCRIPTION:
-- NOTES: ---
--
--[[
TOTALCMD#BAR#DATA
@leeonix
leeonix / genpremake.py
Last active March 8, 2017 01:33
premake5.lua or premake4.lua generator
import os, sys, getopt, string
import uuid
template4 = """
newoption {
trigger = 'to',
value = 'path',
description = 'Set the output location for the generated files'
}
@leeonix
leeonix / array.c
Created May 13, 2015 12:18
dynamic array structure
/*
* =====================================================================================
*
* Filename: array.c
* Description: array structure
* Created: 2011-10-14 9:52:47
*
* =====================================================================================
*/
@leeonix
leeonix / strbuf.c
Created August 16, 2014 08:36
git's strbuf
#include <sys/types.h>
#include <sys/stat.h>
#include <ctype.h>
#include <fcntl.h>
#include <stddef.h>
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include <malloc.h>
#include <errno.h>
@leeonix
leeonix / three_num_add.dpr
Last active August 29, 2015 14:05
计算123456789,所有3位数加法的组合。
program three_num_add;
{$APPTYPE CONSOLE}
uses
Classes,
SysUtils;
type
PResult = ^TResult;
@leeonix
leeonix / genmakefile.py
Last active December 3, 2018 19:45
generate Makefile template using python
import sys, string
template = """
CC = gcc
CXX = g++
AR = ar
DEFINES +=
CFLAGS = $(DEFINES) -c -O2 -Wall
INCLUDES +=
# coding: gbk
<%!
from textwrap import wrap
import re
%><%
def replacer(s):
try:
return '(event == %s)' % (machine.event(s.group()).name)
except KeyError:
return '%s(param)' % machine.input(s.group()).name