diff --git a/CMakeLists.txt b/CMakeLists.txt index c45fb7d..141f7f2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,6 +20,7 @@ set(SOURCES src/core/registry_service.c src/core/path_manager.c src/core/app_context.c + src/core/lua_config.c src/controller/callbacks.c ico/resources.rc ) @@ -51,15 +52,18 @@ target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/include/controller ${CMAKE_SOURCE_DIR}/include/utils ${CMAKE_SOURCE_DIR}/libs/IUP/include + ${CMAKE_SOURCE_DIR}/libs/lua/include ) # 设置库文件搜索路径 target_link_directories(${PROJECT_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/libs/IUP + ${CMAKE_SOURCE_DIR}/libs/lua ) # 链接所需库 target_link_libraries(${PROJECT_NAME} PRIVATE + lua55 iup iupcd gdi32 @@ -70,11 +74,18 @@ target_link_libraries(${PROJECT_NAME} PRIVATE advapi32 ) -# 编译完成后,仅将程序实际需要的核心 DLL 文件复制到构建输出目录 +# 编译完成后,复制程序实际需要的核心 DLL 文件到构建输出目录 set(IUP_REQUIRED_DLLS "${CMAKE_CURRENT_SOURCE_DIR}/libs/IUP/iup.dll") +set(LUA_REQUIRED_DLLS "${CMAKE_CURRENT_SOURCE_DIR}/libs/lua/lua55.dll") add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different ${IUP_REQUIRED_DLLS} "$" COMMENT "Copying required DLLs to build directory..." ) +add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_if_different + ${LUA_REQUIRED_DLLS} + "$" + COMMENT "Copying Lua DLL to build directory..." +) diff --git a/Makefile b/Makefile deleted file mode 100644 index 1da684a..0000000 --- a/Makefile +++ /dev/null @@ -1,60 +0,0 @@ -CC = gcc -WINDRES = windres - -# Paths - specific to user environment -IUP_DIR = libs/iup-3.31_Win64_dllw6_lib -INCLUDE_DIR = $(IUP_DIR)/include -LIB_DIR = $(IUP_DIR) -LOCAL_INCLUDE_DIR = include - -# Output Directories -OBJ_DIR = obj -BIN_DIR = bin - -# Flags -# -mwindows: Create GUI app (no console) -# -DUNICODE -D_UNICODE: Use Wide Character API -CFLAGS = -Wall -O2 -I$(INCLUDE_DIR) -I$(LOCAL_INCLUDE_DIR) -D_WIN32 -DUNICODE -D_UNICODE -fexec-charset=UTF-8 -LDFLAGS = -L$(LIB_DIR) -liup -liupcd -lgdi32 -lcomdlg32 -lcomctl32 -luuid -lole32 -ladvapi32 -mwindows - -# Source -SRC = src/main.c src/utils.c src/registry.c src/callbacks.c src/ui.c src/globals.c -RES = ico/resources.rc -OBJ = $(OBJ_DIR)/main.o $(OBJ_DIR)/utils.o $(OBJ_DIR)/registry.o $(OBJ_DIR)/callbacks.o $(OBJ_DIR)/ui.o $(OBJ_DIR)/globals.o $(OBJ_DIR)/resources.o -EXE = $(BIN_DIR)/PathEditor.exe - -all: $(BIN_DIR) $(OBJ_DIR) $(EXE) - -$(BIN_DIR): - if not exist $(BIN_DIR) mkdir $(BIN_DIR) - -$(OBJ_DIR): - if not exist $(OBJ_DIR) mkdir $(OBJ_DIR) - -$(EXE): $(OBJ) - $(CC) -o $@ $^ $(LDFLAGS) - -$(OBJ_DIR)/main.o: src/main.c - $(CC) $(CFLAGS) -c -o $@ $< - -$(OBJ_DIR)/utils.o: src/utils.c - $(CC) $(CFLAGS) -c -o $@ $< - -$(OBJ_DIR)/registry.o: src/registry.c - $(CC) $(CFLAGS) -c -o $@ $< - -$(OBJ_DIR)/callbacks.o: src/callbacks.c - $(CC) $(CFLAGS) -c -o $@ $< - -$(OBJ_DIR)/ui.o: src/ui.c - $(CC) $(CFLAGS) -c -o $@ $< - -$(OBJ_DIR)/globals.o: src/globals.c - $(CC) $(CFLAGS) -c -o $@ $< - -$(OBJ_DIR)/resources.o: ico/resources.rc - $(WINDRES) -i $< -o $@ - -clean: - if exist $(OBJ_DIR)\*.o del /Q $(OBJ_DIR)\*.o - if exist $(BIN_DIR)\*.exe del /Q $(BIN_DIR)\*.exe \ No newline at end of file diff --git a/include/config.h b/include/config.h deleted file mode 100644 index e3c9810..0000000 --- a/include/config.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef CONFIG_H -#define CONFIG_H - -// ============================================================================ -// UI的配置常量 -// ============================================================================ - -// 应用程序名称 -#define APP_NAME "PathEditor" // 编辑环境变量应用程序名称 -#define APP_NAME_READONLY "PathEditor (只读模式)" // 编辑环境变量只读模式标题 - -// 对话框设置 -#define UI_DLG_SIZE "800x800" // 对话框默认大小 (像素) -#define UI_DLG_MINSIZE "800x800" // 对话框最小大小 (像素) - -// 列表控件设置 -#define UI_LIST_ITEM_PADDING "5x5" // 列表项内边距 -#define UI_LIST_BACKCOLOR "255 255 255" // 列表背景颜色 - -// 按钮设置 -#define UI_BTN_RASTERSIZE "100x32" // 按钮默认大小 - -// 布局间隙和边距 -#define UI_VBOX_GAP "5" // 垂直布局项间隙 -#define UI_VBOX_MARGIN "0x0" // 垂直布局外边距 -#define UI_VBOX_ALL_MARGIN "10x10" // 垂直布局总外边距 -#define UI_VBOX_ALL_GAP "5" // 垂直布局总间隙 - -#define UI_HBOX_GAP "10" // 水平布局项间隙 -#define UI_HBOX_MARGIN "10x10" // 水平布局外边距 -#define UI_HBOX_ALIGNMENT "ACENTER" // 水平布局对齐方式 - -#endif // CONFIG_H diff --git a/include/core/lua_config.h b/include/core/lua_config.h new file mode 100644 index 0000000..9e638a9 --- /dev/null +++ b/include/core/lua_config.h @@ -0,0 +1,34 @@ +#ifndef LUA_CONFIG_H +#define LUA_CONFIG_H + +#include + +// 初始化 Lua 配置系统 +// 返回值: 0 成功, -1 失败 +int lua_config_init(void); + +// 销毁 Lua 配置系统 +void lua_config_destroy(void); + +// 获取字符串配置值 +// section: 配置章节名 (如 "app", "dialog", "button") +// key: 配置键名 (如 "name", "size", "rastersize") +// 返回值: 配置值字符串, 失败时返回 NULL +const char* lua_config_get_string(const char* section, const char* key); + +// 获取整型配置值 +// section: 配置章节名 +// key: 配置键名 +// default_value: 默认值 (当配置不存在或转换失败时返回) +// 返回值: 配置值或默认值 +int lua_config_get_int(const char* section, const char* key, int default_value); + +// 重新加载配置文件 +// 返回值: 0 成功, -1 失败 +int lua_config_reload(void); + +// 获取配置加载状态 +// 返回值: 1 已加载, 0 未加载 +int lua_config_is_loaded(void); + +#endif // LUA_CONFIG_H \ No newline at end of file diff --git a/libs/lua/include/lauxlib.h b/libs/lua/include/lauxlib.h new file mode 100644 index 0000000..7f1d3ca --- /dev/null +++ b/libs/lua/include/lauxlib.h @@ -0,0 +1,271 @@ +/* +** $Id: lauxlib.h $ +** Auxiliary functions for building Lua libraries +** See Copyright Notice in lua.h +*/ + + +#ifndef lauxlib_h +#define lauxlib_h + + +#include +#include + +#include "luaconf.h" +#include "lua.h" + + +/* global table */ +#define LUA_GNAME "_G" + + +typedef struct luaL_Buffer luaL_Buffer; + + +/* extra error code for 'luaL_loadfilex' */ +#define LUA_ERRFILE (LUA_ERRERR+1) + + +/* key, in the registry, for table of loaded modules */ +#define LUA_LOADED_TABLE "_LOADED" + + +/* key, in the registry, for table of preloaded loaders */ +#define LUA_PRELOAD_TABLE "_PRELOAD" + + +typedef struct luaL_Reg { + const char *name; + lua_CFunction func; +} luaL_Reg; + + +#define LUAL_NUMSIZES (sizeof(lua_Integer)*16 + sizeof(lua_Number)) + +LUALIB_API void (luaL_checkversion_) (lua_State *L, lua_Number ver, size_t sz); +#define luaL_checkversion(L) \ + luaL_checkversion_(L, LUA_VERSION_NUM, LUAL_NUMSIZES) + +LUALIB_API int (luaL_getmetafield) (lua_State *L, int obj, const char *e); +LUALIB_API int (luaL_callmeta) (lua_State *L, int obj, const char *e); +LUALIB_API const char *(luaL_tolstring) (lua_State *L, int idx, size_t *len); +LUALIB_API int (luaL_argerror) (lua_State *L, int arg, const char *extramsg); +LUALIB_API int (luaL_typeerror) (lua_State *L, int arg, const char *tname); +LUALIB_API const char *(luaL_checklstring) (lua_State *L, int arg, + size_t *l); +LUALIB_API const char *(luaL_optlstring) (lua_State *L, int arg, + const char *def, size_t *l); +LUALIB_API lua_Number (luaL_checknumber) (lua_State *L, int arg); +LUALIB_API lua_Number (luaL_optnumber) (lua_State *L, int arg, lua_Number def); + +LUALIB_API lua_Integer (luaL_checkinteger) (lua_State *L, int arg); +LUALIB_API lua_Integer (luaL_optinteger) (lua_State *L, int arg, + lua_Integer def); + +LUALIB_API void (luaL_checkstack) (lua_State *L, int sz, const char *msg); +LUALIB_API void (luaL_checktype) (lua_State *L, int arg, int t); +LUALIB_API void (luaL_checkany) (lua_State *L, int arg); + +LUALIB_API int (luaL_newmetatable) (lua_State *L, const char *tname); +LUALIB_API void (luaL_setmetatable) (lua_State *L, const char *tname); +LUALIB_API void *(luaL_testudata) (lua_State *L, int ud, const char *tname); +LUALIB_API void *(luaL_checkudata) (lua_State *L, int ud, const char *tname); + +LUALIB_API void (luaL_where) (lua_State *L, int lvl); +LUALIB_API int (luaL_error) (lua_State *L, const char *fmt, ...); + +LUALIB_API int (luaL_checkoption) (lua_State *L, int arg, const char *def, + const char *const lst[]); + +LUALIB_API int (luaL_fileresult) (lua_State *L, int stat, const char *fname); +LUALIB_API int (luaL_execresult) (lua_State *L, int stat); + +LUALIB_API void *luaL_alloc (void *ud, void *ptr, size_t osize, + size_t nsize); + + +/* predefined references */ +#define LUA_NOREF (-2) +#define LUA_REFNIL (-1) + +LUALIB_API int (luaL_ref) (lua_State *L, int t); +LUALIB_API void (luaL_unref) (lua_State *L, int t, int ref); + +LUALIB_API int (luaL_loadfilex) (lua_State *L, const char *filename, + const char *mode); + +#define luaL_loadfile(L,f) luaL_loadfilex(L,f,NULL) + +LUALIB_API int (luaL_loadbufferx) (lua_State *L, const char *buff, size_t sz, + const char *name, const char *mode); +LUALIB_API int (luaL_loadstring) (lua_State *L, const char *s); + +LUALIB_API lua_State *(luaL_newstate) (void); + +LUALIB_API unsigned luaL_makeseed (lua_State *L); + +LUALIB_API lua_Integer (luaL_len) (lua_State *L, int idx); + +LUALIB_API void (luaL_addgsub) (luaL_Buffer *b, const char *s, + const char *p, const char *r); +LUALIB_API const char *(luaL_gsub) (lua_State *L, const char *s, + const char *p, const char *r); + +LUALIB_API void (luaL_setfuncs) (lua_State *L, const luaL_Reg *l, int nup); + +LUALIB_API int (luaL_getsubtable) (lua_State *L, int idx, const char *fname); + +LUALIB_API void (luaL_traceback) (lua_State *L, lua_State *L1, + const char *msg, int level); + +LUALIB_API void (luaL_requiref) (lua_State *L, const char *modname, + lua_CFunction openf, int glb); + +/* +** =============================================================== +** some useful macros +** =============================================================== +*/ + + +#define luaL_newlibtable(L,l) \ + lua_createtable(L, 0, sizeof(l)/sizeof((l)[0]) - 1) + +#define luaL_newlib(L,l) \ + (luaL_checkversion(L), luaL_newlibtable(L,l), luaL_setfuncs(L,l,0)) + +#define luaL_argcheck(L, cond,arg,extramsg) \ + ((void)(luai_likely(cond) || luaL_argerror(L, (arg), (extramsg)))) + +#define luaL_argexpected(L,cond,arg,tname) \ + ((void)(luai_likely(cond) || luaL_typeerror(L, (arg), (tname)))) + +#define luaL_checkstring(L,n) (luaL_checklstring(L, (n), NULL)) +#define luaL_optstring(L,n,d) (luaL_optlstring(L, (n), (d), NULL)) + +#define luaL_typename(L,i) lua_typename(L, lua_type(L,(i))) + +#define luaL_dofile(L, fn) \ + (luaL_loadfile(L, fn) || lua_pcall(L, 0, LUA_MULTRET, 0)) + +#define luaL_dostring(L, s) \ + (luaL_loadstring(L, s) || lua_pcall(L, 0, LUA_MULTRET, 0)) + +#define luaL_getmetatable(L,n) (lua_getfield(L, LUA_REGISTRYINDEX, (n))) + +#define luaL_opt(L,f,n,d) (lua_isnoneornil(L,(n)) ? (d) : f(L,(n))) + +#define luaL_loadbuffer(L,s,sz,n) luaL_loadbufferx(L,s,sz,n,NULL) + + +/* +** Perform arithmetic operations on lua_Integer values with wrap-around +** semantics, as the Lua core does. +*/ +#define luaL_intop(op,v1,v2) \ + ((lua_Integer)((lua_Unsigned)(v1) op (lua_Unsigned)(v2))) + + +/* push the value used to represent failure/error */ +#if defined(LUA_FAILISFALSE) +#define luaL_pushfail(L) lua_pushboolean(L, 0) +#else +#define luaL_pushfail(L) lua_pushnil(L) +#endif + + + +/* +** {====================================================== +** Generic Buffer manipulation +** ======================================================= +*/ + +struct luaL_Buffer { + char *b; /* buffer address */ + size_t size; /* buffer size */ + size_t n; /* number of characters in buffer */ + lua_State *L; + union { + LUAI_MAXALIGN; /* ensure maximum alignment for buffer */ + char b[LUAL_BUFFERSIZE]; /* initial buffer */ + } init; +}; + + +#define luaL_bufflen(bf) ((bf)->n) +#define luaL_buffaddr(bf) ((bf)->b) + + +#define luaL_addchar(B,c) \ + ((void)((B)->n < (B)->size || luaL_prepbuffsize((B), 1)), \ + ((B)->b[(B)->n++] = (c))) + +#define luaL_addsize(B,s) ((B)->n += (s)) + +#define luaL_buffsub(B,s) ((B)->n -= (s)) + +LUALIB_API void (luaL_buffinit) (lua_State *L, luaL_Buffer *B); +LUALIB_API char *(luaL_prepbuffsize) (luaL_Buffer *B, size_t sz); +LUALIB_API void (luaL_addlstring) (luaL_Buffer *B, const char *s, size_t l); +LUALIB_API void (luaL_addstring) (luaL_Buffer *B, const char *s); +LUALIB_API void (luaL_addvalue) (luaL_Buffer *B); +LUALIB_API void (luaL_pushresult) (luaL_Buffer *B); +LUALIB_API void (luaL_pushresultsize) (luaL_Buffer *B, size_t sz); +LUALIB_API char *(luaL_buffinitsize) (lua_State *L, luaL_Buffer *B, size_t sz); + +#define luaL_prepbuffer(B) luaL_prepbuffsize(B, LUAL_BUFFERSIZE) + +/* }====================================================== */ + + + +/* +** {====================================================== +** File handles for IO library +** ======================================================= +*/ + +/* +** A file handle is a userdata with metatable 'LUA_FILEHANDLE' and +** initial structure 'luaL_Stream' (it may contain other fields +** after that initial structure). +*/ + +#define LUA_FILEHANDLE "FILE*" + + +typedef struct luaL_Stream { + FILE *f; /* stream (NULL for incompletely created streams) */ + lua_CFunction closef; /* to close stream (NULL for closed streams) */ +} luaL_Stream; + +/* }====================================================== */ + + +/* +** {============================================================ +** Compatibility with deprecated conversions +** ============================================================= +*/ +#if defined(LUA_COMPAT_APIINTCASTS) + +#define luaL_checkunsigned(L,a) ((lua_Unsigned)luaL_checkinteger(L,a)) +#define luaL_optunsigned(L,a,d) \ + ((lua_Unsigned)luaL_optinteger(L,a,(lua_Integer)(d))) + +#define luaL_checkint(L,n) ((int)luaL_checkinteger(L, (n))) +#define luaL_optint(L,n,d) ((int)luaL_optinteger(L, (n), (d))) + +#define luaL_checklong(L,n) ((long)luaL_checkinteger(L, (n))) +#define luaL_optlong(L,n,d) ((long)luaL_optinteger(L, (n), (d))) + +#endif +/* }============================================================ */ + + + +#endif + + diff --git a/libs/lua/include/lua.h b/libs/lua/include/lua.h new file mode 100644 index 0000000..ab473dc --- /dev/null +++ b/libs/lua/include/lua.h @@ -0,0 +1,547 @@ +/* +** $Id: lua.h $ +** Lua - A Scripting Language +** Lua.org, PUC-Rio, Brazil (www.lua.org) +** See Copyright Notice at the end of this file +*/ + + +#ifndef lua_h +#define lua_h + +#include +#include + + +#define LUA_COPYRIGHT LUA_RELEASE " Copyright (C) 1994-2025 Lua.org, PUC-Rio" +#define LUA_AUTHORS "R. Ierusalimschy, L. H. de Figueiredo, W. Celes" + + +#define LUA_VERSION_MAJOR_N 5 +#define LUA_VERSION_MINOR_N 5 +#define LUA_VERSION_RELEASE_N 0 + +#define LUA_VERSION_NUM (LUA_VERSION_MAJOR_N * 100 + LUA_VERSION_MINOR_N) +#define LUA_VERSION_RELEASE_NUM (LUA_VERSION_NUM * 100 + LUA_VERSION_RELEASE_N) + + +#include "luaconf.h" + + +/* mark for precompiled code ('Lua') */ +#define LUA_SIGNATURE "\x1bLua" + +/* option for multiple returns in 'lua_pcall' and 'lua_call' */ +#define LUA_MULTRET (-1) + + +/* +** Pseudo-indices +** (The stack size is limited to INT_MAX/2; we keep some free empty +** space after that to help overflow detection.) +*/ +#define LUA_REGISTRYINDEX (-(INT_MAX/2 + 1000)) +#define lua_upvalueindex(i) (LUA_REGISTRYINDEX - (i)) + + +/* thread status */ +#define LUA_OK 0 +#define LUA_YIELD 1 +#define LUA_ERRRUN 2 +#define LUA_ERRSYNTAX 3 +#define LUA_ERRMEM 4 +#define LUA_ERRERR 5 + + +typedef struct lua_State lua_State; + + +/* +** basic types +*/ +#define LUA_TNONE (-1) + +#define LUA_TNIL 0 +#define LUA_TBOOLEAN 1 +#define LUA_TLIGHTUSERDATA 2 +#define LUA_TNUMBER 3 +#define LUA_TSTRING 4 +#define LUA_TTABLE 5 +#define LUA_TFUNCTION 6 +#define LUA_TUSERDATA 7 +#define LUA_TTHREAD 8 + +#define LUA_NUMTYPES 9 + + + +/* minimum Lua stack available to a C function */ +#define LUA_MINSTACK 20 + + +/* predefined values in the registry */ +/* index 1 is reserved for the reference mechanism */ +#define LUA_RIDX_GLOBALS 2 +#define LUA_RIDX_MAINTHREAD 3 +#define LUA_RIDX_LAST 3 + + +/* type of numbers in Lua */ +typedef LUA_NUMBER lua_Number; + + +/* type for integer functions */ +typedef LUA_INTEGER lua_Integer; + +/* unsigned integer type */ +typedef LUA_UNSIGNED lua_Unsigned; + +/* type for continuation-function contexts */ +typedef LUA_KCONTEXT lua_KContext; + + +/* +** Type for C functions registered with Lua +*/ +typedef int (*lua_CFunction) (lua_State *L); + +/* +** Type for continuation functions +*/ +typedef int (*lua_KFunction) (lua_State *L, int status, lua_KContext ctx); + + +/* +** Type for functions that read/write blocks when loading/dumping Lua chunks +*/ +typedef const char * (*lua_Reader) (lua_State *L, void *ud, size_t *sz); + +typedef int (*lua_Writer) (lua_State *L, const void *p, size_t sz, void *ud); + + +/* +** Type for memory-allocation functions +*/ +typedef void * (*lua_Alloc) (void *ud, void *ptr, size_t osize, size_t nsize); + + +/* +** Type for warning functions +*/ +typedef void (*lua_WarnFunction) (void *ud, const char *msg, int tocont); + + +/* +** Type used by the debug API to collect debug information +*/ +typedef struct lua_Debug lua_Debug; + + +/* +** Functions to be called by the debugger in specific events +*/ +typedef void (*lua_Hook) (lua_State *L, lua_Debug *ar); + + +/* +** generic extra include file +*/ +#if defined(LUA_USER_H) +#include LUA_USER_H +#endif + + +/* +** RCS ident string +*/ +extern const char lua_ident[]; + + +/* +** state manipulation +*/ +LUA_API lua_State *(lua_newstate) (lua_Alloc f, void *ud, unsigned seed); +LUA_API void (lua_close) (lua_State *L); +LUA_API lua_State *(lua_newthread) (lua_State *L); +LUA_API int (lua_closethread) (lua_State *L, lua_State *from); + +LUA_API lua_CFunction (lua_atpanic) (lua_State *L, lua_CFunction panicf); + + +LUA_API lua_Number (lua_version) (lua_State *L); + + +/* +** basic stack manipulation +*/ +LUA_API int (lua_absindex) (lua_State *L, int idx); +LUA_API int (lua_gettop) (lua_State *L); +LUA_API void (lua_settop) (lua_State *L, int idx); +LUA_API void (lua_pushvalue) (lua_State *L, int idx); +LUA_API void (lua_rotate) (lua_State *L, int idx, int n); +LUA_API void (lua_copy) (lua_State *L, int fromidx, int toidx); +LUA_API int (lua_checkstack) (lua_State *L, int n); + +LUA_API void (lua_xmove) (lua_State *from, lua_State *to, int n); + + +/* +** access functions (stack -> C) +*/ + +LUA_API int (lua_isnumber) (lua_State *L, int idx); +LUA_API int (lua_isstring) (lua_State *L, int idx); +LUA_API int (lua_iscfunction) (lua_State *L, int idx); +LUA_API int (lua_isinteger) (lua_State *L, int idx); +LUA_API int (lua_isuserdata) (lua_State *L, int idx); +LUA_API int (lua_type) (lua_State *L, int idx); +LUA_API const char *(lua_typename) (lua_State *L, int tp); + +LUA_API lua_Number (lua_tonumberx) (lua_State *L, int idx, int *isnum); +LUA_API lua_Integer (lua_tointegerx) (lua_State *L, int idx, int *isnum); +LUA_API int (lua_toboolean) (lua_State *L, int idx); +LUA_API const char *(lua_tolstring) (lua_State *L, int idx, size_t *len); +LUA_API lua_Unsigned (lua_rawlen) (lua_State *L, int idx); +LUA_API lua_CFunction (lua_tocfunction) (lua_State *L, int idx); +LUA_API void *(lua_touserdata) (lua_State *L, int idx); +LUA_API lua_State *(lua_tothread) (lua_State *L, int idx); +LUA_API const void *(lua_topointer) (lua_State *L, int idx); + + +/* +** Comparison and arithmetic functions +*/ + +#define LUA_OPADD 0 /* ORDER TM, ORDER OP */ +#define LUA_OPSUB 1 +#define LUA_OPMUL 2 +#define LUA_OPMOD 3 +#define LUA_OPPOW 4 +#define LUA_OPDIV 5 +#define LUA_OPIDIV 6 +#define LUA_OPBAND 7 +#define LUA_OPBOR 8 +#define LUA_OPBXOR 9 +#define LUA_OPSHL 10 +#define LUA_OPSHR 11 +#define LUA_OPUNM 12 +#define LUA_OPBNOT 13 + +LUA_API void (lua_arith) (lua_State *L, int op); + +#define LUA_OPEQ 0 +#define LUA_OPLT 1 +#define LUA_OPLE 2 + +LUA_API int (lua_rawequal) (lua_State *L, int idx1, int idx2); +LUA_API int (lua_compare) (lua_State *L, int idx1, int idx2, int op); + + +/* +** push functions (C -> stack) +*/ +LUA_API void (lua_pushnil) (lua_State *L); +LUA_API void (lua_pushnumber) (lua_State *L, lua_Number n); +LUA_API void (lua_pushinteger) (lua_State *L, lua_Integer n); +LUA_API const char *(lua_pushlstring) (lua_State *L, const char *s, size_t len); +LUA_API const char *(lua_pushexternalstring) (lua_State *L, + const char *s, size_t len, lua_Alloc falloc, void *ud); +LUA_API const char *(lua_pushstring) (lua_State *L, const char *s); +LUA_API const char *(lua_pushvfstring) (lua_State *L, const char *fmt, + va_list argp); +LUA_API const char *(lua_pushfstring) (lua_State *L, const char *fmt, ...); +LUA_API void (lua_pushcclosure) (lua_State *L, lua_CFunction fn, int n); +LUA_API void (lua_pushboolean) (lua_State *L, int b); +LUA_API void (lua_pushlightuserdata) (lua_State *L, void *p); +LUA_API int (lua_pushthread) (lua_State *L); + + +/* +** get functions (Lua -> stack) +*/ +LUA_API int (lua_getglobal) (lua_State *L, const char *name); +LUA_API int (lua_gettable) (lua_State *L, int idx); +LUA_API int (lua_getfield) (lua_State *L, int idx, const char *k); +LUA_API int (lua_geti) (lua_State *L, int idx, lua_Integer n); +LUA_API int (lua_rawget) (lua_State *L, int idx); +LUA_API int (lua_rawgeti) (lua_State *L, int idx, lua_Integer n); +LUA_API int (lua_rawgetp) (lua_State *L, int idx, const void *p); + +LUA_API void (lua_createtable) (lua_State *L, int narr, int nrec); +LUA_API void *(lua_newuserdatauv) (lua_State *L, size_t sz, int nuvalue); +LUA_API int (lua_getmetatable) (lua_State *L, int objindex); +LUA_API int (lua_getiuservalue) (lua_State *L, int idx, int n); + + +/* +** set functions (stack -> Lua) +*/ +LUA_API void (lua_setglobal) (lua_State *L, const char *name); +LUA_API void (lua_settable) (lua_State *L, int idx); +LUA_API void (lua_setfield) (lua_State *L, int idx, const char *k); +LUA_API void (lua_seti) (lua_State *L, int idx, lua_Integer n); +LUA_API void (lua_rawset) (lua_State *L, int idx); +LUA_API void (lua_rawseti) (lua_State *L, int idx, lua_Integer n); +LUA_API void (lua_rawsetp) (lua_State *L, int idx, const void *p); +LUA_API int (lua_setmetatable) (lua_State *L, int objindex); +LUA_API int (lua_setiuservalue) (lua_State *L, int idx, int n); + + +/* +** 'load' and 'call' functions (load and run Lua code) +*/ +LUA_API void (lua_callk) (lua_State *L, int nargs, int nresults, + lua_KContext ctx, lua_KFunction k); +#define lua_call(L,n,r) lua_callk(L, (n), (r), 0, NULL) + +LUA_API int (lua_pcallk) (lua_State *L, int nargs, int nresults, int errfunc, + lua_KContext ctx, lua_KFunction k); +#define lua_pcall(L,n,r,f) lua_pcallk(L, (n), (r), (f), 0, NULL) + +LUA_API int (lua_load) (lua_State *L, lua_Reader reader, void *dt, + const char *chunkname, const char *mode); + +LUA_API int (lua_dump) (lua_State *L, lua_Writer writer, void *data, int strip); + + +/* +** coroutine functions +*/ +LUA_API int (lua_yieldk) (lua_State *L, int nresults, lua_KContext ctx, + lua_KFunction k); +LUA_API int (lua_resume) (lua_State *L, lua_State *from, int narg, + int *nres); +LUA_API int (lua_status) (lua_State *L); +LUA_API int (lua_isyieldable) (lua_State *L); + +#define lua_yield(L,n) lua_yieldk(L, (n), 0, NULL) + + +/* +** Warning-related functions +*/ +LUA_API void (lua_setwarnf) (lua_State *L, lua_WarnFunction f, void *ud); +LUA_API void (lua_warning) (lua_State *L, const char *msg, int tocont); + + +/* +** garbage-collection options +*/ + +#define LUA_GCSTOP 0 +#define LUA_GCRESTART 1 +#define LUA_GCCOLLECT 2 +#define LUA_GCCOUNT 3 +#define LUA_GCCOUNTB 4 +#define LUA_GCSTEP 5 +#define LUA_GCISRUNNING 6 +#define LUA_GCGEN 7 +#define LUA_GCINC 8 +#define LUA_GCPARAM 9 + + +/* +** garbage-collection parameters +*/ +/* parameters for generational mode */ +#define LUA_GCPMINORMUL 0 /* control minor collections */ +#define LUA_GCPMAJORMINOR 1 /* control shift major->minor */ +#define LUA_GCPMINORMAJOR 2 /* control shift minor->major */ + +/* parameters for incremental mode */ +#define LUA_GCPPAUSE 3 /* size of pause between successive GCs */ +#define LUA_GCPSTEPMUL 4 /* GC "speed" */ +#define LUA_GCPSTEPSIZE 5 /* GC granularity */ + +/* number of parameters */ +#define LUA_GCPN 6 + + +LUA_API int (lua_gc) (lua_State *L, int what, ...); + + +/* +** miscellaneous functions +*/ + +LUA_API int (lua_error) (lua_State *L); + +LUA_API int (lua_next) (lua_State *L, int idx); + +LUA_API void (lua_concat) (lua_State *L, int n); +LUA_API void (lua_len) (lua_State *L, int idx); + +#define LUA_N2SBUFFSZ 64 +LUA_API unsigned (lua_numbertocstring) (lua_State *L, int idx, char *buff); +LUA_API size_t (lua_stringtonumber) (lua_State *L, const char *s); + +LUA_API lua_Alloc (lua_getallocf) (lua_State *L, void **ud); +LUA_API void (lua_setallocf) (lua_State *L, lua_Alloc f, void *ud); + +LUA_API void (lua_toclose) (lua_State *L, int idx); +LUA_API void (lua_closeslot) (lua_State *L, int idx); + + +/* +** {============================================================== +** some useful macros +** =============================================================== +*/ + +#define lua_getextraspace(L) ((void *)((char *)(L) - LUA_EXTRASPACE)) + +#define lua_tonumber(L,i) lua_tonumberx(L,(i),NULL) +#define lua_tointeger(L,i) lua_tointegerx(L,(i),NULL) + +#define lua_pop(L,n) lua_settop(L, -(n)-1) + +#define lua_newtable(L) lua_createtable(L, 0, 0) + +#define lua_register(L,n,f) (lua_pushcfunction(L, (f)), lua_setglobal(L, (n))) + +#define lua_pushcfunction(L,f) lua_pushcclosure(L, (f), 0) + +#define lua_isfunction(L,n) (lua_type(L, (n)) == LUA_TFUNCTION) +#define lua_istable(L,n) (lua_type(L, (n)) == LUA_TTABLE) +#define lua_islightuserdata(L,n) (lua_type(L, (n)) == LUA_TLIGHTUSERDATA) +#define lua_isnil(L,n) (lua_type(L, (n)) == LUA_TNIL) +#define lua_isboolean(L,n) (lua_type(L, (n)) == LUA_TBOOLEAN) +#define lua_isthread(L,n) (lua_type(L, (n)) == LUA_TTHREAD) +#define lua_isnone(L,n) (lua_type(L, (n)) == LUA_TNONE) +#define lua_isnoneornil(L, n) (lua_type(L, (n)) <= 0) + +#define lua_pushliteral(L, s) lua_pushstring(L, "" s) + +#define lua_pushglobaltable(L) \ + ((void)lua_rawgeti(L, LUA_REGISTRYINDEX, LUA_RIDX_GLOBALS)) + +#define lua_tostring(L,i) lua_tolstring(L, (i), NULL) + + +#define lua_insert(L,idx) lua_rotate(L, (idx), 1) + +#define lua_remove(L,idx) (lua_rotate(L, (idx), -1), lua_pop(L, 1)) + +#define lua_replace(L,idx) (lua_copy(L, -1, (idx)), lua_pop(L, 1)) + +/* }============================================================== */ + + +/* +** {============================================================== +** compatibility macros +** =============================================================== +*/ + +#define lua_newuserdata(L,s) lua_newuserdatauv(L,s,1) +#define lua_getuservalue(L,idx) lua_getiuservalue(L,idx,1) +#define lua_setuservalue(L,idx) lua_setiuservalue(L,idx,1) + +#define lua_resetthread(L) lua_closethread(L,NULL) + +/* }============================================================== */ + +/* +** {====================================================================== +** Debug API +** ======================================================================= +*/ + + +/* +** Event codes +*/ +#define LUA_HOOKCALL 0 +#define LUA_HOOKRET 1 +#define LUA_HOOKLINE 2 +#define LUA_HOOKCOUNT 3 +#define LUA_HOOKTAILCALL 4 + + +/* +** Event masks +*/ +#define LUA_MASKCALL (1 << LUA_HOOKCALL) +#define LUA_MASKRET (1 << LUA_HOOKRET) +#define LUA_MASKLINE (1 << LUA_HOOKLINE) +#define LUA_MASKCOUNT (1 << LUA_HOOKCOUNT) + + +LUA_API int (lua_getstack) (lua_State *L, int level, lua_Debug *ar); +LUA_API int (lua_getinfo) (lua_State *L, const char *what, lua_Debug *ar); +LUA_API const char *(lua_getlocal) (lua_State *L, const lua_Debug *ar, int n); +LUA_API const char *(lua_setlocal) (lua_State *L, const lua_Debug *ar, int n); +LUA_API const char *(lua_getupvalue) (lua_State *L, int funcindex, int n); +LUA_API const char *(lua_setupvalue) (lua_State *L, int funcindex, int n); + +LUA_API void *(lua_upvalueid) (lua_State *L, int fidx, int n); +LUA_API void (lua_upvaluejoin) (lua_State *L, int fidx1, int n1, + int fidx2, int n2); + +LUA_API void (lua_sethook) (lua_State *L, lua_Hook func, int mask, int count); +LUA_API lua_Hook (lua_gethook) (lua_State *L); +LUA_API int (lua_gethookmask) (lua_State *L); +LUA_API int (lua_gethookcount) (lua_State *L); + + +struct lua_Debug { + int event; + const char *name; /* (n) */ + const char *namewhat; /* (n) 'global', 'local', 'field', 'method' */ + const char *what; /* (S) 'Lua', 'C', 'main', 'tail' */ + const char *source; /* (S) */ + size_t srclen; /* (S) */ + int currentline; /* (l) */ + int linedefined; /* (S) */ + int lastlinedefined; /* (S) */ + unsigned char nups; /* (u) number of upvalues */ + unsigned char nparams;/* (u) number of parameters */ + char isvararg; /* (u) */ + unsigned char extraargs; /* (t) number of extra arguments */ + char istailcall; /* (t) */ + int ftransfer; /* (r) index of first value transferred */ + int ntransfer; /* (r) number of transferred values */ + char short_src[LUA_IDSIZE]; /* (S) */ + /* private part */ + struct CallInfo *i_ci; /* active function */ +}; + +/* }====================================================================== */ + + +#define LUAI_TOSTRAUX(x) #x +#define LUAI_TOSTR(x) LUAI_TOSTRAUX(x) + +#define LUA_VERSION_MAJOR LUAI_TOSTR(LUA_VERSION_MAJOR_N) +#define LUA_VERSION_MINOR LUAI_TOSTR(LUA_VERSION_MINOR_N) +#define LUA_VERSION_RELEASE LUAI_TOSTR(LUA_VERSION_RELEASE_N) + +#define LUA_VERSION "Lua " LUA_VERSION_MAJOR "." LUA_VERSION_MINOR +#define LUA_RELEASE LUA_VERSION "." LUA_VERSION_RELEASE + + +/****************************************************************************** +* Copyright (C) 1994-2025 Lua.org, PUC-Rio. +* +* Permission is hereby granted, free of charge, to any person obtaining +* a copy of this software and associated documentation files (the +* "Software"), to deal in the Software without restriction, including +* without limitation the rights to use, copy, modify, merge, publish, +* distribute, sublicense, and/or sell copies of the Software, and to +* permit persons to whom the Software is furnished to do so, subject to +* the following conditions: +* +* The above copyright notice and this permission notice shall be +* included in all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +******************************************************************************/ + + +#endif diff --git a/libs/lua/include/lua.hpp b/libs/lua/include/lua.hpp new file mode 100644 index 0000000..2853364 --- /dev/null +++ b/libs/lua/include/lua.hpp @@ -0,0 +1,10 @@ +// lua.hpp +// Lua header files for C++ +// 'extern "C" not supplied automatically in lua.h and other headers +// because Lua also compiles as C++ + +extern "C" { +#include "lua.h" +#include "lualib.h" +#include "lauxlib.h" +} diff --git a/libs/lua/include/luaconf.h b/libs/lua/include/luaconf.h new file mode 100644 index 0000000..96a7780 --- /dev/null +++ b/libs/lua/include/luaconf.h @@ -0,0 +1,745 @@ +/* +** $Id: luaconf.h $ +** Configuration file for Lua +** See Copyright Notice in lua.h +*/ + + +#ifndef luaconf_h +#define luaconf_h + +#include +#include + + +/* +** =================================================================== +** General Configuration File for Lua +** +** Some definitions here can be changed externally, through the compiler +** (e.g., with '-D' options): They are commented out or protected +** by '#if !defined' guards. However, several other definitions +** should be changed directly here, either because they affect the +** Lua ABI (by making the changes here, you ensure that all software +** connected to Lua, such as C libraries, will be compiled with the same +** configuration); or because they are seldom changed. +** +** Search for "@@" to find all configurable definitions. +** =================================================================== +*/ + + +/* +** {==================================================================== +** System Configuration: macros to adapt (if needed) Lua to some +** particular platform, for instance restricting it to C89. +** ===================================================================== +*/ + +/* +@@ LUA_USE_C89 controls the use of non-ISO-C89 features. +** Define it if you want Lua to avoid the use of a few C99 features +** or Windows-specific features on Windows. +*/ +/* #define LUA_USE_C89 */ + + +/* +** By default, Lua on Windows use (some) specific Windows features +*/ +#if !defined(LUA_USE_C89) && defined(_WIN32) && !defined(_WIN32_WCE) +#define LUA_USE_WINDOWS /* enable goodies for regular Windows */ +#endif + + +#if defined(LUA_USE_WINDOWS) +#define LUA_DL_DLL /* enable support for DLL */ +#define LUA_USE_C89 /* broadly, Windows is C89 */ +#endif + + +/* +** When POSIX DLL ('LUA_USE_DLOPEN') is enabled, the Lua stand-alone +** application will try to dynamically link a 'readline' facility +** for its REPL. In that case, LUA_READLINELIB is the name of the +** library it will look for those facilities. If lua.c cannot open +** the specified library, it will generate a warning and then run +** without 'readline'. If that macro is not defined, lua.c will not +** use 'readline'. +*/ +#if defined(LUA_USE_LINUX) +#define LUA_USE_POSIX +#define LUA_USE_DLOPEN /* needs an extra library: -ldl */ +#define LUA_READLINELIB "libreadline.so" +#endif + + +#if defined(LUA_USE_MACOSX) +#define LUA_USE_POSIX +#define LUA_USE_DLOPEN /* macOS does not need -ldl */ +#define LUA_READLINELIB "libedit.dylib" +#endif + + +#if defined(LUA_USE_IOS) +#define LUA_USE_POSIX +#define LUA_USE_DLOPEN +#endif + + +#if defined(LUA_USE_C89) && defined(LUA_USE_POSIX) +#error "POSIX is not compatible with C89" +#endif + + +/* +@@ LUAI_IS32INT is true iff 'int' has (at least) 32 bits. +*/ +#define LUAI_IS32INT ((UINT_MAX >> 30) >= 3) + +/* }================================================================== */ + + + +/* +** {================================================================== +** Configuration for Number types. These options should not be +** set externally, because any other code connected to Lua must +** use the same configuration. +** =================================================================== +*/ + +/* +@@ LUA_INT_TYPE defines the type for Lua integers. +@@ LUA_FLOAT_TYPE defines the type for Lua floats. +** Lua should work fine with any mix of these options supported +** by your C compiler. The usual configurations are 64-bit integers +** and 'double' (the default), 32-bit integers and 'float' (for +** restricted platforms), and 'long'/'double' (for C compilers not +** compliant with C99, which may not have support for 'long long'). +*/ + +/* predefined options for LUA_INT_TYPE */ +#define LUA_INT_INT 1 +#define LUA_INT_LONG 2 +#define LUA_INT_LONGLONG 3 + +/* predefined options for LUA_FLOAT_TYPE */ +#define LUA_FLOAT_FLOAT 1 +#define LUA_FLOAT_DOUBLE 2 +#define LUA_FLOAT_LONGDOUBLE 3 + + +/* Default configuration ('long long' and 'double', for 64-bit Lua) */ +#define LUA_INT_DEFAULT LUA_INT_LONGLONG +#define LUA_FLOAT_DEFAULT LUA_FLOAT_DOUBLE + + +/* +@@ LUA_32BITS enables Lua with 32-bit integers and 32-bit floats. +*/ +/* #define LUA_32BITS */ + + +/* +@@ LUA_C89_NUMBERS ensures that Lua uses the largest types available for +** C89 ('long' and 'double'); Windows always has '__int64', so it does +** not need to use this case. +*/ +#if defined(LUA_USE_C89) && !defined(LUA_USE_WINDOWS) +#define LUA_C89_NUMBERS 1 +#else +#define LUA_C89_NUMBERS 0 +#endif + + +#if defined(LUA_32BITS) /* { */ +/* +** 32-bit integers and 'float' +*/ +#if LUAI_IS32INT /* use 'int' if big enough */ +#define LUA_INT_TYPE LUA_INT_INT +#else /* otherwise use 'long' */ +#define LUA_INT_TYPE LUA_INT_LONG +#endif +#define LUA_FLOAT_TYPE LUA_FLOAT_FLOAT + +#elif LUA_C89_NUMBERS /* }{ */ +/* +** largest types available for C89 ('long' and 'double') +*/ +#define LUA_INT_TYPE LUA_INT_LONG +#define LUA_FLOAT_TYPE LUA_FLOAT_DOUBLE + +#else /* }{ */ +/* use defaults */ + +#define LUA_INT_TYPE LUA_INT_DEFAULT +#define LUA_FLOAT_TYPE LUA_FLOAT_DEFAULT + +#endif /* } */ + + +/* }================================================================== */ + + + +/* +** {================================================================== +** Configuration for Paths. +** =================================================================== +*/ + +/* +** LUA_PATH_SEP is the character that separates templates in a path. +** LUA_PATH_MARK is the string that marks the substitution points in a +** template. +** LUA_EXEC_DIR in a Windows path is replaced by the executable's +** directory. +*/ +#define LUA_PATH_SEP ";" +#define LUA_PATH_MARK "?" +#define LUA_EXEC_DIR "!" + + +/* +@@ LUA_PATH_DEFAULT is the default path that Lua uses to look for +** Lua libraries. +@@ LUA_CPATH_DEFAULT is the default path that Lua uses to look for +** C libraries. +** CHANGE them if your machine has a non-conventional directory +** hierarchy or if you want to install your libraries in +** non-conventional directories. +*/ + +#define LUA_VDIR LUA_VERSION_MAJOR "." LUA_VERSION_MINOR +#if defined(_WIN32) /* { */ +/* +** In Windows, any exclamation mark ('!') in the path is replaced by the +** path of the directory of the executable file of the current process. +*/ +#define LUA_LDIR "!\\lua\\" +#define LUA_CDIR "!\\" +#define LUA_SHRDIR "!\\..\\share\\lua\\" LUA_VDIR "\\" + +#if !defined(LUA_PATH_DEFAULT) +#define LUA_PATH_DEFAULT \ + LUA_LDIR"?.lua;" LUA_LDIR"?\\init.lua;" \ + LUA_CDIR"?.lua;" LUA_CDIR"?\\init.lua;" \ + LUA_SHRDIR"?.lua;" LUA_SHRDIR"?\\init.lua;" \ + ".\\?.lua;" ".\\?\\init.lua" +#endif + +#if !defined(LUA_CPATH_DEFAULT) +#define LUA_CPATH_DEFAULT \ + LUA_CDIR"?.dll;" \ + LUA_CDIR"..\\lib\\lua\\" LUA_VDIR "\\?.dll;" \ + LUA_CDIR"loadall.dll;" ".\\?.dll" +#endif + +#else /* }{ */ + +#define LUA_ROOT "/usr/local/" +#define LUA_LDIR LUA_ROOT "share/lua/" LUA_VDIR "/" +#define LUA_CDIR LUA_ROOT "lib/lua/" LUA_VDIR "/" + +#if !defined(LUA_PATH_DEFAULT) +#define LUA_PATH_DEFAULT \ + LUA_LDIR"?.lua;" LUA_LDIR"?/init.lua;" \ + LUA_CDIR"?.lua;" LUA_CDIR"?/init.lua;" \ + "./?.lua;" "./?/init.lua" +#endif + +#if !defined(LUA_CPATH_DEFAULT) +#define LUA_CPATH_DEFAULT \ + LUA_CDIR"?.so;" LUA_CDIR"loadall.so;" "./?.so" +#endif + +#endif /* } */ + + +/* +@@ LUA_DIRSEP is the directory separator (for submodules). +** CHANGE it if your machine does not use "/" as the directory separator +** and is not Windows. (On Windows Lua automatically uses "\".) +*/ +#if !defined(LUA_DIRSEP) + +#if defined(_WIN32) +#define LUA_DIRSEP "\\" +#else +#define LUA_DIRSEP "/" +#endif + +#endif + + +/* +** LUA_IGMARK is a mark to ignore all after it when building the +** module name (e.g., used to build the luaopen_ function name). +** Typically, the suffix after the mark is the module version, +** as in "mod-v1.2.so". +*/ +#define LUA_IGMARK "-" + +/* }================================================================== */ + + +/* +** {================================================================== +** Marks for exported symbols in the C code +** =================================================================== +*/ + +/* +@@ LUA_API is a mark for all core API functions. +@@ LUALIB_API is a mark for all auxiliary library functions. +@@ LUAMOD_API is a mark for all standard library opening functions. +** CHANGE them if you need to define those functions in some special way. +** For instance, if you want to create one Windows DLL with the core and +** the libraries, you may want to use the following definition (define +** LUA_BUILD_AS_DLL to get it). +*/ +#if defined(LUA_BUILD_AS_DLL) /* { */ + +#if defined(LUA_CORE) || defined(LUA_LIB) /* { */ +#define LUA_API __declspec(dllexport) +#else /* }{ */ +#define LUA_API __declspec(dllimport) +#endif /* } */ + +#else /* }{ */ + +#define LUA_API extern + +#endif /* } */ + + +/* +** More often than not the libs go together with the core. +*/ +#define LUALIB_API LUA_API + +#if defined(__cplusplus) +/* Lua uses the "C name" when calling open functions */ +#define LUAMOD_API extern "C" +#else +#define LUAMOD_API LUA_API +#endif + +/* }================================================================== */ + + +/* +** {================================================================== +** Compatibility with previous versions +** =================================================================== +*/ + +/* +@@ LUA_COMPAT_GLOBAL avoids 'global' being a reserved word +*/ +#define LUA_COMPAT_GLOBAL + + +/* +@@ LUA_COMPAT_MATHLIB controls the presence of several deprecated +** functions in the mathematical library. +** (These functions were already officially removed in 5.3; +** nevertheless they are still available here.) +*/ +/* #define LUA_COMPAT_MATHLIB */ + + +/* +@@ The following macros supply trivial compatibility for some +** changes in the API. The macros themselves document how to +** change your code to avoid using them. +** (Once more, these macros were officially removed in 5.3, but they are +** still available here.) +*/ +#define lua_strlen(L,i) lua_rawlen(L, (i)) + +#define lua_objlen(L,i) lua_rawlen(L, (i)) + +#define lua_equal(L,idx1,idx2) lua_compare(L,(idx1),(idx2),LUA_OPEQ) +#define lua_lessthan(L,idx1,idx2) lua_compare(L,(idx1),(idx2),LUA_OPLT) + +/* }================================================================== */ + + + +/* +** {================================================================== +** Configuration for Numbers (low-level part). +** Change these definitions if no predefined LUA_FLOAT_* / LUA_INT_* +** satisfy your needs. +** =================================================================== +*/ + +/* +@@ LUAI_UACNUMBER is the result of a 'default argument promotion' +@@ over a floating number. +@@ l_floatatt(x) corrects float attribute 'x' to the proper float type +** by prefixing it with one of FLT/DBL/LDBL. +@@ LUA_NUMBER_FRMLEN is the length modifier for writing floats. +@@ LUA_NUMBER_FMT is the format for writing floats with the maximum +** number of digits that respects tostring(tonumber(numeral)) == numeral. +** (That would be floor(log10(2^n)), where n is the number of bits in +** the float mantissa.) +@@ LUA_NUMBER_FMT_N is the format for writing floats with the minimum +** number of digits that ensures tonumber(tostring(number)) == number. +** (That would be LUA_NUMBER_FMT+2.) +@@ l_mathop allows the addition of an 'l' or 'f' to all math operations. +@@ l_floor takes the floor of a float. +@@ lua_str2number converts a decimal numeral to a number. +*/ + + +/* The following definition is good for most cases here */ + +#define l_floor(x) (l_mathop(floor)(x)) + + +/* now the variable definitions */ + +#if LUA_FLOAT_TYPE == LUA_FLOAT_FLOAT /* { single float */ + +#define LUA_NUMBER float + +#define l_floatatt(n) (FLT_##n) + +#define LUAI_UACNUMBER double + +#define LUA_NUMBER_FRMLEN "" +#define LUA_NUMBER_FMT "%.7g" +#define LUA_NUMBER_FMT_N "%.9g" + +#define l_mathop(op) op##f + +#define lua_str2number(s,p) strtof((s), (p)) + + +#elif LUA_FLOAT_TYPE == LUA_FLOAT_LONGDOUBLE /* }{ long double */ + +#define LUA_NUMBER long double + +#define l_floatatt(n) (LDBL_##n) + +#define LUAI_UACNUMBER long double + +#define LUA_NUMBER_FRMLEN "L" +#define LUA_NUMBER_FMT "%.19Lg" +#define LUA_NUMBER_FMT_N "%.21Lg" + +#define l_mathop(op) op##l + +#define lua_str2number(s,p) strtold((s), (p)) + +#elif LUA_FLOAT_TYPE == LUA_FLOAT_DOUBLE /* }{ double */ + +#define LUA_NUMBER double + +#define l_floatatt(n) (DBL_##n) + +#define LUAI_UACNUMBER double + +#define LUA_NUMBER_FRMLEN "" +#define LUA_NUMBER_FMT "%.15g" +#define LUA_NUMBER_FMT_N "%.17g" + +#define l_mathop(op) op + +#define lua_str2number(s,p) strtod((s), (p)) + +#else /* }{ */ + +#error "numeric float type not defined" + +#endif /* } */ + + + +/* +@@ LUA_UNSIGNED is the unsigned version of LUA_INTEGER. +@@ LUAI_UACINT is the result of a 'default argument promotion' +@@ over a LUA_INTEGER. +@@ LUA_INTEGER_FRMLEN is the length modifier for reading/writing integers. +@@ LUA_INTEGER_FMT is the format for writing integers. +@@ LUA_MAXINTEGER is the maximum value for a LUA_INTEGER. +@@ LUA_MININTEGER is the minimum value for a LUA_INTEGER. +@@ LUA_MAXUNSIGNED is the maximum value for a LUA_UNSIGNED. +@@ lua_integer2str converts an integer to a string. +*/ + + +/* The following definitions are good for most cases here */ + +#define LUA_INTEGER_FMT "%" LUA_INTEGER_FRMLEN "d" + +#define LUAI_UACINT LUA_INTEGER + +#define lua_integer2str(s,sz,n) \ + l_sprintf((s), sz, LUA_INTEGER_FMT, (LUAI_UACINT)(n)) + +/* +** use LUAI_UACINT here to avoid problems with promotions (which +** can turn a comparison between unsigneds into a signed comparison) +*/ +#define LUA_UNSIGNED unsigned LUAI_UACINT + + +/* now the variable definitions */ + +#if LUA_INT_TYPE == LUA_INT_INT /* { int */ + +#define LUA_INTEGER int +#define LUA_INTEGER_FRMLEN "" + +#define LUA_MAXINTEGER INT_MAX +#define LUA_MININTEGER INT_MIN + +#define LUA_MAXUNSIGNED UINT_MAX + +#elif LUA_INT_TYPE == LUA_INT_LONG /* }{ long */ + +#define LUA_INTEGER long +#define LUA_INTEGER_FRMLEN "l" + +#define LUA_MAXINTEGER LONG_MAX +#define LUA_MININTEGER LONG_MIN + +#define LUA_MAXUNSIGNED ULONG_MAX + +#elif LUA_INT_TYPE == LUA_INT_LONGLONG /* }{ long long */ + +/* use presence of macro LLONG_MAX as proxy for C99 compliance */ +#if defined(LLONG_MAX) /* { */ +/* use ISO C99 stuff */ + +#define LUA_INTEGER long long +#define LUA_INTEGER_FRMLEN "ll" + +#define LUA_MAXINTEGER LLONG_MAX +#define LUA_MININTEGER LLONG_MIN + +#define LUA_MAXUNSIGNED ULLONG_MAX + +#elif defined(LUA_USE_WINDOWS) /* }{ */ +/* in Windows, can use specific Windows types */ + +#define LUA_INTEGER __int64 +#define LUA_INTEGER_FRMLEN "I64" + +#define LUA_MAXINTEGER _I64_MAX +#define LUA_MININTEGER _I64_MIN + +#define LUA_MAXUNSIGNED _UI64_MAX + +#else /* }{ */ + +#error "Compiler does not support 'long long'. Use option '-DLUA_32BITS' \ + or '-DLUA_C89_NUMBERS' (see file 'luaconf.h' for details)" + +#endif /* } */ + +#else /* }{ */ + +#error "numeric integer type not defined" + +#endif /* } */ + +/* }================================================================== */ + + +/* +** {================================================================== +** Dependencies with C99 and other C details +** =================================================================== +*/ + +/* +@@ l_sprintf is equivalent to 'snprintf' or 'sprintf' in C89. +** (All uses in Lua have only one format item.) +*/ +#if !defined(LUA_USE_C89) +#define l_sprintf(s,sz,f,i) snprintf(s,sz,f,i) +#else +#define l_sprintf(s,sz,f,i) ((void)(sz), sprintf(s,f,i)) +#endif + + +/* +@@ lua_strx2number converts a hexadecimal numeral to a number. +** In C99, 'strtod' does that conversion. Otherwise, you can +** leave 'lua_strx2number' undefined and Lua will provide its own +** implementation. +*/ +#if !defined(LUA_USE_C89) +#define lua_strx2number(s,p) lua_str2number(s,p) +#endif + + +/* +@@ lua_pointer2str converts a pointer to a readable string in a +** non-specified way. +*/ +#define lua_pointer2str(buff,sz,p) l_sprintf(buff,sz,"%p",p) + + +/* +@@ lua_number2strx converts a float to a hexadecimal numeral. +** In C99, 'sprintf' (with format specifiers '%a'/'%A') does that. +** Otherwise, you can leave 'lua_number2strx' undefined and Lua will +** provide its own implementation. +*/ +#if !defined(LUA_USE_C89) +#define lua_number2strx(L,b,sz,f,n) \ + ((void)L, l_sprintf(b,sz,f,(LUAI_UACNUMBER)(n))) +#endif + + +/* +** 'strtof' and 'opf' variants for math functions are not valid in +** C89. Otherwise, the macro 'HUGE_VALF' is a good proxy for testing the +** availability of these variants. ('math.h' is already included in +** all files that use these macros.) +*/ +#if defined(LUA_USE_C89) || (defined(HUGE_VAL) && !defined(HUGE_VALF)) +#undef l_mathop /* variants not available */ +#undef lua_str2number +#define l_mathop(op) (lua_Number)op /* no variant */ +#define lua_str2number(s,p) ((lua_Number)strtod((s), (p))) +#endif + + +/* +@@ LUA_KCONTEXT is the type of the context ('ctx') for continuation +** functions. It must be a numerical type; Lua will use 'intptr_t' if +** available, otherwise it will use 'ptrdiff_t' (the nearest thing to +** 'intptr_t' in C89) +*/ +#define LUA_KCONTEXT ptrdiff_t + +#if !defined(LUA_USE_C89) && defined(__STDC_VERSION__) && \ + __STDC_VERSION__ >= 199901L +#include +#if defined(INTPTR_MAX) /* even in C99 this type is optional */ +#undef LUA_KCONTEXT +#define LUA_KCONTEXT intptr_t +#endif +#endif + + +/* +@@ lua_getlocaledecpoint gets the locale "radix character" (decimal point). +** Change that if you do not want to use C locales. (Code using this +** macro must include the header 'locale.h'.) +*/ +#if !defined(lua_getlocaledecpoint) +#define lua_getlocaledecpoint() (localeconv()->decimal_point[0]) +#endif + + +/* +** macros to improve jump prediction, used mostly for error handling +** and debug facilities. (Some macros in the Lua API use these macros. +** Define LUA_NOBUILTIN if you do not want '__builtin_expect' in your +** code.) +*/ +#if !defined(luai_likely) + +#if defined(__GNUC__) && !defined(LUA_NOBUILTIN) +#define luai_likely(x) (__builtin_expect(((x) != 0), 1)) +#define luai_unlikely(x) (__builtin_expect(((x) != 0), 0)) +#else +#define luai_likely(x) (x) +#define luai_unlikely(x) (x) +#endif + +#endif + + + +/* }================================================================== */ + + +/* +** {================================================================== +** Language Variations +** ===================================================================== +*/ + +/* +@@ LUA_NOCVTN2S/LUA_NOCVTS2N control how Lua performs some +** coercions. Define LUA_NOCVTN2S to turn off automatic coercion from +** numbers to strings. Define LUA_NOCVTS2N to turn off automatic +** coercion from strings to numbers. +*/ +/* #define LUA_NOCVTN2S */ +/* #define LUA_NOCVTS2N */ + + +/* +@@ LUA_USE_APICHECK turns on several consistency checks on the C API. +** Define it as a help when debugging C code. +*/ +/* #define LUA_USE_APICHECK */ + +/* }================================================================== */ + + +/* +** {================================================================== +** Macros that affect the API and must be stable (that is, must be the +** same when you compile Lua and when you compile code that links to +** Lua). +** ===================================================================== +*/ + +/* +@@ LUA_EXTRASPACE defines the size of a raw memory area associated with +** a Lua state with very fast access. +** CHANGE it if you need a different size. +*/ +#define LUA_EXTRASPACE (sizeof(void *)) + + +/* +@@ LUA_IDSIZE gives the maximum size for the description of the source +** of a function in debug information. +** CHANGE it if you want a different size. +*/ +#define LUA_IDSIZE 60 + + +/* +@@ LUAL_BUFFERSIZE is the initial buffer size used by the lauxlib +** buffer system. +*/ +#define LUAL_BUFFERSIZE ((int)(16 * sizeof(void*) * sizeof(lua_Number))) + + +/* +@@ LUAI_MAXALIGN defines fields that, when used in a union, ensure +** maximum alignment for the other items in that union. +*/ +#define LUAI_MAXALIGN lua_Number n; double u; void *s; lua_Integer i; long l + +/* }================================================================== */ + + + + + +/* =================================================================== */ + +/* +** Local configuration. You can use this space to add your redefinitions +** without modifying the main part of the file. +*/ + + + +#endif + diff --git a/libs/lua/include/lualib.h b/libs/lua/include/lualib.h new file mode 100644 index 0000000..068f60a --- /dev/null +++ b/libs/lua/include/lualib.h @@ -0,0 +1,65 @@ +/* +** $Id: lualib.h $ +** Lua standard libraries +** See Copyright Notice in lua.h +*/ + + +#ifndef lualib_h +#define lualib_h + +#include "lua.h" + + +/* version suffix for environment variable names */ +#define LUA_VERSUFFIX "_" LUA_VERSION_MAJOR "_" LUA_VERSION_MINOR + +#define LUA_GLIBK 1 +LUAMOD_API int (luaopen_base) (lua_State *L); + +#define LUA_LOADLIBNAME "package" +#define LUA_LOADLIBK (LUA_GLIBK << 1) +LUAMOD_API int (luaopen_package) (lua_State *L); + + +#define LUA_COLIBNAME "coroutine" +#define LUA_COLIBK (LUA_LOADLIBK << 1) +LUAMOD_API int (luaopen_coroutine) (lua_State *L); + +#define LUA_DBLIBNAME "debug" +#define LUA_DBLIBK (LUA_COLIBK << 1) +LUAMOD_API int (luaopen_debug) (lua_State *L); + +#define LUA_IOLIBNAME "io" +#define LUA_IOLIBK (LUA_DBLIBK << 1) +LUAMOD_API int (luaopen_io) (lua_State *L); + +#define LUA_MATHLIBNAME "math" +#define LUA_MATHLIBK (LUA_IOLIBK << 1) +LUAMOD_API int (luaopen_math) (lua_State *L); + +#define LUA_OSLIBNAME "os" +#define LUA_OSLIBK (LUA_MATHLIBK << 1) +LUAMOD_API int (luaopen_os) (lua_State *L); + +#define LUA_STRLIBNAME "string" +#define LUA_STRLIBK (LUA_OSLIBK << 1) +LUAMOD_API int (luaopen_string) (lua_State *L); + +#define LUA_TABLIBNAME "table" +#define LUA_TABLIBK (LUA_STRLIBK << 1) +LUAMOD_API int (luaopen_table) (lua_State *L); + +#define LUA_UTF8LIBNAME "utf8" +#define LUA_UTF8LIBK (LUA_TABLIBK << 1) +LUAMOD_API int (luaopen_utf8) (lua_State *L); + + +/* open selected libraries */ +LUALIB_API void (luaL_openselectedlibs) (lua_State *L, int load, int preload); + +/* open all libraries */ +#define luaL_openlibs(L) luaL_openselectedlibs(L, ~0, 0) + + +#endif diff --git a/libs/lua/liblua55.a b/libs/lua/liblua55.a new file mode 100644 index 0000000..d6ae770 Binary files /dev/null and b/libs/lua/liblua55.a differ diff --git a/libs/lua/lua55.dll b/libs/lua/lua55.dll new file mode 100644 index 0000000..ff62671 Binary files /dev/null and b/libs/lua/lua55.dll differ diff --git a/lua/config.lua b/lua/config.lua new file mode 100644 index 0000000..0eda968 --- /dev/null +++ b/lua/config.lua @@ -0,0 +1,71 @@ +-- PathEditor 配置文件 +-- 用于热更新 UI 参数,无需重新编译即可调整界面 + +local config = { + -- 应用程序信息 + app = { + name = "PathEditor", + name_readonly = "PathEditor (只读模式)" + }, + + -- 对话框设置 + dialog = { + size = "800x800", + minsize = "800x800", + select_dir = "选择目录" + }, + + -- 列表控件设置 + list = { + item_padding = "5x5", + backcolor = "255 255 255" + }, + + -- 按钮设置 + button = { + rastersize = "100x32", + new = "新建(N)", + edit = "编辑(E)", + browse = "浏览(B)...", + del = "删除(D)", + up = "上移(U)", + down = "下移(O)", + clean = "一键清理", + ok = "确定", + cancel = "取消", + help = "帮助(?)" + }, + + -- 标签文本 + label = { + title = "环境变量编辑器:", + search_placeholder = "输入关键词搜索...", + tab_sys = "系统变量 (System)", + tab_user = "用户变量 (User)" + }, + + -- 布局设置 + layout = { + vbox_gap = "5", + vbox_margin = "0x0", + vbox_all_margin = "10x10", + vbox_all_gap = "5", + hbox_gap = "10", + hbox_margin = "10x10", + hbox_alignment = "ACENTER" + }, + + -- 状态栏 + status = { + normal = "状态: 就绪", + readonly = "状态: ⚠️ 只读模式 (无管理员权限)", + saving = "状态: 保存中...", + saved = "状态: ✓ 保存成功", + error = "状态: ✗ 保存失败", + deleted = "状态: 已删除选中项", + loaded = "状态: 已加载系统和用户变量", + drag_folder_only = "提示: 只能拖拽文件夹添加到 PATH" + } +} + +return config \ No newline at end of file diff --git a/src/controller/callbacks.c b/src/controller/callbacks.c index aafe76e..f5f5b0c 100644 --- a/src/controller/callbacks.c +++ b/src/controller/callbacks.c @@ -2,6 +2,7 @@ #include "core/app_context.h" #include "core/registry_service.h" #include "core/path_manager.h" +#include "core/lua_config.h" #include "utils/string_ext.h" #include "utils/os_env.h" #include "ui/ui_utils.h" @@ -117,7 +118,7 @@ int btn_browse_cb(Ihandle *self) Ihandle *dlg = IupGetDialog(self); Ihandle *filedlg = IupFileDlg(); IupSetAttribute(filedlg, "DIALOGTYPE", "DIR"); - IupSetAttribute(filedlg, "TITLE", "选择目录"); + IupSetAttribute(filedlg, "TITLE", lua_config_get_string("dialog", "select_dir")); IupPopup(filedlg, IUP_CENTER, IUP_CENTER); @@ -160,7 +161,7 @@ int btn_del_cb(Ihandle *self) Ihandle *lbl_status = IupGetDialogChild(dlg, "LBL_STATUS"); if (lbl_status) - IupSetAttribute(lbl_status, "TITLE", "状态: 已删除选中项"); + IupSetAttribute(lbl_status, "TITLE", lua_config_get_string("status", "deleted")); return IUP_DEFAULT; } @@ -288,7 +289,7 @@ int list_dropfiles_cb(Ihandle *self, const char *filename, int num, int x, int y { Ihandle *lbl_status = IupGetDialogChild(dlg, "LBL_STATUS"); if (lbl_status) - IupSetAttribute(lbl_status, "TITLE", "提示: 只能拖拽文件夹添加到 PATH"); + IupSetAttribute(lbl_status, "TITLE", lua_config_get_string("status", "drag_folder_only")); } return IUP_DEFAULT; @@ -331,7 +332,7 @@ int btn_ok_cb(Ihandle *self) SendMessageTimeoutW(HWND_BROADCAST, WM_SETTINGCHANGE, 0, (LPARAM)L"Environment", SMTO_ABORTIFHUNG, 5000, NULL); IupMessage("成功", "系统和用户 PATH 环境变量均已更新!"); if (lbl_status) - IupSetAttribute(lbl_status, "TITLE", "状态: 全部保存成功"); + IupSetAttribute(lbl_status, "TITLE", lua_config_get_string("status", "saved")); } else if (sys_ok) { @@ -345,7 +346,7 @@ int btn_ok_cb(Ihandle *self) { IupMessage("错误", "保存失败!"); if (lbl_status) - IupSetAttribute(lbl_status, "TITLE", "状态: 保存失败"); + IupSetAttribute(lbl_status, "TITLE", lua_config_get_string("status", "error")); } return IUP_DEFAULT; } @@ -403,5 +404,5 @@ void load_all_paths(void) Ihandle *lbl_status = IupGetDialogChild(dlg, "LBL_STATUS"); if (lbl_status) - IupSetAttribute(lbl_status, "TITLE", "状态: 已加载系统和用户变量"); + IupSetAttribute(lbl_status, "TITLE", lua_config_get_string("status", "loaded")); } \ No newline at end of file diff --git a/src/core/lua_config.c b/src/core/lua_config.c new file mode 100644 index 0000000..e58d1a1 --- /dev/null +++ b/src/core/lua_config.c @@ -0,0 +1,200 @@ +#include "core/lua_config.h" +#include +#include +#include +#include +#include +#include + +static lua_State* G_L = NULL; +static int G_loaded = 0; +static const char* G_config_path = "lua/config.lua"; + +static const char* get_string_default(const char* section, const char* key) +{ + if (strcmp(section, "app") == 0) + { + if (strcmp(key, "name") == 0) return "PathEditor"; + if (strcmp(key, "name_readonly") == 0) return "PathEditor (只读模式)"; + } + else if (strcmp(section, "dialog") == 0) + { + if (strcmp(key, "size") == 0) return "800x800"; + if (strcmp(key, "minsize") == 0) return "800x800"; + if (strcmp(key, "select_dir") == 0) return "选择目录"; + } + else if (strcmp(section, "list") == 0) + { + if (strcmp(key, "item_padding") == 0) return "5x5"; + if (strcmp(key, "backcolor") == 0) return "255 255 255"; + } + else if (strcmp(section, "button") == 0) + { + if (strcmp(key, "rastersize") == 0) return "100x32"; + if (strcmp(key, "new") == 0) return "新建(N)"; + if (strcmp(key, "edit") == 0) return "编辑(E)"; + if (strcmp(key, "browse") == 0) return "浏览(B)..."; + if (strcmp(key, "del") == 0) return "删除(D)"; + if (strcmp(key, "up") == 0) return "上移(U)"; + if (strcmp(key, "down") == 0) return "下移(O)"; + if (strcmp(key, "clean") == 0) return "一键清理"; + if (strcmp(key, "ok") == 0) return "确定"; + if (strcmp(key, "cancel") == 0) return "取消"; + if (strcmp(key, "help") == 0) return "帮助(?)"; + } + else if (strcmp(section, "label") == 0) + { + if (strcmp(key, "title") == 0) return "环境变量编辑器:"; + if (strcmp(key, "search_placeholder") == 0) return "输入关键词搜索..."; + if (strcmp(key, "tab_sys") == 0) return "系统变量 (System)"; + if (strcmp(key, "tab_user") == 0) return "用户变量 (User)"; + } + else if (strcmp(section, "layout") == 0) + { + if (strcmp(key, "vbox_gap") == 0) return "5"; + if (strcmp(key, "vbox_margin") == 0) return "0x0"; + if (strcmp(key, "vbox_all_margin") == 0) return "10x10"; + if (strcmp(key, "vbox_all_gap") == 0) return "5"; + if (strcmp(key, "hbox_gap") == 0) return "10"; + if (strcmp(key, "hbox_margin") == 0) return "10x10"; + if (strcmp(key, "hbox_alignment") == 0) return "ACENTER"; + } + else if (strcmp(section, "status") == 0) + { + if (strcmp(key, "normal") == 0) return "状态: 就绪"; + if (strcmp(key, "readonly") == 0) return "状态: ⚠️ 只读模式 (无管理员权限)"; + if (strcmp(key, "saving") == 0) return "状态: 保存中..."; + if (strcmp(key, "saved") == 0) return "状态: ✓ 保存成功"; + if (strcmp(key, "error") == 0) return "状态: ✗ 保存失败"; + if (strcmp(key, "deleted") == 0) return "状态: 已删除选中项"; + if (strcmp(key, "loaded") == 0) return "状态: 已加载系统和用户变量"; + if (strcmp(key, "drag_folder_only") == 0) return "提示: 只能拖拽文件夹添加到 PATH"; + } + return ""; +} + +int lua_config_init(void) +{ + if (G_L != NULL) + { + return 0; + } + + G_L = luaL_newstate(); + if (G_L == NULL) + { + return -1; + } + + luaL_openlibs(G_L); + + if (luaL_dofile(G_L, G_config_path) != LUA_OK) + { + const char* err = lua_tostring(G_L, -1); + if (err) + { + fprintf(stderr, "[Lua Config] 加载配置文件失败: %s\n", err); + } + lua_settop(G_L, 0); + G_loaded = 0; + return 0; + } + + lua_settop(G_L, 0); + G_loaded = 1; + return 0; +} + +void lua_config_destroy(void) +{ + if (G_L != NULL) + { + lua_close(G_L); + G_L = NULL; + } + G_loaded = 0; +} + +const char* lua_config_get_string(const char* section, const char* key) +{ + if (G_L == NULL || section == NULL || key == NULL) + { + return get_string_default(section, key); + } + + lua_getglobal(G_L, "config"); + if (!lua_istable(G_L, -1)) + { + lua_settop(G_L, 0); + return get_string_default(section, key); + } + + lua_getfield(G_L, -1, section); + if (!lua_istable(G_L, -1)) + { + lua_settop(G_L, 0); + return get_string_default(section, key); + } + + lua_getfield(G_L, -1, key); + if (!lua_isstring(G_L, -1)) + { + lua_settop(G_L, 0); + return get_string_default(section, key); + } + + const char* value = lua_tostring(G_L, -1); + lua_settop(G_L, 0); + + return value ? value : get_string_default(section, key); +} + +int lua_config_get_int(const char* section, const char* key, int default_value) +{ + if (G_L == NULL || section == NULL || key == NULL) + { + return default_value; + } + + lua_getglobal(G_L, "config"); + if (!lua_istable(G_L, -1)) + { + lua_settop(G_L, 0); + return default_value; + } + + lua_getfield(G_L, -1, section); + if (!lua_istable(G_L, -1)) + { + lua_settop(G_L, 0); + return default_value; + } + + lua_getfield(G_L, -1, key); + if (!lua_isnumber(G_L, -1)) + { + lua_settop(G_L, 0); + return default_value; + } + + int value = (int)lua_tointeger(G_L, -1); + lua_settop(G_L, 0); + + return value; +} + +int lua_config_reload(void) +{ + if (G_L != NULL) + { + lua_close(G_L); + G_L = NULL; + } + + return lua_config_init(); +} + +int lua_config_is_loaded(void) +{ + return G_loaded; +} \ No newline at end of file diff --git a/src/main.c b/src/main.c index 4d2323d..6dc314a 100644 --- a/src/main.c +++ b/src/main.c @@ -4,11 +4,11 @@ #include #include #include "core/app_context.h" +#include "core/lua_config.h" #include "utils/string_ext.h" #include "utils/os_env.h" #include "controller/callbacks.h" #include "ui/main_window.h" -#include "config.h" /* !编译命令: @@ -39,6 +39,11 @@ int main(int argc, char **argv) IupOpen(&argc, &argv); IupSetGlobal("UTF8MODE", "YES"); + if (lua_config_init() != 0) + { + IupMessage("警告", "Lua 配置系统初始化失败,将使用默认值"); + } + // 在管理员模式下,解决无法拖拽文件到列表框的问题 (UIPI) // 需要加载 User32.dll 获取 ChangeWindowMessageFilter 函数 HMODULE hUser32 = LoadLibraryW(L"user32.dll"); @@ -81,7 +86,7 @@ int main(int argc, char **argv) { Ihandle *lbl_status = IupGetDialogChild(dlg, "LBL_STATUS"); if (lbl_status) - IupSetAttribute(lbl_status, "TITLE", "状态: ⚠️ 只读模式 (无管理员权限)"); + IupSetAttribute(lbl_status, "TITLE", lua_config_get_string("status", "readonly")); Ihandle *btn_new = IupGetDialogChild(dlg, "BTN_NEW"); Ihandle *btn_edit = IupGetDialogChild(dlg, "BTN_EDIT"); @@ -119,6 +124,7 @@ int main(int argc, char **argv) IupMainLoop(); destroy_app_context(ctx); + lua_config_destroy(); IupClose(); return 0; diff --git a/src/ui/dialogs.c b/src/ui/dialogs.c index 5c6cc05..30b80ec 100644 --- a/src/ui/dialogs.c +++ b/src/ui/dialogs.c @@ -1,4 +1,5 @@ #include "ui/dialogs.h" +#include "core/lua_config.h" #include #include @@ -27,13 +28,13 @@ int custom_input_dialog(const char *title, const char *label_text, char *buffer, IupSetAttribute(text, "RASTERSIZE", "500x"); IupSetAttribute(text, "NAME", "INPUT_TEXT"); - Ihandle *btn_ok = IupButton("确定", NULL); + Ihandle *btn_ok = IupButton(lua_config_get_string("button", "ok"), NULL); IupSetCallback(btn_ok, "ACTION", on_dialog_ok); - IupSetAttribute(btn_ok, "RASTERSIZE", "100x32"); + IupSetAttribute(btn_ok, "RASTERSIZE", lua_config_get_string("button", "rastersize")); - Ihandle *btn_cancel = IupButton("取消", NULL); + Ihandle *btn_cancel = IupButton(lua_config_get_string("button", "cancel"), NULL); IupSetCallback(btn_cancel, "ACTION", on_dialog_cancel); - IupSetAttribute(btn_cancel, "RASTERSIZE", "100x32"); + IupSetAttribute(btn_cancel, "RASTERSIZE", lua_config_get_string("button", "rastersize")); Ihandle *vbox = IupVbox( IupLabel(label_text), diff --git a/src/ui/main_window.c b/src/ui/main_window.c index 6ad6bab..10465ed 100644 --- a/src/ui/main_window.c +++ b/src/ui/main_window.c @@ -1,6 +1,6 @@ #include "ui/main_window.h" #include "controller/callbacks.h" -#include "config.h" +#include "core/lua_config.h" #include // 创建路径列表控件 @@ -9,8 +9,8 @@ static Ihandle *create_path_list(const char *name) Ihandle *list = IupFlatList(); IupSetAttribute(list, "NAME", name); IupSetAttribute(list, "EXPAND", "YES"); - IupSetAttribute(list, "ITEMPADDING", UI_LIST_ITEM_PADDING); - IupSetAttribute(list, "BACKCOLOR", UI_LIST_BACKCOLOR); + IupSetAttribute(list, "ITEMPADDING", lua_config_get_string("list", "item_padding")); + IupSetAttribute(list, "BACKCOLOR", lua_config_get_string("list", "backcolor")); IupSetAttribute(list, "BORDER", "YES"); IupSetAttribute(list, "CANFOCUS", "YES"); IupSetAttribute(list, "HLINE", "NO"); @@ -21,7 +21,7 @@ static Ihandle *create_path_list(const char *name) } // 创建主窗口 -Ihandle* create_main_window(void) +Ihandle *create_main_window(void) { // 创建系统路径列表 Ihandle *list_sys = create_path_list("LIST_SYS"); @@ -32,7 +32,7 @@ Ihandle* create_main_window(void) Ihandle *txt_search = IupText(NULL); IupSetAttribute(txt_search, "NAME", "TXT_SEARCH"); IupSetAttribute(txt_search, "EXPAND", "HORIZONTAL"); - IupSetAttribute(txt_search, "CUEBANNER", "输入关键词搜索..."); + IupSetAttribute(txt_search, "CUEBANNER", lua_config_get_string("label", "search_placeholder")); IupSetCallback(txt_search, "VALUECHANGED_CB", (Icallback)txt_search_cb); // 创建选项卡 @@ -41,24 +41,24 @@ Ihandle* create_main_window(void) IupVbox(list_user, NULL), NULL); IupSetAttribute(tabs_main, "NAME", "TABS_MAIN"); - IupSetAttribute(tabs_main, "TABTITLE0", "系统变量 (System)"); - IupSetAttribute(tabs_main, "TABTITLE1", "用户变量 (User)"); + IupSetAttribute(tabs_main, "TABTITLE0", lua_config_get_string("label", "tab_sys")); + IupSetAttribute(tabs_main, "TABTITLE1", lua_config_get_string("label", "tab_user")); IupSetAttribute(tabs_main, "TABTYPE", "TOP"); // 创建操作按钮 - Ihandle *btn_new = IupButton("新建(N)", NULL); + Ihandle *btn_new = IupButton(lua_config_get_string("button", "new"), NULL); IupSetAttribute(btn_new, "NAME", "BTN_NEW"); - Ihandle *btn_edit = IupButton("编辑(E)", NULL); + Ihandle *btn_edit = IupButton(lua_config_get_string("button", "edit"), NULL); IupSetAttribute(btn_edit, "NAME", "BTN_EDIT"); - Ihandle *btn_browse = IupButton("浏览(B)...", NULL); + Ihandle *btn_browse = IupButton(lua_config_get_string("button", "browse"), NULL); IupSetAttribute(btn_browse, "NAME", "BTN_BROWSE"); - Ihandle *btn_del = IupButton("删除(D)", NULL); + Ihandle *btn_del = IupButton(lua_config_get_string("button", "del"), NULL); IupSetAttribute(btn_del, "NAME", "BTN_DEL"); - Ihandle *btn_up = IupButton("上移(U)", NULL); + Ihandle *btn_up = IupButton(lua_config_get_string("button", "up"), NULL); IupSetAttribute(btn_up, "NAME", "BTN_UP"); - Ihandle *btn_down = IupButton("下移(O)", NULL); + Ihandle *btn_down = IupButton(lua_config_get_string("button", "down"), NULL); IupSetAttribute(btn_down, "NAME", "BTN_DOWN"); - Ihandle *btn_clean = IupButton("一键清理", NULL); + Ihandle *btn_clean = IupButton(lua_config_get_string("button", "clean"), NULL); IupSetAttribute(btn_clean, "NAME", "BTN_CLEAN"); // 设置按钮回调 @@ -71,13 +71,14 @@ Ihandle* create_main_window(void) IupSetCallback(btn_clean, "ACTION", (Icallback)btn_clean_cb); // 设置按钮大小 - IupSetAttribute(btn_new, "RASTERSIZE", UI_BTN_RASTERSIZE); - IupSetAttribute(btn_edit, "RASTERSIZE", UI_BTN_RASTERSIZE); - IupSetAttribute(btn_browse, "RASTERSIZE", UI_BTN_RASTERSIZE); - IupSetAttribute(btn_del, "RASTERSIZE", UI_BTN_RASTERSIZE); - IupSetAttribute(btn_up, "RASTERSIZE", UI_BTN_RASTERSIZE); - IupSetAttribute(btn_down, "RASTERSIZE", UI_BTN_RASTERSIZE); - IupSetAttribute(btn_clean, "RASTERSIZE", UI_BTN_RASTERSIZE); + const char *btn_size = lua_config_get_string("button", "rastersize"); + IupSetAttribute(btn_new, "RASTERSIZE", btn_size); + IupSetAttribute(btn_edit, "RASTERSIZE", btn_size); + IupSetAttribute(btn_browse, "RASTERSIZE", btn_size); + IupSetAttribute(btn_del, "RASTERSIZE", btn_size); + IupSetAttribute(btn_up, "RASTERSIZE", btn_size); + IupSetAttribute(btn_down, "RASTERSIZE", btn_size); + IupSetAttribute(btn_clean, "RASTERSIZE", btn_size); // 创建操作按钮垂直布局 Ihandle *vbox_btns = IupVbox( @@ -87,25 +88,25 @@ Ihandle* create_main_window(void) IupFill(), btn_up, btn_down, NULL); - IupSetAttribute(vbox_btns, "GAP", UI_VBOX_GAP); - IupSetAttribute(vbox_btns, "MARGIN", UI_VBOX_MARGIN); + IupSetAttribute(vbox_btns, "GAP", lua_config_get_string("layout", "vbox_gap")); + IupSetAttribute(vbox_btns, "MARGIN", lua_config_get_string("layout", "vbox_margin")); // 创建主窗口水平布局 Ihandle *hbox_main = IupHbox(tabs_main, vbox_btns, NULL); - IupSetAttribute(hbox_main, "GAP", UI_HBOX_GAP); - IupSetAttribute(hbox_main, "MARGIN", UI_HBOX_MARGIN); + IupSetAttribute(hbox_main, "GAP", lua_config_get_string("layout", "hbox_gap")); + IupSetAttribute(hbox_main, "MARGIN", lua_config_get_string("layout", "hbox_margin")); // 创建状态标签 - Ihandle *lbl_status = IupLabel("状态: 就绪"); + Ihandle *lbl_status = IupLabel(lua_config_get_string("status", "normal")); IupSetAttribute(lbl_status, "NAME", "LBL_STATUS"); IupSetAttribute(lbl_status, "EXPAND", "HORIZONTAL"); // 创建底部按钮 - Ihandle *btn_ok = IupButton("确定", NULL); + Ihandle *btn_ok = IupButton(lua_config_get_string("button", "ok"), NULL); IupSetAttribute(btn_ok, "NAME", "BTN_OK"); - Ihandle *btn_cancel = IupButton("取消", NULL); + Ihandle *btn_cancel = IupButton(lua_config_get_string("button", "cancel"), NULL); IupSetAttribute(btn_cancel, "NAME", "BTN_CANCEL"); - Ihandle *btn_help = IupButton("帮助(?)", NULL); + Ihandle *btn_help = IupButton(lua_config_get_string("button", "help"), NULL); IupSetAttribute(btn_help, "NAME", "BTN_HELP"); // 设置底部按钮回调 @@ -114,31 +115,31 @@ Ihandle* create_main_window(void) IupSetCallback(btn_help, "ACTION", (Icallback)btn_help_cb); // 设置底部按钮大小 - IupSetAttribute(btn_ok, "RASTERSIZE", UI_BTN_RASTERSIZE); - IupSetAttribute(btn_cancel, "RASTERSIZE", UI_BTN_RASTERSIZE); - IupSetAttribute(btn_help, "RASTERSIZE", UI_BTN_RASTERSIZE); + IupSetAttribute(btn_ok, "RASTERSIZE", btn_size); + IupSetAttribute(btn_cancel, "RASTERSIZE", btn_size); + IupSetAttribute(btn_help, "RASTERSIZE", btn_size); // 创建底部按钮水平布局 Ihandle *hbox_bottom = IupHbox(lbl_status, IupFill(), btn_help, btn_ok, btn_cancel, NULL); - IupSetAttribute(hbox_bottom, "GAP", UI_HBOX_GAP); - IupSetAttribute(hbox_bottom, "MARGIN", UI_HBOX_MARGIN); - IupSetAttribute(hbox_bottom, "ALIGNMENT", UI_HBOX_ALIGNMENT); + IupSetAttribute(hbox_bottom, "GAP", lua_config_get_string("layout", "hbox_gap")); + IupSetAttribute(hbox_bottom, "MARGIN", lua_config_get_string("layout", "hbox_margin")); + IupSetAttribute(hbox_bottom, "ALIGNMENT", lua_config_get_string("layout", "hbox_alignment")); // 创建主窗口垂直布局 Ihandle *vbox_all = IupVbox( - IupLabel("环境变量编辑器:"), + IupLabel(lua_config_get_string("label", "title")), txt_search, hbox_main, hbox_bottom, NULL); - IupSetAttribute(vbox_all, "MARGIN", UI_VBOX_ALL_MARGIN); - IupSetAttribute(vbox_all, "GAP", UI_VBOX_ALL_GAP); + IupSetAttribute(vbox_all, "MARGIN", lua_config_get_string("layout", "vbox_all_margin")); + IupSetAttribute(vbox_all, "GAP", lua_config_get_string("layout", "vbox_all_gap")); // 创建主窗口对话框 Ihandle *dlg = IupDialog(vbox_all); - IupSetAttribute(dlg, "TITLE", APP_NAME); - IupSetAttribute(dlg, "RASTERSIZE", UI_DLG_SIZE); - IupSetAttribute(dlg, "MINSIZE", UI_DLG_MINSIZE); + IupSetAttribute(dlg, "TITLE", lua_config_get_string("app", "name")); + IupSetAttribute(dlg, "RASTERSIZE", lua_config_get_string("dialog", "size")); + IupSetAttribute(dlg, "MINSIZE", lua_config_get_string("dialog", "minsize")); IupSetAttribute(dlg, "MINBOX", "NO"); IupSetAttribute(dlg, "MAXBOX", "NO");