예제 #1
0
static int lua_register_slurm_output_functions (void)
{
	/*
	 *  Register slurm output functions in a global "slurm" table
	 */
	lua_newtable (L);
	luaL_register (L, NULL, slurm_functions);

	/*
	 *  Create more user-friendly lua versions of SLURM log functions.
	 */
	luaL_loadstring (L, "slurm.error (string.format(unpack({...})))");
	lua_setfield (L, -2, "log_error");
	luaL_loadstring (L, "slurm.log (0, string.format(unpack({...})))");
	lua_setfield (L, -2, "log_info");
	luaL_loadstring (L, "slurm.log (1, string.format(unpack({...})))");
	lua_setfield (L, -2, "log_verbose");
	luaL_loadstring (L, "slurm.log (2, string.format(unpack({...})))");
	lua_setfield (L, -2, "log_debug");
	luaL_loadstring (L, "slurm.log (3, string.format(unpack({...})))");
	lua_setfield (L, -2, "log_debug2");

	/*
	 * slurm.SUCCESS, slurm.FAILURE and slurm.ERROR
	 */
	lua_pushnumber (L, SLURM_FAILURE);
	lua_setfield (L, -2, "FAILURE");
	lua_pushnumber (L, SLURM_ERROR);
	lua_setfield (L, -2, "ERROR");
	lua_pushnumber (L, SLURM_SUCCESS);
	lua_setfield (L, -2, "SUCCESS");

	lua_setglobal (L, "slurm");
	return 0;
}
예제 #2
0
파일: gtkglext.c 프로젝트: ifreedom/lgob
int luaopen_lgob_gtkglext(lua_State *L)
{
    luaL_loadstring(L, "require('lgob.gtk')"); lua_call(L, 0, 0);
	luaL_loadstring(L, "glib.handle_log('GtkGLExt')"); lua_call(L, 0, 0);
    
    gtk_gl_init(NULL, NULL);
	luaL_register(L, "gtkglext", gtkglext);
	luaL_loadstring(L, "gtkglext.Object = gobject.Object"); lua_call(L, 0, 0);
    
	/* Register the classes */
	register_class(L, "Config", "Object", config);
	register_class(L, "Widget", "Object", widget);
	register_class(L, "Drawable", NULL, drawable);
	
	/* Register special class table */
	lua_getfield(L, LUA_REGISTRYINDEX, "lgobSpecial");
	lua_pushliteral(L, "GdkGLWindowImplX11"); lua_getfield(L, -3, "Drawable"); lua_rawset(L, -3);
	lua_pushliteral(L, "GdkGLWindowImplWin32"); lua_getfield(L, -3, "Drawable"); lua_rawset(L, -3);
	lua_pop(L, 1);
	
	/* GdkGLConfigMode */
	lua_pushliteral(L, "MODE_RGB"); lua_pushinteger(L, GDK_GL_MODE_RGB); lua_rawset(L, -3);
	lua_pushliteral(L, "MODE_RGBA"); lua_pushinteger(L, GDK_GL_MODE_RGBA); lua_rawset(L, -3);
	lua_pushliteral(L, "MODE_SINGLE"); lua_pushinteger(L, GDK_GL_MODE_SINGLE); lua_rawset(L, -3);
	lua_pushliteral(L, "MODE_INDEX"); lua_pushinteger(L, GDK_GL_MODE_INDEX); lua_rawset(L, -3);
	lua_pushliteral(L, "MODE_DOUBLE"); lua_pushinteger(L, GDK_GL_MODE_DOUBLE); lua_rawset(L, -3);
	lua_pushliteral(L, "MODE_STEREO"); lua_pushinteger(L, GDK_GL_MODE_STEREO); lua_rawset(L, -3);
	lua_pushliteral(L, "MODE_ALPHA"); lua_pushinteger(L, GDK_GL_MODE_ALPHA); lua_rawset(L, -3);
	lua_pushliteral(L, "MODE_DEPTH"); lua_pushinteger(L, GDK_GL_MODE_DEPTH); lua_rawset(L, -3);
	lua_pushliteral(L, "MODE_STENCIL"); lua_pushinteger(L, GDK_GL_MODE_STENCIL); lua_rawset(L, -3);
	lua_pushliteral(L, "MODE_ACCUM"); lua_pushinteger(L, GDK_GL_MODE_ACCUM); lua_rawset(L, -3);
	
	return 1;
}
int Lua_Calaos::requestUrl(lua_State *L)
{
    int nb = lua_gettop(L);

    if (nb == 1 && lua_isstring(L, 1))
    {
        std::string url = lua_tostring(L, 1);

        std::string code = "local http = require(\"socket.http\")\n"    \
                      "http.request(\"" + url + "\")";

        luaL_loadstring(L, code.c_str());
        lua_call(L, 0, 0);
    }
    else if (nb == 2 && lua_isstring(L, 1) && lua_isstring(L, 2))
    {
        std::string url = lua_tostring(L, 1);
        std::string post_data = lua_tostring(L, 2);

        std::string code = "local http = require(\"socket.http\")\n"    \
                      "http.request(\"" + url + "\", \"" + Utils::escape_quotes(post_data) + "\")";

        luaL_loadstring(L, code.c_str());
        lua_call(L, 0, 0);
    }
    else
    {
        std::string err = "requestUrl(): invalid argument. Requires a string (URL to call).";
        lua_pushstring(L, err.c_str());
        lua_error(L);
    }

    return 0;
}
예제 #4
0
static int SPANK_table_create (lua_State *L)
{
    lua_newtable (L);
    lua_pushcfunction (L, l_spank_log_msg);
    lua_setfield (L, -2, "_log_msg");

    /*
     *  Create more user-friendly lua versions of SLURM log functions
     *   with lua.
     */
    luaL_loadstring (L, "SPANK._log_msg (-1, string.format(unpack({...})))");
    lua_setfield (L, -2, "log_error");

    luaL_loadstring (L, "SPANK._log_msg (0, string.format(unpack({...})))");
    lua_setfield (L, -2, "log_info");

    luaL_loadstring (L, "SPANK._log_msg (1, string.format(unpack({...})))");
    lua_setfield (L, -2, "log_verbose");

    luaL_loadstring (L, "SPANK._log_msg (2, string.format(unpack({...})))");
    lua_setfield (L, -2, "log_debug");

    /*
     *  SPANK.SUCCESS and SPANK.FAILURE
     */
    lua_pushnumber (L, -1);
    lua_setfield (L, -2, "FAILURE");

    lua_pushnumber (L, 0);
    lua_setfield (L, -2, "SUCCESS");

    lua_setglobal (L, "SPANK");
    return (0);
}
예제 #5
0
파일: vte.c 프로젝트: ifreedom/lgob
static void _wrap_vte_init(lua_State* L)
{
	luaL_register(L, "vte", vte);
	
	luaL_loadstring(L, "require('lgob.gtk')"); lua_call(L, 0, 0);
	luaL_loadstring(L, "vte.Object = gobject.Object"); lua_call(L, 0, 0);
	luaL_loadstring(L, "vte.Widget = gtk.Widget"); lua_call(L, 0, 0);
	
	lua_getfield(L, LUA_REGISTRYINDEX, "lgobPrefix");
	lua_pushliteral(L, "Vte"); lua_pushliteral(L, "vte"); lua_rawset(L, -3);
	lua_pop(L, 1);
	
	luaL_loadstring(L, "glib.handle_log('Vte')"); lua_call(L, 0, 0);
}
예제 #6
0
void Desktop::OnCommand(const string_t &cmd)
{
    if( cmd.empty() )
    {
        return;
    }

    string_t exec;

    if( g_client && !g_client->IsLocal() )
    {
        if( cmd[0] == '/' )
        {
            exec = cmd.substr(1); // cut off the first symbol and execute cmd
        }
        else
        {
            dynamic_cast<TankClient*>(g_client)->SendTextMessage(cmd);
            return;
        }
    }
    else
    {
        exec = cmd;
    }


    if( luaL_loadstring(g_env.L, exec.c_str()) )
    {
        lua_pop(g_env.L, 1);

        string_t tmp = "print(";
        tmp += exec;
        tmp += ")";

        if( luaL_loadstring(g_env.L, tmp.c_str()) )
        {
            lua_pop(g_env.L, 1);
        }
        else
        {
            script_exec(g_env.L, tmp.c_str());
            return;
        }
    }

    script_exec(g_env.L, exec.c_str());
}
예제 #7
0
파일: proto.c 프로젝트: rjose/prototypes
static void *repl_routine(void *arg)
{
        char buf[MAXLINE];
        int error;

        lua_State *L = luaL_newstate();
        luaL_openlibs(L);

        /*
         * Require shell functions
         */
        lua_getglobal(L, "require");
        lua_pushstring(L, "app.shell_functions");
        if (lua_pcall(L, 1, 1, 0) != LUA_OK)
                luaL_error(L, "Problem requiring shell functions: %s",
                                lua_tostring(L, -1));

        /*
         * REPL
         */
        printf("qplan> ");
        while (fgets(buf, sizeof(buf), stdin) != NULL) {
                error = luaL_loadstring(L, buf) || lua_pcall(L, 0, 0, 0);

                if (error) {
                        fprintf(stderr, "%s\n", lua_tostring(L, -1));
                        lua_pop(L, 1);
                }
                printf("qplan> ");
        }

        lua_close(L);
        return NULL;
}
예제 #8
0
파일: rdl.c 프로젝트: surajpkn/flux-sched
static int rdl_dostringf (struct rdl *rdl, const char *fmt, ...)
{
    char *s;
    int rc;
    int top;

    va_list ap;
    va_start (ap, fmt);
    rc = vasprintf (&s, fmt, ap);
    va_end (ap);

    if (rc < 0)
        return (-1);

    top = lua_gettop (rdl->L);

    if (  luaL_loadstring (rdl->L, s)
       || lua_pcall (rdl->L, 0, LUA_MULTRET, 0)) {
        VERR (rdl->rl, "dostring (%s): %s\n", s, lua_tostring (rdl->L, -1));
        lua_settop (rdl->L, 0);
        free (s);
        return (-1);
    }
    free (s);

    return (lua_gettop (rdl->L) - top);
}
예제 #9
0
파일: LuaVM.hpp 프로젝트: trfd/CES
 /// <summary>
 /// Run a chunk lua script.
 /// </summary>
 inline void runChunk(const std::string& snippet)
 {
     if(luaL_loadstring(m_luaState,snippet.c_str())==0) // load and run the file
         lua_pcall(m_luaState,0,0,0);
     else
         std::cout<<"ERROR: Unable to load "<<snippet<<"\n";
 }
예제 #10
0
static int l_str_reload(lua_State *L)
{
    // The first argument should be the old root object, second argument the
    // new one.
    luaL_checktype(L, 1, LUA_TUSERDATA);
    luaL_checktype(L, 2, LUA_TUSERDATA);

    // Create caching table to track what has been reloaded
    // (i.e. things are added to this table as they are reloaded, and
    // __index will perform the reloading as required).
    lua_newtable(L);
    lua_insert(L, 1);
    lua_settop(L, 3);
    lua_rawset(L, 1);
    lua_createtable(L, 0, 1);
    lua_pushcfunction(L, l_str_reload_actual);
    lua_setfield(L, -2, "__index");
    lua_setmetatable(L, -2);

    aux_push_weak_table(L, 0);
    luaL_loadstring(L,
       "local reload, all_proxies, _ = ...\n"
       // Make a copy of all_proxies which isn't a weak table
       "local proxies_copy = {}\n"
       "for k, v in pairs(all_proxies) do proxies_copy[k] = v end\n"
       // Do the reloading
       "for k in pairs(proxies_copy) do _ = reload[k] end\n"
       );
    lua_insert(L, 1);
    lua_call(L, 2, 0);

    return 0;
}
예제 #11
0
void lua_engine::load_string(const char *value)
{
	int s = luaL_loadstring(m_lua_state, value);
	report(s);
	update_machine();
	start();
}
예제 #12
0
int lua_mapgen(map *m, std::string terrain_type, mapgendata, int t, float, const std::string &scr)
{
    if( lua_state == nullptr ) {
        return 0;
    }
    lua_State *L = lua_state;
    {
        map **map_userdata = (map **) lua_newuserdata(L, sizeof(map *));
        *map_userdata = m;
        luah_setmetatable(L, "map_metatable");
        luah_setglobal(L, "map", -1);
    }

    int err = luaL_loadstring(L, scr.c_str() );
    if( lua_report_error( L, err, scr.c_str() ) ) {
        return err;
    }
    //    int function_index = luaL_ref(L, LUA_REGISTRYINDEX); // todo; make use of this
    //    lua_rawgeti(L, LUA_REGISTRYINDEX, function_index);

    lua_pushstring(L, terrain_type.c_str());
    lua_setglobal(L, "tertype");
    lua_pushinteger(L, t);
    lua_setglobal(L, "turn");

    err = lua_pcall(L, 0 , LUA_MULTRET, 0);
    lua_report_error( L, err, scr.c_str() );

    //    luah_remove_from_registry(L, function_index); // todo: make use of this

    return err;
}
예제 #13
0
/*
 *  Convert '%' to '%%" on the msg string on top of the stack.
 */
static const char *l_string_sanitized (lua_State *L)
{
    int err;
    const char fn[] = "local s = ... return string.gsub(s, '%%', '%%%%')";

    err = luaL_loadstring (L, fn);
    if (err) {
        slurm_error ("spank/lua: loadstring (%s): %s", fn, lua_tostring(L, -1));
        return (NULL);
    }

    /*
     *  Move string to top of stack:
     */
    lua_pushvalue (L, 2);
    lua_remove (L, 2);

    /*
     *  Call gsub, throwing away 2nd return value (number of matches),
     *   leaving modified string on top of stack:
     */
    err = lua_pcall (L, 1, 1, 0);
    if (err) {
        slurm_error ("spank/lua: sanitize msg: %s", lua_tostring (L, -1));
        return (NULL);
    }

    return (lua_tostring (L, -1));
}
예제 #14
0
파일: winfw.c 프로젝트: Lancelod-Liu/ejoy2d
void
ejoy2d_win_init(int orix, int oriy, int width, int height, float scale, const char* folder) {
	G = create_game();
	lua_State *L = ejoy2d_game_lua(G->game);
	lua_pushcfunction(L, traceback);
	int tb = lua_gettop(L);
	int err = luaL_loadstring(L, startscript);
	if (err) {
		const char *msg = lua_tostring(L,-1);
		fault("%s", msg);
	}

  lua_pushstring(L, folder);
  lua_pushstring(L, "examples/ex03.lua");

	err = lua_pcall(L, 2, 0, tb);
	if (err) {
		const char *msg = lua_tostring(L,-1);
		fault("%s", msg);
	}

	lua_pop(L,1);

	screen_init(width,height,scale);
	ejoy2d_game_start(G->game);
}
예제 #15
0
파일: winfw.c 프로젝트: xubingyue/engine2d
void
engine2d_win_init(struct STARTUP_INFO* startup) {
    STARTUP = startup;
    G = create_game();
    
    screen_init(startup->width, startup->height, startup->scale);

    
    lua_State *L = engine2d_game_lua(G->game);
    
    lua_pushcfunction(L, traceback);
    
    int tb = lua_gettop(L);
    int err = luaL_loadstring(L, startscript);
    if (err) {
        const char *msg = lua_tostring(L,-1);
        fault("%s", msg);
    }
    
    lua_pushstring(L, startup->folder);
    lua_pushstring(L, startup->script);
    push_startup_info(L, startup);
    err = lua_pcall(L, 3, 0, tb);
    if (err) {
        const char *msg = lua_tostring(L,-1);
        fault("%s", msg);
    }
    
    lua_pop(L,1);
    

    engine2d_game_logicframe(LOGIC_FRAME);

    engine2d_game_start(G->game);
}
예제 #16
0
int PlotScript::openLuaFile(lua_State* _ls, const char *_luaFile )
{
	int isOpen = -1;
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
	std::string code("require \"");
	code.append(_luaFile);
	code.append("\"");
	//return executeString(code.c_str());
	isOpen = luaL_loadstring(_ls, code.c_str());
	lua_pcall(_ls, 0, LUA_MULTRET, 0);
	if(isOpen != 0)
	{
		log("Can't open Error: %s", _luaFile);
	}
#else
	if (luaL_loadfile(_ls, _luaFile) != 0) {
		log("loadfile error[file:%s]: %s", _luaFile,lua_tostring(_ls, -1));
	}

	if (lua_pcall(_ls, 0, LUA_MULTRET, 0) != 0) {
		log("pcall error[file: %s", _luaFile,lua_tostring(_ls, -1));
	}

	isOpen = luaL_dofile(_ls, _luaFile);
	if(isOpen != 0)
	{
		log("Open Lua Error: %s", _luaFile);
	}
#endif
	return isOpen;
}
예제 #17
0
파일: bind.c 프로젝트: ccxvii/mio
void run_string(const char *cmd)
{
	if (!L) {
		console_printnl("[no command interpreter]");
		return;
	}

	int status = luaL_loadstring(L, cmd);
	if (status) {
		const char *msg = lua_tostring(L, -1);
		console_printnl(msg);
		lua_pop(L, 1);
		return;
	}

	status = docall(L, 0, LUA_MULTRET);
	if (status) {
		const char *msg = lua_tostring(L, -1);
		console_printnl(msg);
		lua_pop(L, 1);
		return;
	}

	if (lua_gettop(L) > 0) {
		lua_getglobal(L, "print");
		lua_insert(L, 1);
		lua_pcall(L, lua_gettop(L)-1, 0, 0);
	}
}
예제 #18
0
void CLuaManager::RegisterPreScript(lua_State *L)
{
	const char preScript[] = "" \
		"local callMT = {}\n" \
		"function callMT : __index(k)\n" \
		"	k = tostring(k)\n" \
		"	self[k] = function(a, ...)\n" \
		"		if a == nil and #{...} == 0 then\n" \
		"			return call(self.res, k)\n" \
		"		elseif a == self then\n" \
		"			return call(self.res, k, ...)\n" \
		"		else\n" \
		"			return call(self.res, k, a, ...)\n" \
		"		end\n" \
		"	end\n" \
		"	return self[k]\n" \
		"end\n" \
		"local exportMT = {}\n" \
		"function exportMT : __index(k)\n" \
		"	if isResourceRunning(k) then\n" \
		"		k = tostring(k)\n" \
		"		return setmetatable({ res = k }, callMT)\n" \
		"	else\n" \
		"		print('export: ' ..k .. ' resource is not running!', 1)\n" \
		"		return nil\n" \
		"	end\n" \
		"end\n" \
		"export = setmetatable({}, exportMT)\n";

	luaL_loadstring(L, preScript);
	lua_pcall(L, 0, LUA_MULTRET, 0);
}
예제 #19
0
파일: pixel.c 프로젝트: zhoukk/pixel
void pixel_start(int w, int h, const char *start) {
	lua_State *L = luaL_newstate();
	luaL_checkversion(L);
	lua_atpanic(L, _panic);
	luaL_openlibs(L);
	luaX_loader(L);

	pixel_init(L);

	pixel_log("version:%d\n", shader_version());

	memset(&P, 0, sizeof P);
	P.L = L;
	P.fps = PIXEL_FPS;
	P.w = w;
	P.h = h;
	P.s = 1.0f;
	screen_init(P.w, P.h, P.s);
	lua_pushcfunction(L, traceback);
	int tb = lua_gettop(L);
	if (LUA_OK != luaL_loadstring(L, start_script)) {
		pixel_log("%s\n", lua_tostring(L, -1));
	}
	lua_pushstring(L, start);
	if (LUA_OK != lua_pcall(L, 1, 0, tb)) {
		pixel_log("lua_init:%s\n", lua_tostring(L, -1));
	}
	lua_pop(L, 1);
	lua_getfield(L, LUA_REGISTRYINDEX, PIXEL_INIT);
	lua_call(L, 0, 0);
	assert(lua_gettop(L) == 0);
	lua_pushcfunction(L, traceback);
	lua_getfield(L, LUA_REGISTRYINDEX, PIXEL_UPDATE);
	lua_getfield(L, LUA_REGISTRYINDEX, PIXEL_FRAME);
}
예제 #20
0
파일: main.c 프로젝트: s207152/androluajit
int luaHello() {
	lua_State *L;

	/* Create new Lua state */
	L = luaL_newstate();

	/* Load Lua libraries */
	luaL_openlibs(L); 

	// Embedding Lanes by using custom loader
	luaopen_lanes_embedded(L, load_lanes_lua);
	// lua_pop(L, 1);

	luaL_loadstring(L, lanes_test);
	// luaL_loadstring(L, "local lanes = require 'lanes'.configure{with_timers = false}");
	if(lua_pcall(L, 0, 0, 0))
	// if(luaL_dostring( L, "print('hi'); local lanes = require 'lanes'.configure{with_timers = false}; local l = lanes.linda(); print('end')"))
		printf("lua pcall failed: %s\n", lua_tostring(L, -1));
	// luaL_dostring( L, "print('hi'); local lanes = require 'lanes'.configure{with_timers = false}; local l = lanes.linda(); print('end')");

	/* Close Lua state */
	lua_close(L);

	return 0;
}
예제 #21
0
//----------------------------------------------------------------//
void MOAIHarness::ReceiveEvaluate(lua_State *L, json_t* node)
{
	// Get the evaluation.
	json_t* np_eval = json_object_get(node, "Evaluation");
	if (np_eval == NULL || json_typeof(np_eval) != JSON_STRING)
		return;

	// Get the current stack index so we know how many
	// positions to clear afterward.
	int top = lua_gettop(L);

	// Load the string from the message
	MOAIScopedLuaState state ( L );
	int status = luaL_loadstring ( state, json_string_value(np_eval) );
	if ( state.PrintErrors ( ZLLog::CONSOLE, status )) return;

	// Call the string
	state.DebugCall ( 0, 0 );

	// Now unload all of the things we just put on the stack
	// until the stack is the same size.
	std::string indent = "    ";
	json_t* result = MOAIHarness::ConvertStackPartialToJSON(L, top + 1, lua_gettop(L));
	lua_pop(L, lua_gettop(L) - top);

	// Send the message back to the IDE.
	MOAIHarness::SendResult(result);
}
예제 #22
0
/*
** Runs given string in the context of the script file.
**
*/
void LuaScript::RunString(const std::wstring& str)
{
    auto L = GetState();

    if (IsInitialized())
    {
        const std::string narrowStr = m_Unicode ?
                                      StringUtil::NarrowUTF8(str) : StringUtil::Narrow(str);

        // Load the string as a Lua chunk
        if (luaL_loadstring(L, narrowStr.c_str()))
        {
            LuaManager::ReportErrors(m_File);
        }

        // Push our table onto the stack
        lua_rawgeti(L, LUA_GLOBALSINDEX, m_Ref);

        // Pop table and set the environment of the loaded chunk to it
        lua_setfenv(L, -2);

        if (lua_pcall(L, 0, 0, 0))
        {
            LuaManager::ReportErrors(m_File);
        }
    }
}
예제 #23
0
void MyLua::runCode( QObject *target, const QString &successMethod, const QString &failMethod,
                     const QString &data )
{
   QMutexLocker locker(&mDataMutex);
   int errorcode = luaL_loadstring( mpL, data.toUtf8().constData() );
   if( !errorcode )
   {
      errorcode = lua_pcall( mpL, 0, 0, 0 );
   }
   if( errorcode )
   {
      const QString errmsg( lua_tostring( mpL, -1 ) );
      if( !QMetaObject::invokeMethod( target, failMethod.toAscii().constData(), Qt::QueuedConnection,
                                      Q_ARG( QString, errmsg ) ) )
      {
         qFatal( "%s:%d call failed in %s", __FILE__, __LINE__, Q_FUNC_INFO );
      }
      lua_pop( mpL, 1 );
   }
   else
   {

      if( !QMetaObject::invokeMethod( target, successMethod.toAscii().constData(), Qt::QueuedConnection ) )
      {
         qFatal( "%s:%d call failed in %s", __FILE__, __LINE__, Q_FUNC_INFO );
      }
   }
}
예제 #24
0
bool cLuaState::LoadString(const AString & a_StringToLoad, const AString & a_FileName, bool a_LogWarnings)
{
	ASSERT(IsValid());

	// Load the file:
	int s = luaL_loadstring(m_LuaState, a_StringToLoad.c_str());
	if (s != 0)
	{
		if (a_LogWarnings)
		{
			LOGWARNING("Can't load %s because of a load error in string from \"%s\": %d (%s)", m_SubsystemName.c_str(), a_FileName.c_str(), s, lua_tostring(m_LuaState, -1));
		}
		lua_pop(m_LuaState, 1);
		return false;
	}

	// Execute the globals:
	s = lua_pcall(m_LuaState, 0, LUA_MULTRET, 0);
	if (s != 0)
	{
		if (a_LogWarnings)
		{
			LOGWARNING("Can't load %s because of an initialization error in string from \"%s\": %d (%s)", m_SubsystemName.c_str(), a_FileName.c_str(), s, lua_tostring(m_LuaState, -1));
		}
		lua_pop(m_LuaState, 1);
		return false;
	}

	return true;
}
예제 #25
0
static int runthread(void *code_)
{
  char *code = code_;
  lua_State *L = luaL_newstate();

  if(!L) {
    printf("THREAD FATAL ERROR: could not create lua state\n");
    return -1;
  }
  luaL_openlibs(L);

  if(luaL_loadstring(L, code)) {
    printf("FATAL THREAD PANIC: (loadstring) %s\n", lua_tolstring(L, -1, NULL));
    free(code);
    lua_close(L);
    return -1;
  }

  free(code);
  if(lua_pcall(L, 0, 0, 0)) {
    printf("FATAL THREAD PANIC: (pcall) %s\n", lua_tolstring(L, -1, NULL));
    lua_close(L);
    return -1;
  }

  lua_close(L);
  return 0;
}
예제 #26
0
파일: winfw.c 프로젝트: Coolxiaoo/ejoy2d
void
ejoy2d_win_init(int argc, char *argv[]) {
	G = create_game();
	lua_State *L = ejoy2d_game_lua(G->game);
	lua_pushcfunction(L, traceback);
	int tb = lua_gettop(L);
	int err = luaL_loadstring(L, startscript);
	if (err) {
		const char *msg = lua_tostring(L,-1);
		fault("%s", msg);
	}
  
  lua_pushstring(L, "./");
  lua_pushstring(L, "examples/ex03.lua");
  
	err = lua_pcall(L, 2, 0, tb);
	if (err) {
		const char *msg = lua_tostring(L,-1);
		fault("%s", msg);
	}

	lua_pop(L,1);

	screen_init(WIDTH,HEIGHT,1.0f);
	ejoy2d_game_start(G->game);
}
void lua_player::download_global()
{
  QObject::disconnect(this, SLOT(download_global ()));

  assert(pending_download_file != 0);
  QByteArray content = pending_download_file->io_device()->readAll();
  pending_download_file = 0;
  if(content.size() > 0)
  {
    int r = luaL_loadstring(current_frame(), content.constData());
    if(r != 0)
    {
      std::string error = "Error loading file ";
      // error += root_path;
      // error += '/';
      // error += path;
      error += " with error: ";
      if(lua_gettop(current_frame ()) >= 1)
      {
        luabind::object error_msg(luabind::from_stack(current_frame (), -1));
        if(luabind::type(error_msg) == LUA_TSTRING)
          error += luabind::object_cast<std::string>(error_msg);
      }
      ncl_window->error_occurred(error);
    }
    else
    {
      run_current_frame();
    }
  }  
  else
  {
    std::cout << "file was empty" << std::endl;
  }
}
예제 #28
0
파일: tests.c 프로젝트: remram44/safelua
int main(int argc, char **argv)
{
    lua_State *state = safelua_open();
    int i;
    lua_pushcfunction(state, l_alloc);
    lua_setglobal(state, "alloc");
    lua_pushcfunction(state, l_free);
    lua_setglobal(state, "free");
    for(i = 1; i < argc; ++i)
    {
        luaL_loadstring(state, argv[i]);
        int counter = 3;
        int ret = safelua_pcallk(state, 0, LUA_MULTRET, 0, 0, NULL,
                                 mycancel, &counter);
        if(ret == LUA_OK)
            ;
        else if(ret == SAFELUA_CANCELED)
        {
            printf("Canceled during line %d\n", i);
            fprintf(stderr, "Resources: \"%s\"\n", resources);
            return 2;
        }
        else
        {
            printf("Error executing line %d: %d\n", i, ret);
            safelua_close(state);
            return 1;
        }
    }
    safelua_close(state);
    fprintf(stderr, "Resources: \"%s\"\n", resources);
    return 0;
}
예제 #29
0
int lua_mapgen(map * m, std::string terrain_type, mapgendata md, int t, float d, const std::string & scr) {
    lua_State* L = lua_state; 
    {
        map** map_userdata = (map**) lua_newuserdata(L, sizeof(map*));
        *map_userdata = m;
        luah_setmetatable(L, "map_metatable");
        luah_setglobal(L, "map", -1);
    }
   
    int err = luaL_loadstring(L, scr.c_str() );
    if(err) {
        // Error handling.
        const char* error = lua_tostring(L, -1);
        debugmsg("Error loading lua mapgen: %s", error);
        return err;
    }
//    int function_index = luaL_ref(L, LUA_REGISTRYINDEX); // todo; make use of this
//    lua_rawgeti(L, LUA_REGISTRYINDEX, function_index);

    lua_pushstring(L, terrain_type.c_str());
    lua_setglobal(L, "tertype");
    lua_pushinteger(L, t);
    lua_setglobal(L, "turn");

    err=lua_pcall(L, 0 , LUA_MULTRET, 0);
    if(err) {
        // Error handling.
        const char* error = lua_tostring(L, -1);
        debugmsg("Error running lua mapgen: %s", error);
    }

//    luah_remove_from_registry(L, function_index); // todo: make use of this

    return err;
}
예제 #30
0
파일: winfw.c 프로젝트: ywxzm/ejoy2d
void
ejoy2d_win_init(int argc, char *argv[]) {
	G = create_game();
	screen_init(WIDTH,HEIGHT,1.0f);
	lua_State *L = ejoy2d_game_lua(G->game);
	lua_pushcfunction(L, traceback);
	int tb = lua_gettop(L);
	int err = luaL_loadstring(L, startscript);
	if (err) {
		const char *msg = lua_tostring(L,-1);
		fault("%s", msg);
	}

	char modname[1024];

	int sz = GetModuleFileNameA(0,  modname, 1024);

	lua_pushlstring(L, modname, sz);

	int i;
	for (i=1;i<argc;i++) {
		lua_pushstring(L, argv[i]);
	}

	err = lua_pcall(L, argc, 0, tb);
	if (err) {
		const char *msg = lua_tostring(L,-1);
		fault("%s", msg);
	}

	lua_pop(L,1);

	ejoy2d_game_start(G->game);
}