2 * GRUB -- GRand Unified Bootloader
3 * Copyright (C) 2009 Free Software Foundation, Inc.
5 * GRUB is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * GRUB is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
25 #include <grub/parser.h>
27 static lua_State
*state
;
30 grub_lua_parse_line (char *line
, grub_reader_getline_t getline
)
38 r
= luaL_loadbuffer (state
, line
, grub_strlen (line
), "grub");
41 r
= lua_pcall (state
, 0, 0, 0);
43 grub_error (GRUB_ERR_BAD_ARGUMENT
, "lua command fails");
52 if (r
== LUA_ERRSYNTAX
)
55 const char *msg
= lua_tolstring(state
, -1, &lmsg
);
56 const char *tp
= msg
+ lmsg
- (sizeof(LUA_QL("<eof>")) - 1);
57 if (grub_strstr(msg
, LUA_QL("<eof>")) == tp
)
63 if ((getline (&n
, 1)) || (! n
))
65 grub_error (GRUB_ERR_BAD_ARGUMENT
, "incomplete command");
69 len
= grub_strlen (line
);
70 t
= grub_malloc (len
+ grub_strlen (n
) + 2);
74 grub_strcpy (t
, line
);
76 grub_strcpy (t
+ len
+ 1, n
);
87 lua_gc (state
, LUA_GCCOLLECT
, 0);
92 static struct grub_parser grub_lua_parser
=
95 .parse_line
= grub_lua_parse_line
105 lua_gc(state
, LUA_GCSTOP
, 0);
106 luaL_openlibs(state
);
107 luaL_register(state
, "grub", grub_lua_lib
);
108 lua_gc(state
, LUA_GCRESTART
, 0);
109 grub_parser_register ("lua", &grub_lua_parser
);
117 grub_parser_unregister (&grub_lua_parser
);