Exemplo n.º 1
0
int main(int argc, char **argv)
{
    int status;
#ifdef USE_READLINE
    initialize_readline();
#endif
    gsl_shell_init(gsl_shell);
    gsl_shell_open(gsl_shell);

    pthread_mutex_lock(&gsl_shell->exec_mutex);

    smain.argc = argc;
    smain.argv = argv;
    status = lua_cpcall(gsl_shell->L, pmain, NULL);
    report(gsl_shell->L, status);

    pthread_mutex_unlock(&gsl_shell->exec_mutex);

    gsl_shell_close_with_graph(gsl_shell, !smain.keep_windows);
    gsl_shell_free(gsl_shell);

    return (status || smain.status) ? EXIT_FAILURE : EXIT_SUCCESS;
}
Exemplo n.º 2
0
Arquivo: luac.c Projeto: ARMinARM/elua
int main(int argc, char* argv[])
{
 lua_State* L;
 struct Smain s;
 
 int test=1;
 target.little_endian=*(char*)&test;
 target.sizeof_int=sizeof(int);
 target.sizeof_strsize_t=sizeof(strsize_t);
 target.sizeof_lua_Number=sizeof(lua_Number);
 target.lua_Number_integral=(((lua_Number)0.5)==0);
 target.is_arm_fpa=0;

 int i=doargs(argc,argv);
 argc-=i; argv+=i;
 if (argc<=0) usage("no input files given");
 L=lua_open();
 if (L==NULL) fatal("not enough memory for state");
 s.argc=argc;
 s.argv=argv;
 if (lua_cpcall(L,pmain,&s)!=0) fatal(lua_tostring(L,-1));
 lua_close(L);
 return EXIT_SUCCESS;
}
Exemplo n.º 3
0
bool run_script(const char *script_name)
{
    int status;
    struct Smain s;

    /* Read and regiter the SCALE interface methods.
     */
    SCALE::Lua_if &lua = SCALE::Lua_if::get_instance();
#if 0
  lua_State *L = lua_open();  /* create state */
  if (L == NULL) {
    l_message(argv[0], "cannot create state: not enough memory");
    return EXIT_FAILURE;
  }
#endif

    if(scale_register) {
        scale_register(lua.state());
    }

    if(luaL_loadfile(L, argv[1]) || lua_pcall(L, 0, LUA_MULTRET, 0)) {
        luaL_error(L, "Cannot run Lua config file: %s", lua_tostring(L, -1));
        return false;
    }

#if 0
  s.argc = argc;
  s.argv = argv;
  status = lua_cpcall(lua.state(), &pmain, &s);
  report(lua.state(), status);
  //lua_close(L);
  return (status || s.status) ? EXIT_FAILURE : EXIT_SUCCESS;
#endif

    return true;
}
Exemplo n.º 4
0
void lbot_openlibs(lua_State *L, Funct* pDefconInterface, std::vector< std::vector<std::string> > &vvCommandLineOptions)
{
  g_pDefconInterface = pDefconInterface;
  lua_cpcall(L, lbot_openlibs_actual, reinterpret_cast<void*>(&vvCommandLineOptions));
}
Exemplo n.º 5
0
static int install(lua_State *L)
{
	int type= lua_type(L, 1);
	SIGN_HANDLER_FUN domain = NULL;
	printf("args type : ");
	switch (type){
		case LUA_TNIL:
			printf("1\n");
			break;
		case LUA_TNUMBER:
			printf("2\n");
			break;
		case LUA_TBOOLEAN:
			printf("3\n");
			break;
		case LUA_TSTRING:
			printf("4\n");
			lua_func_cmds = lua_tostring (L, 1);
			break;
		case LUA_TTABLE:
			printf("5\n");
			break;
		case LUA_TFUNCTION:
			printf("6\n");
			lua_CFunction sig_handler = lua_tocfunction (L, 1);
			lua_cpcall(L, sig_handler, NULL);
			break;
		case LUA_TUSERDATA:
			printf("7\n");
			break;
		case LUA_TTHREAD:
			printf("8\n");
			break;
		case LUA_TLIGHTUSERDATA:
			printf("9\n");
			break;
		default:
			printf("10\n");
			break;
	
	
	}
	//int test=0;
	{
		void run_lua_string(int signum){
			//test++;
			//printf("--------sign %d-------\n", signum);
			lua_State *L = lua_open();
			luaopen_base(L);
			luaL_openlibs(L);
			if(luaL_dostring(L, lua_func_cmds)){
				const char* errMsg = lua_tostring(L, -1);
				printf("%s\n", errMsg);
			};
			//luaL_dostring(L, "print('xxxxxxxx')");
			lua_close(L);
			//return test;
		}
		//test = run_lua_string();
		//lua_pushnumber(L, test);
		domain = run_lua_string;
	}
Exemplo n.º 6
0
bool EmbeddedGamePanel::loadLua()
{
    // Create state
    m_L = luaL_newstate();
    lua_atpanic(m_L, _l_panic);

    // Save a pointer to ourselves in the registry
    lua_pushliteral(m_L, "wxWindow");
    lua_pushlightuserdata(m_L, reinterpret_cast<wxWindow*>(this));
    lua_settable(m_L, LUA_REGISTRYINDEX);

    // Open default libraries, and override appropriate bits
    luaL_openlibs(m_L);
    luaT_execute(m_L, "print = ...", _l_print);

    // Set _MAP_EDITOR to true, to allow scripts to notice that they are
    // running inside this component, rather than standalone.
    luaT_execute(m_L, "_MAP_EDITOR = true");

    // Load CorsixTH.lua and perform other initialisation needed by it
    lua_settop(m_L, 0);
    lua_pushcfunction(m_L, CorsixTH_lua_stacktrace);
    lua_pushcfunction(m_L, CorsixTH_lua_main_no_eval);
    lua_checkstack(m_L, wxTheApp->argc);
    for(int i = 0; i < wxTheApp->argc; ++ i)
        lua_pushstring(m_L, wxTheApp->argv[i]);
    if(lua_pcall(m_L, wxTheApp->argc, 1, 1))
    {
        if(m_pPrintTarget)
        {
            m_pPrintTarget->AppendText(L"Error initialising Lua: ");
            m_pPrintTarget->AppendText(lua_tostring(m_L, -1));
            m_pPrintTarget->AppendText(L"\n");
        }
        return false;
    }
    // NB: CorsixTH_lua_main_no_eval will have loaded CorsixTH.lua and left it
    // as the top value on the stack, but will not have executed it.
    // The stack will hence have two things on it: the stacktrace function,
    // and the loaded CorsixTH.lua

    // Overwrite what CorsixTH_lua_main_no_eval registered for require("sdl")
    // with our own function that uses wxWidgets to do what SDL would have.
    luaT_execute(m_L, "package.preload.sdl = ...", _l_open_sdl);

    // Replace the Surface:endFrame() function with our own
    lua_getglobal(m_L, "require");
    lua_pushliteral(m_L, "TH");
    lua_call(m_L, 1, 1);
    lua_getfield(m_L, -1, "surface");
    lua_getfield(m_L, -1, "endFrame");
    lua_pushcclosure(m_L, _l_end_frame, 1);
    lua_setfield(m_L, -2, "endFrame");
    lua_pop(m_L, 2);

    // Perform extra initialisation
    if(m_fnExtraLuaInit)
    {
        if(lua_cpcall(m_L, m_fnExtraLuaInit, m_pExtraLuaInitArg) != 0)
            lua_pop(m_L, 1);
    }

    // Execute CorsixTH.lua in a coroutine
    lua_getglobal(m_L, "coroutine");
    lua_getfield(m_L, -1, "create");
    lua_replace(m_L, -2);
    lua_insert(m_L, -2);
    lua_call(m_L, 1, 1);
    lua_State *L = lua_tothread(m_L, -1);
    if(lua_resume(L, 0) != LUA_YIELD)
    {
        if(m_pPrintTarget)
        {
            // Push debug.traceback onto m_L
            lua_getglobal(m_L, "debug");
            lua_getfield(m_L, -1, "traceback");
            lua_replace(m_L, -2);
            // Push the thread onto m_L
            lua_pushvalue(m_L, -2);
            // Push tostring(errmsg) onto m_L
            lua_getglobal(m_L, "tostring");
            lua_xmove(L, m_L, 1);
            lua_call(m_L, 1, 1);
            // Push constant 1 onto m_L
            lua_pushinteger(m_L, 1);
            // Call debug.traceback(thread, tostring(err), 1)
            lua_call(m_L, 3, 1);
            // Display resulting string and pop it
            m_pPrintTarget->AppendText(L"Error initialising Lua: ");
            m_pPrintTarget->AppendText(lua_tostring(m_L, -1));
            m_pPrintTarget->AppendText(L"\n");
            lua_pop(m_L, 1);
        }
        return false;
    }
    lua_settop(L, 1);
    m_Lthread = L;

    // The stack of the Lua states is now as follows:
    // m_L: stacktrace function, m_Lthread <top
    // m_Lthread: event dispatch coroutine <top

    return true;
}