PageRenderTime 15ms CodeModel.GetById 2ms app.highlight 6ms RepoModel.GetById 4ms app.codeStats 0ms

/script_binding/lua/lua_runner.c

http://ftk.googlecode.com/
C | 73 lines | 34 code | 10 blank | 29 comment | 7 complexity | 7329258c4fd0f194de59c9b07e96fe16 MD5 | raw file
 1/*
 2 * File:   lua_runner.c
 3 * Author: Li XianJing <xianjimli@hotmail.com>
 4 * Brief:  lua runner
 5 *
 6 * Copyright (c) 2009 - 2010  Li XianJing <xianjimli@hotmail.com>
 7 *
 8 * Licensed under the Academic Free License version 2.1
 9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23 */
24
25/*
26 * History:
27 * ================================================================
28 * 2009-11-22 Li XianJing <xianjimli@hotmail.com> created
29 *
30 */
31
32#include "lualib.h"
33#include "ftk_lua.h"
34#include "ftk_mmap.h"
35
36static void l_message (const char *pname, const char *msg) {
37  if (pname) fprintf(stderr, "%s: ", pname);
38  fprintf(stderr, "%s\n", msg);
39  fflush(stderr);
40}
41
42
43static int report (lua_State *L, int status) {
44  if (status && !lua_isnil(L, -1)) {
45    const char *msg = lua_tostring(L, -1);
46    if (msg == NULL) msg = "(error object is not a string)";
47    l_message("ftk_run", msg);
48    lua_pop(L, 1);
49  }
50  return status;
51}
52
53int FTK_MAIN(int argc, char* argv[])
54{
55	int ret = 0;
56	lua_State *L = NULL;
57
58	if(argc != 2)
59	{
60		printf("Usage: %s lua\n", argv[0]);
61
62		return 0;
63	}
64
65	L = lua_open();
66	luaL_openlibs(L);
67	ftk_lua_init(L);
68	ret = luaL_dofile(L, argv[1]);
69	report(L, ret);
70	lua_close(L);
71
72	return 0;
73}