Beispiel #1
0
void LuaState::Init( bool initStandardLibrary )
{
	// Register some basic functions with Lua.
	if (initStandardLibrary)
	{
		// A "bug" in Lua 5.01 causes stack entries to be left behind.
		LuaAutoBlock autoBlock(this);
		luaopen_base(m_state);
		luaopen_table( m_state );
		luaopen_io(m_state);
		luaopen_string(m_state);
		luaopen_wstring(m_state);
		luaopen_math(m_state);
		luaopen_debug(m_state);
#ifndef _WIN32_WCE
		luaopen_loadlib(m_state);
#endif _WIN32_WCE

		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_LOG);

	lua_atpanic( m_state, FatalError );
}
Beispiel #2
0
int ltapi_libraries_load( lua_State * L )
{
    /* load required library and discard any possible results remaining at
     * the stack */

    luaopen_base( L );
    lua_settop( L, 0 );

    luaopen_table( L );
    lua_settop( L, 0 );

    luaopen_io( L );
    lua_settop( L, 0 );

    luaopen_string( L );
    lua_settop( L, 0 );

    luaopen_math( L );
    lua_settop( L, 0 );

    luaopen_debug( L );
    lua_settop( L, 0 );

    luaopen_loadlib( L );
    lua_settop( L, 0 );

    return 0;
}
Beispiel #3
0
ActionScript::ActionScript(Game *igame,const std::string &datadir,const std::string &scriptname):
game(igame),
_player(NULL)
{
	this->loaded = false;
	lastuid = 0;
	if(scriptname == "")
		return;
	luaState = lua_open();
	luaopen_loadlib(luaState);
	luaopen_base(luaState);
	luaopen_math(luaState);
	luaopen_string(luaState);
	luaopen_io(luaState);
    lua_dofile(luaState, std::string(datadir + "actions/lib/actions.lua").c_str());

#ifdef USING_VISUAL_2005
	FILE* in = NULL;
	fopen_s(&in, scriptname.c_str(), "r");
#else
	FILE* in=fopen(scriptname.c_str(), "r");
#endif //USING_VISUAL_2005
	if(!in){
		std::cout << "Error: Can not open " << scriptname.c_str() << std::endl;
		return;
	}
	else
		fclose(in);
	lua_dofile(luaState, scriptname.c_str());
	this->setGlobalNumber("addressOfActionScript", (int)this);
	this->loaded = true;
	this->registerFunctions();
}
Beispiel #4
0
initlua(void)
{
	PyObject *m;
	m = Py_InitModule("lua", lua_methods);

	if (!L) {
		L = lua_open();
		luaopen_base(L);
		luaopen_table(L);
		luaopen_io(L);
		luaopen_string(L);
		luaopen_debug(L);
		luaopen_loadlib(L);
		luaopen_python(L);
		lua_settop(L, 0);
	}
}
Beispiel #5
0
void ScriptManager::openLuaState() {
	_luaState = lua_open();
	if (!_luaState) {
		throw Common::Exception("Failed to open Lua state");
	}

	luaopen_base(_luaState);
	luaopen_io(_luaState);
	luaopen_math(_luaState);
	luaopen_string(_luaState);
	luaopen_table(_luaState);
	luaopen_loadlib(_luaState);
	luaopen_debug(_luaState);

	tolua_open(_luaState);

	lua_atpanic(_luaState, &ScriptManager::atPanic);
}
static lua_State *filtro_abrir_lua(modulo_t *modulo, const char *ruta) {
  dato_filtro_t * dato = (dato_filtro_t*)modulo->m_dato;
  lua_State *l;
  static const struct luaL_reg arraylib [] = {
    {"set", filtro_gestos_setarray},
    {"get", filtro_gestos_getarray},
    {"size", filtro_gestos_getsize},
    {"copiar", filtro_gestos_copiar},
    {"crear_copia", filtro_gestos_crear_copia},
    {"difuminar", filtro_gestos_difuminar},
    {"centrar", filtro_gestos_centrar},
    {"rotar", filtro_gestos_rotar},
    {"centrar2", filtro_gestos_centrar2},
    {"buscar_limites", filtro_gestos_buscar_limites},
    {"clean", filtro_gestos_clean},
    {"make_up", filtro_gestos_make_up},
    {"on_border", filtro_gestos_on_border},
    {"borrar_bounds", filtro_gestos_borrar_bounds},
    {NULL, NULL}
  };

  static const struct luaL_reg arrayparam [] = {
    {"get_colores", filtro_gestos_get_colores},
    {NULL, NULL}
  };

  dato->m_lua = lua_open();
  l = dato->m_lua;
  luaL_openlib(l, "imagen", arraylib, 0);
  luaL_openlib(l, "parametros", arrayparam, 0);

  luaopen_base(l);
  luaopen_table(l);
  luaopen_io(l);
  luaopen_string(l);
  luaopen_math(l);
  luaopen_loadlib(l);    

  luaL_loadfile(l, ruta);
  lua_pcall(l, 0, 0, 0);

  return l;
}
Beispiel #7
0
CLuaBridge::CLuaBridge(void) : m_pLuaContext(NULL)
{
	m_pLuaContext = lua_open();

	if (m_pLuaContext != NULL)
	{
		lua_pushcclosure(m_pLuaContext, LuaDebugMessage, 0);
		lua_setglobal(m_pLuaContext, "trace");

		lua_atpanic(m_pLuaContext, (lua_CFunction)HandleLuaAsssert);

		luaopen_io(m_pLuaContext);
		luaopen_math(m_pLuaContext);
		luaopen_base(m_pLuaContext);
		luaopen_loadlib(m_pLuaContext);
		luaopen_table(m_pLuaContext);
		luaopen_string(m_pLuaContext);
		luaopen_debug(m_pLuaContext);		
	}
}
Beispiel #8
0
int script_init()
{
	/* Create a script environment and install the standard libraries */
	L = lua_open();
	luaopen_base(L);
	luaopen_table(L);
	luaopen_io(L);
	luaopen_string(L);
	luaopen_math(L);
	luaopen_loadlib(L);

	lua_atpanic(L, panic);

	/* Register my extensions to the Lua environment */
	lua_register(L, "addoption",  addoption);
	lua_register(L, "_ALERT",     alert);
	lua_register(L, "copyfile",   copyfile);
	lua_register(L, "docommand",  docommand);
	lua_register(L, "dopackage",  dopackage);
	lua_register(L, "findlib",    findlib);
	lua_register(L, "matchfiles", matchfiles);
	lua_register(L, "newpackage", newpackage);

	/* Add some extensions to the built-in "os" table */
	lua_getglobal(L, "os");

	lua_pushstring(L, "chdir");
	lua_pushcfunction(L, chdir_lua);
	lua_settable(L, -3);

	lua_pushstring(L, "copyfile");
	lua_pushcfunction(L, copyfile);
	lua_settable(L, -3);

	lua_pushstring(L, "findlib");
	lua_pushcfunction(L, findlib);
	lua_settable(L, -3);

	lua_pushstring(L, "getcwd");
	lua_pushcfunction(L, getcwd_lua);
	lua_settable(L, -3);

	lua_pushstring(L, "rmdir");
	lua_pushcfunction(L, rmdir_lua);
	lua_settable(L, -3);

	lua_pop(L, 1);

	/* Register some commonly used Lua4 functions */
	lua_register(L, "rmdir", rmdir_lua);

	lua_getglobal(L, "table");
	lua_pushstring(L, "insert");
	lua_gettable(L, -2);
	lua_setglobal(L, "tinsert");
	lua_pop(L, 1);

	lua_getglobal(L, "os");
	lua_pushstring(L, "remove");
	lua_gettable(L, -2);
	lua_setglobal(L, "remove");
	lua_pop(L, 1);

	/* Set the global OS identifiers */
	lua_pushstring(L, os_get());
	lua_setglobal(L, "OS");

	lua_pushnumber(L, 1);
	lua_setglobal(L, os_get());

	/* Create a list of option descriptions for addoption() */
	lua_getregistry(L);
	lua_pushstring(L, "options");
	lua_newtable(L);
	lua_settable(L, -3);
	lua_pop(L, 1);

	/* Create and populate a global "options" table */
	buildOptionsTable();

	/* Create an empty list of packages */
	lua_getregistry(L);
	lua_pushstring(L, "packages");
	lua_newtable(L);
	lua_settable(L, -3);
	lua_pop(L, 1);

	/* Create a default project object */
	buildNewProject();

	/* Set hook to intercept creation of globals, used to create packages */
	lua_pushvalue(L, LUA_GLOBALSINDEX);
	lua_newtable(L);
	lua_pushstring(L, "__index");
	lua_pushcfunction(L, getglobal);
	lua_settable(L, -3);
	lua_setmetatable(L, -2);
	lua_pop(L, 1);

	return 1;
}