|
|
@ -17,6 +17,9 @@ static size_t len = 0; |
|
|
static size_t cursor_pos = 0; |
|
|
static size_t cursor_pos = 0; |
|
|
static int escape_mode = 0; // 0: 正常, 1: 收到 ESC, 2: 收到 ESC [
|
|
|
static int escape_mode = 0; // 0: 正常, 1: 收到 ESC, 2: 收到 ESC [
|
|
|
|
|
|
|
|
|
|
|
|
static lua_help_entry_t help_entries[MAX_HELP_ENTRIES]; |
|
|
|
|
|
static int help_entry_count = 0; |
|
|
|
|
|
|
|
|
static void add_to_history(const char *cmd) |
|
|
static void add_to_history(const char *cmd) |
|
|
{ |
|
|
{ |
|
|
if (cmd == NULL || strlen(cmd) == 0) return; |
|
|
if (cmd == NULL || strlen(cmd) == 0) return; |
|
|
@ -397,6 +400,39 @@ static char *readline(const char *_pcPrompt, char *_pcBuffer, int _iSize, int _i |
|
|
|
|
|
|
|
|
extern int luaopen_stm32(lua_State *L); |
|
|
extern int luaopen_stm32(lua_State *L); |
|
|
|
|
|
|
|
|
|
|
|
void lua_register_help(lua_State *L, const char *name, lua_CFunction func, const char *description) |
|
|
|
|
|
{ |
|
|
|
|
|
lua_pushcfunction(L, func); |
|
|
|
|
|
lua_setglobal(L, name); |
|
|
|
|
|
|
|
|
|
|
|
if (help_entry_count < MAX_HELP_ENTRIES) |
|
|
|
|
|
{ |
|
|
|
|
|
help_entries[help_entry_count].name = name; |
|
|
|
|
|
help_entries[help_entry_count].description = description; |
|
|
|
|
|
help_entry_count++; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void lua_add_help_entry(const char *name, const char *description) |
|
|
|
|
|
{ |
|
|
|
|
|
if (help_entry_count < MAX_HELP_ENTRIES) |
|
|
|
|
|
{ |
|
|
|
|
|
help_entries[help_entry_count].name = name; |
|
|
|
|
|
help_entries[help_entry_count].description = description; |
|
|
|
|
|
help_entry_count++; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static int l_help(lua_State *L) |
|
|
|
|
|
{ |
|
|
|
|
|
lua_print("Available commands:\n"); |
|
|
|
|
|
for (int i = 0; i < help_entry_count; i++) |
|
|
|
|
|
{ |
|
|
|
|
|
lua_print(" %-16s %s\n", help_entries[i].name, help_entries[i].description); |
|
|
|
|
|
} |
|
|
|
|
|
return 0; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
static int l_name(lua_State *L) |
|
|
static int l_name(lua_State *L) |
|
|
{ |
|
|
{ |
|
|
lua_print("%s\n", Rd_GetBuildTime()); |
|
|
lua_print("%s\n", Rd_GetBuildTime()); |
|
|
@ -405,8 +441,8 @@ static int l_name(lua_State *L) |
|
|
|
|
|
|
|
|
static int luaopen_default(lua_State *L) |
|
|
static int luaopen_default(lua_State *L) |
|
|
{ |
|
|
{ |
|
|
lua_pushcfunction(L, l_name); |
|
|
lua_register_help(L, "help", l_help, "Show this help message"); |
|
|
lua_setglobal(L, "name"); // name = l_name
|
|
|
lua_register_help(L, "name", l_name, "Show build time"); |
|
|
return 0; |
|
|
return 0; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -415,6 +451,7 @@ int lua_init(lua_output _lua_print) |
|
|
if (NULL == _lua_print) return -1; |
|
|
if (NULL == _lua_print) return -1; |
|
|
lua_print = _lua_print; |
|
|
lua_print = _lua_print; |
|
|
|
|
|
|
|
|
|
|
|
help_entry_count = 0; |
|
|
buffer_len = 0; |
|
|
buffer_len = 0; |
|
|
capacity = 256; |
|
|
capacity = 256; |
|
|
len = 0; |
|
|
len = 0; |
|
|
|