Пример #1
0
    bool Environment::init() {
        getGlobal("_E");

        if (!isTable(-1)) {
            newTable(regFunctions->length());
            lua_setglobal(L, "_E");
        }
        pop(1);


        loopv(*regFunctions) {
            (*regFunctions)[i]();

        }

        delete regFunctions;

    luvit_init(L, uv_default_loop());
#ifdef SERVER

      /* Pull up the preload table */
    select("package", "preload");

    pushRow("native_server", server::lua::luaopen_server);

    pop(2);
#endif
#ifdef LUA_PANIC_DEBUG
    #pragma message("Using lua atpanic crasher.")
    lua_atpanic(L, crash);
#endif
        isInitialized = true;

        return true;
    }
Пример #2
0
void LuaState::Init( bool initStandardLibrary )
{
#if LUAPLUS_INCLUDE_STANDARD_LIBRARY
	// Register some basic functions with Lua.
	if (initStandardLibrary)
	{
		LuaAutoBlock autoBlock(this);

		lua_cpcall(m_state, &pmain, NULL);

#ifdef LUA_MTSUPPORT
//        luaopen_thread(m_state);
#endif // LUA_MTSUPPORT

		ScriptFunctionsRegister( this );

        GetGlobals().Register("LuaDumpGlobals", LS_LuaDumpGlobals);
		GetGlobals().Register("LuaDumpObject", LS_LuaDumpObject);
		GetGlobals().Register("LuaDumpFile", LS_LuaDumpFile);

		GetGlobals().Register("LOG", LS_LOG);
		GetGlobals().Register("_ALERT", LS_ALERT);
	}
#endif // LUAPLUS_INCLUDE_STANDARD_LIBRARY

	lua_atpanic( m_state, FatalError );
}
Пример #3
0
Файл: uscript.c Проект: adsr/mle
// Run uscript
uscript_t *uscript_run(editor_t *editor, char *path) {
    lua_State *L;
    uscript_t *uscript;
    L = luaL_newstate();
    luaL_openlibs(L);
    luaL_requiref(L, "mle", luaopen_mle, 1);

    uscript = calloc(1, sizeof(uscript_t));
    uscript->editor = editor;
    uscript->L = L;

    lua_pushpointer(L, (void*)uscript);
    lua_setglobal(L, MLE_USCRIPT_KEY);
    lua_pop(L, 1);

    lua_getglobal(L, "_G");
    lua_pushcfunction(L, _uscript_write);
    lua_setfield(L, -2, "print");
    lua_pop(L, 1);

    lua_atpanic(L, _uscript_panic);


    luaL_loadfile(L, path); // TODO err

    lua_pcall(L, 0, 0, 0);
    return uscript;
}
Пример #4
0
LUALIB_API lua_State *luaL_newstate(void)
{
    lua_State *L = lua_newstate(l_alloc, NULL);
    if (L)
        lua_atpanic(L, &panic);
    return L;
}
Пример #5
0
//Attempt to bind with Lua
bool FLLua::load()
{
	LL_INFOS("Lua") << "Thread initializing." << llendl;
	pLuaStack = lua_open();
	if(!pLuaStack)
	{
		LL_INFOS("Lua") << __LINE__ << ": Failed lua_open" << llendl;
		LuaError("lua_open() Failed");
		return false;
	}

	//LL_INFOS("Lua") << __LINE__ << ": Skipping lua_atpanic" << llendl;
	lua_atpanic(pLuaStack, luaOnPanic);

	LL_INFOS("Lua") << __LINE__ << ": Loading standard Lua libs" << llendl;
	luaL_openlibs(pLuaStack);

	LL_INFOS("Lua") << __LINE__ << ": *** LOADING SWIG BINDINGS ***" << llendl;
	luaopen_SL(pLuaStack);
//	luaopen_GL(pLuaStack);
//	luaopen_Region(pLuaStack);
//	luaopen_Object(pLuaStack);

	std::string  version; 

	LL_INFOS("Lua") << __LINE__ << ": Assigning _SLUA_VERSION" << llendl;
	// Assign _SLUA_VERSION, which contains the version number of the host viewer.
	version = llformat("_SLUA_VERSION=\"%d.%d.%d.%d\"",LL_VERSION_MAJOR,LL_VERSION_MINOR,LL_VERSION_PATCH,LL_VERSION_BUILD);
	if(luaL_dostring(pLuaStack, version.c_str()))
	{
		LuaError(Lua_getErrorMessage(pLuaStack).c_str());
		return false;
	}

	LL_INFOS("Lua") << __LINE__ << ": Assigning _SLUA_CHANNEL" << llendl;	
	// Assign _SLUA_CHANNEL, which contains the channel name of the host client.
	version = llformat("_SLUA_CHANNEL=\"%s\"",LL_CHANNEL);
	if(luaL_dostring(pLuaStack, version.c_str()))
	{
		LuaError(Lua_getErrorMessage(pLuaStack).c_str());
		return false;
	}


	LL_INFOS("Lua") << __LINE__ << ": Assigning _SLUA_REVISION" << llendl;	
	// Assign _SLUA_CHANNEL, which contains the channel name of the host client.
	version = "_SLUA_REVISION=\"$Rev$\"";
	if(luaL_dostring(pLuaStack, version.c_str()))
	{
		LuaError(Lua_getErrorMessage(pLuaStack).c_str());
		return false;
	}

	LL_INFOS("Lua") << __LINE__ << ": LoadFile (_init_.lua)" << llendl;

	if(!LoadFile(gDirUtilp->getExpandedFilename(FL_PATH_LUA,"_init_.lua")))
		return false;
	return true;
}
Пример #6
0
LuaThread *luaL_newstate (void) {
  LuaThread *L = lua_newstate();
  if (L) {
    GLOBAL_CHANGE(L);
    lua_atpanic(L, &panic);
  }
  return L;
}
Пример #7
0
lua_State *
ejoy2d_lua_init() {
	lua_State *L = luaL_newstate();
	
	lua_atpanic(L, _panic);
	luaL_openlibs(L);
	return L;
}
Пример #8
0
void clua_setgostate(lua_State* L, int gostateindex)
{
	lua_atpanic(L, default_panicf);
	lua_pushlightuserdata(L,(void*)&GoStateRegistryKey);
	lua_pushinteger(L, gostateindex);
	//set into registry table
	lua_settable(L, LUA_REGISTRYINDEX);
}
Пример #9
0
void LuaState_UserStateOpen(lua_State* L)
{
#if LUAPLUS_EXTENSIONS
	lua_setusergcfunction(L, LuaPlusGCFunction);
#else
	luaplus_assert(0);
#endif /* LUAPLUS_EXTENSIONS */
	lua_atpanic(L, FatalError);
}
Пример #10
0
LUALIB_API lua_State *luaL_newstate (void) {
	if(isLic()!=1)
	{
		return NULL;
	}
	lua_State *L = lua_newstate(l_alloc, NULL);
	if (L) lua_atpanic(L, &panic);
	return L;
}
Пример #11
0
int main(int argc, char ** argv) {
    lua_State * L;
    
    if (argc != 2) {
	printf("You have to specify the lua script to run.\n");
	return -1;
    }
    
    // Create lua VM
       
    if (!(L = lua_open())) {
	printf("Error creating lua_State\n");
	return -1;
    }
    
    lua_atpanic(L, test_error);

    
    printf("Creating luaVM... ");
    luaL_openlibs(L); 

   
    printf("Binding some functions... ");
    printf("test_export "); lua_register(L, "test_export", test_export);
    printf("done!\n");
    
    
    printf("Loading script file: `%s'\n", argv[1]);
    
    // load script
    int status = luaL_loadfile(L, argv[1]);
	
    // call script
    if (status == 0) 
    {
	printf("Running.\n");
    	status = lua_pcall(L, 0, LUA_MULTRET, 0);
    }
    
    // show error, if any
    if (status != 0) 
    {
	printf("error: %s\n", lua_tostring(L, -1));
	lua_pop(L, 1);  // remove error message
    }

   
    printf("Done!.\n");
    
    // cleanup
    lua_close(L);


    
    return 0;
}
Пример #12
0
LuaSimpleContext::LuaSimpleContext(const mkString& name)
    : m_pimpl(new LuaSimpleContextPimpl)
    , m_name(name)
{
    m_pimpl->L = luaL_newstate();
    debugRegisterLuaState(m_pimpl->L, this);

    lua_atpanic(m_pimpl->L, panic);
    luaL_openlibs(m_pimpl->L);
}
Пример #13
0
//////////////////////////////////////////////////////////////////////
// Constructor
CLuaVM::CLuaVM(/*IHostVirtualMachine& vmHost*/) :
	//m_vmHost(vmHost),
	////Pm_ID(InterlockedIncrement(&s_nextID)),
	m_ID(++s_nextID),
	////Pm_timestampLastUsed(GetTickCount())
	m_timestampLastUsed(0)	// until no equivalent function available
{
	LogDebug("CLuaVM::CLuaVM (%p)", this);
	lua_atpanic(m_L, OnPanic);
}
Пример #14
0
Cloud::Lua::StateUniquePtr Cloud::Lua::NewState()
{
    auto* state = luaL_newstate();
    if (state)
    {
        lua_atpanic(state, &LuaPanic);
    }

    return StateUniquePtr(state);
}
Пример #15
0
//lua_State* state
CLuaVM::CLuaVM() : _vm(0)
{

    //luabind::set_pcall_callback( onLuaError );
    //registerErrorHandlers();

    createVM();
    luabind::set_pcall_callback( onLuaError );
    lua_atpanic (this->getVM(), onLuaPanic);
}
Пример #16
0
/* 创建lua全局状态机 */
LUALIB_API lua_State *luaL_newstate (void) {
  /*
   * l_alloc -> line 919 封装了realloc分配内存函数
   *
   * lua_newstate -> lstate.c line 262 创建lua全局状态机结构对象
   */
  lua_State *L = lua_newstate(l_alloc, NULL);
  if (L) lua_atpanic(L, &panic);
  return L;
}
Пример #17
0
//==============================================================================
Error LuaBinder::create(Allocator<U8>& alloc, void* parent)
{
	m_parent = parent;
	m_alloc = alloc;

	m_l = lua_newstate(luaAllocCallback, this);
	luaL_openlibs(m_l);
	lua_atpanic(m_l, &luaPanic);

	return ErrorCode::NONE;
}
Пример #18
0
lua_State *
ejoy2d_lua_init() {
	lua_State *L = luaL_newstate();
	checkluaversion(L);
	lua_pushliteral(L, OS_STRING);
	lua_setglobal(L , "OS");
	
	lua_atpanic(L, _panic);
	luaL_openlibs(L);
	return L;
}
Пример #19
0
State::State( Context* context_name ):mContext(context_name){
    
    mState = luaL_newstate();
    if(!mState){
		throw LuaException( "Error creating state for context: " + mContext->getName() );
    }
    luaL_openlibs( mState );
    luabind::open( mState );
    lua_atpanic(mState, &State::panic);
	luabind::set_pcall_callback(&defaultLuabindErrorHandler);
}
Пример #20
0
NzLuaInstance::NzLuaInstance() :
m_memoryLimit(0),
m_memoryUsage(0),
m_timeLimit(1000),
m_level(0)
{
	m_state = lua_newstate(MemoryAllocator, this);
	lua_atpanic(m_state, AtPanic);
	lua_sethook(m_state, TimeLimiter, LUA_MASKCOUNT, 1000);
	luaL_openlibs(m_state);
}
Пример #21
0
	void swig_return_userdata_measure(nonius::chronometer& meter) {
		lua_State* L = luaL_newstate();
		lua_atpanic(L, panic_throw);

		luaopen_lb(L);
		lua_do_or_die(L, "f = lb.basic_return");

		auto code = repeated_code("b = f(i)");
		meter.measure([&]() {
			lua_do_or_die(L, code.c_str());
		});
	}
Пример #22
0
Файл: lauxlib.c Проект: lua/lua
LUALIB_API lua_State *luaL_newstate (void) {
  lua_State *L = lua_newstate(l_alloc, NULL);
  if (L) {
    int *previoustocont;  /* space for warning state */
    lua_atpanic(L, &panic);
    previoustocont = (int *)lua_newuserdatauv(L, sizeof(int), 0);
    luaL_ref(L, LUA_REGISTRYINDEX);  /* make sure it won't be collected */
    *previoustocont = 0;  /* next message starts a new warning */
    lua_setwarnf(L, warnf, previoustocont);
  }
  return L;
}
Пример #23
0
LuaManager::LuaManager() : m_lua(NULL) {
	if (instantiated) {
		fprintf(stderr, "Can't instantiate more than one LuaManager");
		abort();
	}

	m_lua = luaL_newstate();
	pi_lua_open_standard_base(m_lua);
	lua_atpanic(m_lua, pi_lua_panic);

	instantiated = true;
}
Пример #24
0
	void swig_member_function_call_measure(nonius::chronometer& meter) {
		lua_State* L = luaL_newstate();
		lua_atpanic(L, panic_throw);

		luaopen_lb(L);
		lua_do_or_die(L, "b = lb.basic()");

		auto code = repeated_code(member_function_call_code);
		meter.measure([&]() {
			lua_do_or_die(L, code.c_str());
		});
	}
Пример #25
0
lua_State* my_lua_newstate_throwing() {
  lua_State* L = my_lua_newstate();
  if (!L) throw std::bad_alloc();
  lua_atpanic(L, atpanic_throw);
  try {
    my_lua_openlibs(L);
  } catch (...) {
    lua_close(L);
    throw;
  }
  return L;
}
Пример #26
0
void lbcontext_initialize_lua(struct lbcontext *lbctx)
{
	char *main_lua_script = NULL;
	char *lua_if_version = NULL;

	/* return immediately if already been here */
	if (!lbctx || lbctx->lua) return;

	if (asprintf(&main_lua_script, "%s/lua_scripts/main.lua",
	     ldbox_session_dir) < 0) {
		LB_LOG(LB_LOGLEVEL_ERROR,
			"lbcontext_initialize_lua: asprintf failed to allocate memory");
		return;
	}
		
	LB_LOG(LB_LOGLEVEL_INFO, "Loading '%s'", main_lua_script);

	lbctx->lua = luaL_newstate();
	lua_atpanic(lbctx->lua, lb_lua_panic);

	disable_mapping(lbctx);
	luaL_openlibs(lbctx->lua);
	lua_bind_lb_functions(lbctx->lua); /* register our lb_ functions */
	lua_bind_ruletree_functions(lbctx->lua); /* register our ruletree_ functions */
	lua_bind_lblib_functions(lbctx->lua); /* register lblib.* functions */

	load_and_execute_lua_file(lbctx, main_lua_script);

	enable_mapping(lbctx);

	/* check Lua/C interface version. */
	lua_if_version = read_string_variable_from_lua(lbctx,
		"lb_lua_c_interface_version");
	if (!lua_if_version) {
		LB_LOG(LB_LOGLEVEL_ERROR, "FATAL ERROR: "
			"lb's Lua scripts didn't provide"
			" 'lb_lua_c_interface_version' identifier!");
		exit(1);
	}
	if (strcmp(lua_if_version, LB_LUA_C_INTERFACE_VERSION)) {
		LB_LOG(LB_LOGLEVEL_ERROR, "FATAL ERROR: "
			"lb's Lua script interface version mismatch:"
			" scripts provide '%s', but '%s' was expected",
			lua_if_version, LB_LUA_C_INTERFACE_VERSION);
		exit(1);
	}
	free(lua_if_version);

	LB_LOG(LB_LOGLEVEL_INFO, "lua initialized.");
	LB_LOG(LB_LOGLEVEL_NOISE, "gettop=%d", lua_gettop(lbctx->lua));

	free(main_lua_script);
}
Пример #27
0
int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine,
		int nCmdShow) {

	window = GetDesktopWindow();

	lua_State*L = luaL_newstate();
	if (L == NULL) {
		MessageBoxW(window,L"Fatal Error" , L"Error while initializing LuaState", 0);
		return -1;
	}

	lua_atpanic(L, lua_panic);

	luaL_openlibs(L);

	_jason_openlibs(L); 	/* Open the additional built-in libraries */

	int status = 0;

	status = luaL_loadfile(L, INIT_FILE);

	if (status == LUA_ERRFILE)
		status = loadfileW(L, WINIT_FILE);

	if(status == LUA_ERRFILE) {
		MessageBoxW(window, _T(lua_tostring(L, -1)), L"Error opening init file", 0);
		return -1;
	}

	if(status!=0) {
		const char *s = lua_tostring(L, -1);
		MessageBoxW(window, _T(s), L"Error while compiling lua file", 0);
		return -1;
	}

	char param[BUFSIZ];
	wordToMultibyte(lpCmdLine, param);
	lua_pushstring(L, param);

	status = lua_pcall(L, 1, 0, 0);

	if(status!=0) {
		MessageBoxW(window, _T(lua_tostring(L, -1)), L"Error while initializing LuaState", 0);
		return -1;
	}


	lua_close(L);

	return 0;
}
Пример #28
0
	void swig_userdata_variable_access_last_measure(nonius::chronometer& meter) {
		lua_State* L = luaL_newstate();
		lua_atpanic(L, panic_throw);

		luaopen_lb(L);
		lua_do_or_die(L, "b = lb.basic_large()");

		auto code = repeated_code(
			userdata_variable_access_large_last_code
		);
		meter.measure([&]() {
			lua_do_or_die(L, code.c_str());
		});
	}
Пример #29
0
	void swig_implicit_inheritance_call_measure(nonius::chronometer& meter) {
		// Unsupported
		// E.g., we're doing something wrong
		lua_State* L = luaL_newstate();
		lua_atpanic(L, panic_throw);

		luaopen_lb(L);
		lua_do_or_die(L, "b = lb.complex_ab()");

		std::string code = repeated_code("b:b_func()");
		meter.measure([&]() {
			lua_do_or_die(L, code.c_str());
		});
	}
Пример #30
0
TSInternalLua::TSInternalLua(TSLua *tslua)
{
	mTSLua = tslua;
	mLuaState = luaL_newstate();
	lua_atpanic(mLuaState, tsluaI_atpanic);
	lua_pushlightuserdata(mLuaState, tslua);
	lua_setfield(mLuaState, LUA_REGISTRYINDEX, "tslua");
	lua_pushlightuserdata(mLuaState, this);
	lua_setfield(mLuaState, LUA_REGISTRYINDEX, "tsinternallua");
	luaL_openlibs(mLuaState);
	lua_pushcfunction(mLuaState, tsluaI_print);
	lua_setglobal(mLuaState, "print");
	lua_sethook(mLuaState, tsluaI_hook, LUA_MASKLINE | LUA_MASKRET, 0);
}