diff --git a/CMakeLists.txt b/CMakeLists.txt index 15bad08..bef24da 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,6 +4,9 @@ project(interface_test VERSION 1.0.0 LANGUAGES C CXX) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) +site_name(BUILD_HOSTNAME) +add_definitions(-DRD_HOSTNAME="${BUILD_HOSTNAME}") + set(GENERATED_COMMON_DIR "${CMAKE_BINARY_DIR}/library/common") file(MAKE_DIRECTORY "${GENERATED_COMMON_DIR}") set(COMMON_CFG_IN "${CMAKE_CURRENT_SOURCE_DIR}/library/common/common_cfg.h.in") diff --git a/library/common/common.c b/library/common/common.c index 03072eb..af02486 100644 --- a/library/common/common.c +++ b/library/common/common.c @@ -4,7 +4,7 @@ #include "common.h" #include // 必须包含此头文件以使用变参宏 -static char g_sBuildTime[64] = {0}; +static char g_sBuildTime[128] = {0}; WEAK void elog_output(uint8_t level, const char *tag, const char *file, const char *func, long line, const char *format, ...) { @@ -97,6 +97,10 @@ int Rd_RegularFileExists(const char *_psPath) char *Rd_GetBuildTime(void) { - snprintf(g_sBuildTime, sizeof(g_sBuildTime), "%s %s", __DATE__, __TIME__); +#ifdef RD_HOSTNAME + snprintf(g_sBuildTime, sizeof(g_sBuildTime), "%s build [%s %s] by %s", RD_VERSION, __DATE__, __TIME__, RD_HOSTNAME); +#else + snprintf(g_sBuildTime, sizeof(g_sBuildTime), "%s build [%s %s]", RD_VERSION, __DATE__, __TIME__); +#endif return g_sBuildTime; } \ No newline at end of file diff --git a/library/common/common_cfg.h.in b/library/common/common_cfg.h.in index 5408426..63bd9d7 100644 --- a/library/common/common_cfg.h.in +++ b/library/common/common_cfg.h.in @@ -12,6 +12,7 @@ extern "C"{ #cmakedefine MEM_POOL_TOTAL_SIZE @MEM_POOL_TOTAL_SIZE@ #cmakedefine CONFIG_CAN_NEW_VERSION @CONFIG_CAN_NEW_VERSION@ +#cmakedefine RD_VERSION "@RD_VERSION@" #cmakedefine IOC_100PIN #cmakedefine USE_TALNET diff --git a/library/common/include/common.h b/library/common/include/common.h index ab36fbc..41a96bf 100644 --- a/library/common/include/common.h +++ b/library/common/include/common.h @@ -11,6 +11,10 @@ #define RD_NULL -2 //对象为空 #define RD_INVALUE -3 //非法参数 +#ifndef RD_VERSION +#define RD_VERSION "N/A" +#endif + /* 原子操作跨平台要兼容 */ #if defined(__GNUC__) || defined(__clang__) #define ATOMIC_LOAD(ptr, type, order) __atomic_load_n((ptr), (order)) diff --git a/lua/lua.c b/lua/lua.c index dc5c0a9..f74dfeb 100644 --- a/lua/lua.c +++ b/lua/lua.c @@ -397,6 +397,19 @@ static char *readline(const char *_pcPrompt, char *_pcBuffer, int _iSize, int _i extern int luaopen_stm32(lua_State *L); +static int l_name(lua_State *L) +{ + lua_print("%s\n", Rd_GetBuildTime()); + return 0; +} + +static int luaopen_default(lua_State *L) +{ + lua_pushcfunction(L, l_name); + lua_setglobal(L, "name"); // name = l_name + return 0; +} + int lua_init(lua_output _lua_print) { if (NULL == _lua_print) return -1; @@ -443,6 +456,7 @@ int lua_init(lua_output _lua_print) #ifdef USE_LUA_ST luaopen_stm32(L); #endif + luaopen_default(L); lua_print("Lua REPL V5.4\nType 'exit' or Ctrl+D to quit.\n\n"); lua_print("%s", incomplete ? CONT_PROMPT : PROMPT); return 0;