26 #define RTTLUA_BOILER "OROCOS RTTLua (TLSF)" 28 #define RTTLUA_BOILER "OROCOS RTTLua" 30 #define RTTLUA_VERSION "1.0-beta5" 31 #define XSTR(x) STR(x) 43 luaL_error(L,
"interrupted!");
55 "usage: %s [options] [script [args]].\n" 56 "Available options are:\n" 57 " -e stat execute string " LUA_QL(
"stat")
"\n" 58 " -l name require library " LUA_QL(
"name")
"\n" 59 " -i enter interactive mode after executing " LUA_QL(
"script")
"\n" 60 " -v show version information\n" 61 " -- stop handling options\n" 62 " - execute stdin and stop handling options\n" 68 void l_message (
const char *pname,
const char *msg) {
69 if (pname) fprintf(stderr,
"%s: ", pname);
70 fprintf(stderr,
"%s\n", msg);
78 if (msg == NULL) msg =
"(error object is not a string)";
113 signal(SIGINT, SIG_DFL);
125 l_message(NULL,
" Use Ctrl-d to quit." );
132 while (argv[argc]) argc++;
133 narg = argc - (n + 1);
134 luaL_checkstack(L, narg + 3,
"too many arguments to script");
135 for (i=n+1; i < argc; i++)
138 for (i=0; i < argc; i++) {
147 int status = luaL_loadfile(L, name) ||
docall(L, 0, 1);
153 int status = luaL_loadbuffer(L, s, strlen(s), name) ||
docall(L, 0, 1);
167 if (p == NULL) p = (firstline ? LUA_PROMPT : LUA_PROMPT2);
177 const char *tp = msg + lmsg - (
sizeof(LUA_QL(
"<eof>")) - 1);
178 if (strstr(msg, LUA_QL(
"<eof>")) == tp) {
188 char buffer[LUA_MAXINPUT];
192 if (lua_readline(L, b, prmt) == 0)
195 if (l > 0 && b[l-1] ==
'\n')
197 if (firstline && b[0] ==
'=')
230 while ((status =
loadline(L)) != -1) {
231 if (status == 0) status =
docall(L, 0, 0);
238 "error calling " LUA_QL(
"print")
" (%s)",
252 int narg =
getargs(L, argv, n);
255 if (strcmp(fname,
"-") == 0 && strcmp(argv[n-1],
"--") != 0)
257 status = luaL_loadfile(L, fname);
260 status =
docall(L, narg, 0);
268 #define notail(x) {if ((x)[2] != '\0') return -1;} 273 for (i = 1; argv[i] != NULL; i++) {
274 if (argv[i][0] !=
'-')
276 switch (argv[i][1]) {
279 return (argv[i+1] != NULL ? i+1 : 0);
292 if (argv[i][2] ==
'\0') {
294 if (argv[i] == NULL)
return -1;
306 for (i = 1; i < n; i++) {
307 if (argv[i] == NULL)
continue;
308 lua_assert(argv[i][0] ==
'-');
309 switch (argv[i][1]) {
311 const char *chunk = argv[i] + 2;
312 if (*chunk ==
'\0') chunk = argv[++i];
313 lua_assert(chunk != NULL);
314 if (
dostring(L, chunk,
"=(command line)") != 0)
319 const char *filename = argv[i] + 2;
320 if (*filename ==
'\0') filename = argv[++i];
321 lua_assert(filename != NULL);
334 const char *init = getenv(LUA_INIT);
335 if (init == NULL)
return 0;
336 else if (init[0] ==
'@')
339 return dostring(L, init,
"=" LUA_INIT);
354 int has_i = 0, has_v = 0, has_e = 0;
356 if (argv[0] && argv[0][0])
progname = argv[0];
361 if (s->
status != 0)
return 0;
362 script =
collectargs(argv, &has_i, &has_v, &has_e);
370 if (s->
status != 0)
return 0;
373 if (s->
status != 0)
return 0;
376 else if (script == 0 && !has_e && !has_v) {
377 if (lua_stdin_is_tty()) {
393 l_message(argv[0],
"cannot create state: not enough memory");
401 return (status || s.
status) ? EXIT_FAILURE : EXIT_SUCCESS;
413 return (status || s.
status) ? EXIT_FAILURE : EXIT_SUCCESS;
LUA_API int() lua_pcall(lua_State *L, int nargs, int nresults, int errfunc)
#define lua_pushliteral(L, s)
LUA_API void() lua_pushstring(lua_State *L, const char *s)
LUA_API void() lua_pushinteger(lua_State *L, lua_Integer n)
LUA_API void() lua_pushvalue(lua_State *L, int idx)
static lua_State * globalL
static int loadline(lua_State *L)
#define lua_tostring(L, i)
static int collectargs(char **argv, int *pi, int *pv, int *pe)
static int incomplete(lua_State *L, int status)
int dofile(lua_State *L, const char *name)
LUA_API void() lua_insert(lua_State *L, int idx)
static int dolibrary(lua_State *L, const char *name)
static int report(lua_State *L, int status)
static int pushline(lua_State *L, int firstline)
#define lua_setglobal(L, s)
#define lua_isfunction(L, n)
static int getargs(lua_State *L, char **argv, int n)
int main_args(lua_State *L, int argc, char **argv)
LUA_API void() lua_concat(lua_State *L, int n)
static void laction(int i)
int main(int argc, char **argv)
LUA_API void() lua_createtable(lua_State *L, int narr, int nrec)
#define lua_istable(L, n)
LUA_API int() lua_cpcall(lua_State *L, lua_CFunction func, void *ud)
struct lua_State lua_State
#define lua_getglobal(L, s)
LUA_API int() lua_isstring(lua_State *L, int idx)
LUA_API int() lua_gc(lua_State *L, int what, int data)
LUA_API void() lua_close(lua_State *L)
static const char * get_prompt(lua_State *L, int firstline)
static int runargs(lua_State *L, char **argv, int n)
LUA_API void() lua_rawseti(lua_State *L, int idx, int n)
LUA_API void() lua_getfield(lua_State *L, int idx, const char *k)
static void lstop(lua_State *L, lua_Debug *ar)
int dostring(lua_State *L, const char *s, const char *name)
LUA_API void() lua_remove(lua_State *L, int idx)
LUA_API int() lua_gettop(lua_State *L)
static int handle_luainit(lua_State *L)
static void print_quit_info(void)
#define lua_pushcfunction(L, f)
LUA_API void() lua_call(lua_State *L, int nargs, int nresults)
LUA_API void *() lua_touserdata(lua_State *L, int idx)
static int docall(lua_State *L, int narg, int clear)
static int pmain(lua_State *L)
LUA_API const char *() lua_tolstring(lua_State *L, int idx, size_t *len)
static const char * progname
LUA_API const char *() lua_pushfstring(lua_State *L, const char *fmt,...)
LUA_API void() lua_settop(lua_State *L, int idx)
void l_message(const char *pname, const char *msg)
static int traceback(lua_State *L)
LUA_API int lua_sethook(lua_State *L, lua_Hook func, int mask, int count)
static void print_usage(void)
static int handle_script(lua_State *L, char **argv, int n)
static void print_version(void)