{"id":13500046,"url":"https://github.com/dpapavas/luaprompt","last_synced_at":"2026-01-10T22:46:54.843Z","repository":{"id":20305184,"uuid":"23579002","full_name":"dpapavas/luaprompt","owner":"dpapavas","description":"An embeddable Lua command prompt as well as a stand-alone interpreter with pretty-printing and autocompletion.","archived":false,"fork":false,"pushed_at":"2024-10-27T19:25:25.000Z","size":124,"stargazers_count":94,"open_issues_count":0,"forks_count":16,"subscribers_count":9,"default_branch":"master","last_synced_at":"2024-10-27T23:54:10.764Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dpapavas.png","metadata":{"files":{"readme":"README","changelog":"ChangeLog","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-09-02T13:08:59.000Z","updated_at":"2024-10-27T19:25:21.000Z","dependencies_parsed_at":"2024-01-16T14:04:00.392Z","dependency_job_id":"ecc1298c-f812-416a-bc9a-732cd74bdefa","html_url":"https://github.com/dpapavas/luaprompt","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dpapavas%2Fluaprompt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dpapavas%2Fluaprompt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dpapavas%2Fluaprompt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dpapavas%2Fluaprompt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dpapavas","download_url":"https://codeload.github.com/dpapavas/luaprompt/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246145012,"owners_count":20730494,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T22:00:50.362Z","updated_at":"2026-01-10T22:46:54.780Z","avatar_url":"https://github.com/dpapavas.png","language":"C","funding_links":[],"categories":["C"],"sub_categories":[],"readme":"luaprompt\n\nCopyright (C) 2012-2023 Dimitris Papavasileiou \u003cdpapavas@protonmail.ch\u003e\n\nluaprompt is both an interactive Lua prompt that can be used instead\nof the official interpreter, as well as a module that provides a Lua\ncommand prompt that can be embedded in a host application.  As a\nstandalone interpreter it provides many conveniences that are missing\nfrom the official Lua interpreter.  As an embedded prompt, it's meant\nfor applications that use Lua as a configuration or interface language\nand can therefore benefit from an interactive prompt for debugging or\nregular use.\n\nluaprompt features:\n\n* Readline-based input with history and completion: In particular all\n  keywords, global variables and table accesses (with string or\n  integer keys) can be completed in addition to readline's standard\n  file completion.  Module names are also completed, for modules\n  installed in the standard directories, and completed modules can\n  optionally be loaded.\n\n* Persistent command history (retained across sessions), as well as\n  recording of command results for future reference.\n\n* Proper value pretty-printing for interactive use: When an expression\n  is entered at the prompt, all returned values are printed\n  (prepending with an equal sign is not required).  Values are printed\n  in a descriptive way that tries to be as readable as possible.  The\n  formatting tries to mimic Lua code (this is done to minimize\n  ambiguities and no guarantees are made that it is valid code).\n\n* Color highlighting of error messages and variable printouts.\n\nInstallation\n============\n\nluaprompt is available as a rock.  It can be installed via LuaRocks with:\n\n    luarocks install luaprompt\n\nAlternatively, you can customize the behavior as described in the\n\"Configuration\" section.  Start by downloading and unpacking the\nsources with:\n\n    luarocks unpack luaprompt\n\nChange to the directory it was downloaded to, edit the rockspec file\nto add, remove or change the default configuration macros, and then\nbuild and install with:\n\n    luarocks make \u003crockspec-file\u003e\n\nStandalone usage\n================\n\nBesides the luaprompt module, the rock contains a standalone\ninterpreter based on luaprompt. It tries to mimic the standard Lua\ninterpreter as much as possible (currently only the -E flag is not\nsupported) while providing the extra set of features described above.\n          \nTo invoke the interpreter, simply type \"luap\" instead of \"lua\" on the\ncommand line.  A file with custom configuration, or startup actions\ncan be placed either at \"~/.luaprc.lua\", or, alternatively, at\n\"~/.config/luaprc.lua\".  The first of these to be found is loaded and\nexecuted at startup.\n\nAs an example, an rc file setting alternate prompts and history file\nlocations, would contain something like the following:\n\nlocal prompt = require \"prompt\"\nprompt.history = \"/tmp/lua_history\"\nprompt.prompts = {\"%  \", \"%% \"}\n\nThe prompt module\n=================\n     \nUsing the module is pretty straightforward, as it essentially wraps\nthe calls described in the section on embedding luaprompt below.  This\nfunctionality is available, either in variables which can be set or\nqueried, or in Lua functions.  An example session, which covers\neverything and should be self-explanatory, follows:\n\n\u003e prompt = require \"prompt\"\n\u003e prompt.colorize = true\n\u003e prompt.name = \"myprompt\"\n\u003e prompt.history = \"/tmp/.myprompt_history\"\n\u003e prompt.prompts = {\n\u003e\u003e    function () return string.format(\"(%d)%% \", os.time()) end,\n\u003e\u003e    \"%% \"\n\u003e\u003e }\n\u003e prompt.enter()\n%   _G[nil] = \n%% nil\nmyprompt:2: table index is nil\n\nStack trace:\n\t#0 [C]: in function '__newindex'\n\t#1 myprompt:2: in the main chunk\n\t#2 [C]: in function 'enter'\n\t#3 stdin:1: in the main chunk\n\t#4 [C]: in function ?\n\n% ^D \n\u003e\n\nOne can also use just the pretty-printer of luaprompt, by calling\nprompt.describe, which returns a string with a pretty print-out of the\nargument.  For example:\n\n\u003e =prompt.describe(coroutine)\n{ \n  create = \u003cfunction: 0x41a8b0\u003e,\n  yield = \u003cfunction: 0x41a630\u003e,\n  wrap = \u003cfunction: 0x41a910\u003e,\n  running = \u003cfunction: 0x41a890\u003e,\n  resume = \u003cfunction: 0x41a9e0\u003e,\n  status = \u003cfunction: 0x41a770\u003e,\n}\n\nConfiguration\n=============\n\nYou can customize luaprompts command line interface, as it is based on\nGNU Readline.  This includes the ability to change behavior, such as\nhow completion is performed, define additional keybindings or redefine\nexisting ones, define custom macros and other possibilities.  It is\ntherefore highly recommended to consult the Readline's documentation\nfor more information.\n\nNote that luaprompt sets its application name, so that you can have\ncustom Readline configuration, that will be effective for luaprompt\nonly (thus not affecting every other Readline-enabled application on\nyour system).  You can achieve that using $if ... $endif conditional\nconstructs within Readline's initialization file.  Again, see\nReadline's documentation for more information.\n\nAt build time, you can use several macros in order to configure\nluaprompt's functionality, by defining them in your Makefile.  For\ninstance, to pass the macro MACRO_NAME to the compiler, simply add\n-DMACRO_NAME, or -DMACRO_WITH_VALUE=\\\"value\\\" to the compile flags.\n\nThe following macros control auto-completion:\n\nCOMPLETE_KEYWORDS:       Keywords such as for, while, etc\nCOMPLETE_MODULES:        Module names\nCOMPLETE_TABLE_KEYS:     Table keys, including global variables\nCOMPLETE_METATABLE_KEYS: Keys in the __index metafield, if it\n                         exists and is a table\nCOMPLETE_FILE_NAMES:     File names\n\nDefine SAVE_RESULTS to enable tracking of results.  When enabled each\nreturned value, that is, each value the prompt prints out, is also\nadded to a table for future reference.\n\nThe name of the table holding the results can be configured by\ndefining RESULTS_TABLE_NAME to the desired table name (as a C string).\n\nThe table holding the results, can also be made to have weak values,\nso as not to interfere with garbage collection.  To enable this,\ndefine WEAK_RESULTS.\n\nUncomment the following line and customize the prefix as desired to\n\nYou can keep the auto-completer from considering certain table keys\n(and hence global variables) for completion, based on their prefix.\nTo enable this behavior, define HIDDEN_KEY_PREFIX to the desired\nprefix (as a C string).\n\nWhen completing certain kinds of values, such as tables or\nfunctions, the completer also appends certain useful suffixes such\nas '.', '[' or '('. Normally these are appended only when the\nvalue's name has already been fully entered, or previously fully\ncompleted, so that one can still complete the name without the\nsuffix.  In order to append the suffix, one then only has to press\nthe completion key one more time.\n\nDefine ALWAYS_APPEND_SUFFIXES to make the completer always append\nthese suffixes.\n\nThe autocompleter can complete module names, as if they were already\nrequire'd and available as a global variable.  Once the module name is\nfully completed, a further tab press loads the module and exports it\nas a global variable so that all further tab-completions now apply to\nthe module's table.\n\nYou can disable this functionality, by defining NO_MODULE_LOAD.\nModule names will then only be completed inside strings (for use with\nrequire).\n\nTo make the auto-completer ask for confirmation before loading or\nglobalizing a module, define CONFIRM_MODULE_LOAD.\n\nEmbedded Usage\n==============\n\nTo embed luaprompt into a host application, simply compile and link\nprompt.c with your sources.  A POSIX environment is assumed and GNU\nReadline is required for proper command line editing.  If it is\nprovided, you should define the macros HAVE_LIBREADLINE and\nHAVE_READLINE_HISTORY.  You should also define HAVE_IOCTL, unless your\nenvironment doesn't support the TIOCGWINSZ ioctl call to get the\nterminal width.\n\nThe API is very simple:\n\nvoid luap_enter (lua_State *L)\nCall this to begin an interactive session.  The session can be\nterminated with Ctrl-D.\n\nvoid luap_setname (lua_State *L, const char *name)\nSet the name of the application.  This is basically the chunk name\ndisplayed with error messages.  The default program name is \"lua\".\n\nvoid luap_setprompts (lua_State *L, const char *single, char *multi)\nProvide two prompts, one for single-line and one for multi-line\ninput. The defaults prompts are \"\u003e \" and \"\u003e\u003e \".\n\nvoid luap_setpromptfuncs (lua_State *L)\nPops two values off the stack and, if they're functions, uses them as\nprompt generators, for single and multi-line prompts respectively.  If\nany of the supplied values are not functions, the prompts set via\nluap_setprompts above, or the last generated prompts are used.  The\nsupplied functions should return a string (which will be used as a\nprompt).\n\nvoid luap_sethistory (lua_State *L, const char *file) Set the file to\nbe used to perist the command history across sessions.  If this\nfunction isn't called the command history is lost on session exit.\nNote that the provided name is used as-is, that is, it is not expanded\nas if it was entered at the shell so you cannot use a string of the\nform \"~/.lua_history\" for example.\n\nvoid luap_setcolor (lua_State *L, int enable)\nSetting enable to zero disables color output.  Color output is enabled\nby default if the output has not been redirected to a file or pipe.\n\nThere are also matching luap_get* calls, which work much like you'd\nexpect them to:\n\nvoid luap_getprompts(lua_State *L, const char **single, const char **multi)\nvoid luap_getpromptfuncs(lua_State *L)\nvoid luap_gethistory(lua_State *L, const char **file)\nvoid luap_getcolor(lua_State *L, int *enabled)\nvoid luap_getname(lua_State *L, const char **name)\n\nIn addition to the above the following calls, which are meant for\ninternal use can be used by the host application as well if required.\n\nchar *luap_describe (lua_State *L, int index)\nReturns a string with a human-readable serialization of the value at\nthe specified index.\n\nint luap_call (lua_State *L, int n)\nCalls a function with n arguments and provides a stack trace on error.\nThis is equivalent to calling lua_pcall with LUA_MULTRET.\n\nLicense\n=======\n\nluaprompt is released under the terms and conditions of the MIT/X11\nlicense.  See the LICENSE file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdpapavas%2Fluaprompt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdpapavas%2Fluaprompt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdpapavas%2Fluaprompt/lists"}