Example #1
0
int CDbgLuaHelper::PrepareLua(lua_State* l)
{
    // call this function immediatly before calling lua_pcall.
    //returns index in stack for errorFunc
//	return 0;
    lua_register(l, "DEBUGGER_ERRORMESSAGE", errormessageLua );
    lua_sethook(l, hookLua, LUA_MASKLINE|LUA_MASKCALL|LUA_MASKRET, 0);

    int top = lua_gettop(l);
    lua_getglobal(l, "DEBUGGER_ERRORMESSAGE");
    lua_insert(l, top);
    return top;

}
Example #2
0
void lua_sr_kemi_register_core(lua_State *L)
{
	int ret;

	lua_register(L, "KSR_C", sr_kemi_KSR_C);
	lua_register(L, "KSR_MOD_C", sr_kemi_KSR_MOD_C);

	ret = luaL_dostring(L,
			"KSR = {}\n"
			"KSR.__index = function (table, key)\n"
			"  return function (...)\n"
			"    return KSR_C(key, ...)\n"
			"  end\n"
			"end\n"
			"setmetatable(KSR, KSR)\n"
		);

	/* special modules - pv.get(...) can return int or str */
	luaL_openlib(L, "KSR.pv",   _sr_pv_Map,   0);
	luaL_openlib(L, "KSR.x",   _sr_kemi_x_Map,   0);

	LM_DBG("pushing lua KSR table definition returned %d\n", ret);
}
bool AssetBuilder::InitializeLua(const std::string & i_ScriptDir, const std::string & i_RelativeScriptPath)
{
	// Create a new Lua state
	{
		mluaState = luaL_newstate();
		if (!mluaState)
		{
			return false;
		}
	}
	// Open the standard libraries
	luaL_openlibs(mluaState);
	// Register custom functions
	{
		lua_register(mluaState, "CopyAssetFile", CopyAssetFile);
		lua_register(mluaState, "CreateDirectoryIfNecessary", CreateDirectoryIfNecessary);
		lua_register(mluaState, "DoesFileExist", DoesFileExist);
		lua_register(mluaState, "GetLastWriteTime", GetLastWriteTime);
		lua_register(mluaState, "OutputErrorMessage", OutputErrorMessage);
	}

	return true;
}
//Registers a new LUA data type and its meta methods (operators) and other methods
void LUA_OpenLibrary(lua_State* L, const VLUATypeInfo *pInfo, IVRSDUserDataAccessor* pUserDataAccessor /*= NULL*/)
{
  //Add all the meta methods for this class
  luaL_newmetatable(L, pInfo->pszTypeName);
  const luaL_Reg* pReg = pInfo->m_pMethods;
  LUA_RegMetatable(L, pReg);

  //Register a constructor for the new type
  if(pInfo->m_Constructor.func)
    lua_register(L, pInfo->m_Constructor.name, pInfo->m_Constructor.func);

  if(pUserDataAccessor)
    VRSDClient::GetGlobalClient().RegisterUserDataAccessor(pUserDataAccessor);
}
Example #5
0
int main() {
    lua_State * l = (lua_State *)luaL_newstate();
    const luaL_Reg *lib;

    for (lib = STANDARD_LIBS; lib->func; ++lib) {
        luaL_requiref(l, lib->name, lib->func, 1);
        lua_pop(l, 1);
    }

    lua_register(l, "sleep", lua_sleep);
    if (do_lua_file(l, "tests.lua"))
        return 0;
    return 1;
}
	void OpenVarListLibs( lua_State *L )
	{
		lua_register( L, "HasVarList", HasVarList );
		lua_register( L, "AddVar", AddVar );
		lua_register( L, "RemoveVar", RemoveVar );
		lua_register( L, "SetVar", SetVar );
		lua_register( L, "GetVar", GetVar );

		// some constants.
		lua_pushinteger( L, Script::VT_SCRIPT );
		lua_setglobal( L, "VT_SCRIPT" );
		lua_pushinteger( L, Script::VT_SRCSHAPE );
		lua_setglobal( L, "VT_SRCSHAPE" );
		lua_pushinteger( L, Script::VT_DESTSHAPE );
		lua_setglobal( L, "VT_DESTSHAPE" );
		lua_pushinteger( L, Script::VT_REGION );
		lua_setglobal( L, "VT_REGION" );
		lua_pushinteger( L, Script::VT_GLOBAL );
		lua_setglobal( L, "VT_GLOBAL" );

		lua_pushnumber( L, (lua_Number) Private::TypeTrait<VariableList::Number>::InvalidVal() );
		lua_setglobal( L, "INVALID_NUM" );
	}
Example #7
0
/**
 * \copydoc LuaData::import_from_lua
 */
bool DialogResources::import_from_lua(lua_State* l) {

  lua_pushlightuserdata(l, this);
  lua_setfield(l, LUA_REGISTRYINDEX, "dialogs");
  lua_register(l, "dialog", l_dialog);
  if (lua_pcall(l, 0, 0, 0) != 0) {
    Debug::error(std::string("Error in dialog data file: ")
                 + lua_tostring(l, -1));
    lua_pop(l, 1);
    return false;
  }

  return true;
}
void FactionManager::loadLuaConfig() {
	info("Loading config file.", true);

	Lua* lua = new Lua();
	lua->init();

	lua_register(lua->getLuaState(), "addFaction", addFaction);

	//Load the faction manager lua file.
	lua->runFile("scripts/managers/faction_manager.lua");

	delete lua;
	lua = NULL;
}
Example #9
0
void CLuaManager::DisableFunctions(lua_State *L)
{
	lua_register(L, "dofile", CLuaFunctions::DisableFunction);
	lua_register(L, "loadfile", CLuaFunctions::DisableFunction);
	lua_register(L, "loadlib", CLuaFunctions::DisableFunction);
	lua_register(L, "require", CLuaFunctions::DisableFunction);
	lua_register(L, "setfenv", CLuaFunctions::DisableFunction);
	lua_register(L, "getfenv", CLuaFunctions::DisableFunction);
}
Example #10
0
void CLuaMain::InitSecurity ( void )
{
    lua_register ( m_luaVM, "dofile", CLuaFunctionDefs::DisabledFunction );
    lua_register ( m_luaVM, "loadfile", CLuaFunctionDefs::DisabledFunction );
    lua_register ( m_luaVM, "require", CLuaFunctionDefs::DisabledFunction );
    lua_register ( m_luaVM, "loadlib", CLuaFunctionDefs::DisabledFunction );
    lua_register ( m_luaVM, "getfenv", CLuaFunctionDefs::DisabledFunction );
    lua_register ( m_luaVM, "newproxy", CLuaFunctionDefs::DisabledFunction );
}
Example #11
0
void map_register2lua(lua_State *L)
{
	lua_register(L,"NewBattleMap",&luaNewBattleMap);
	lua_register(L,"DelBattleMap",&luaDelBattleMap);
	lua_register(L,"GetPath",&luaGetPath);
	lua_register(L,"AoiEnterMap",&luaAoiEnterMap);
	lua_register(L,"AoiLeaveMap",&luaAoiLeaveMap);
	lua_register(L,"AoiMoveTo",&luaAoiMoveTo);	
}
Example #12
0
const easy_lua* easy_lua::export_function(
    const std::string_view& name,
    const FnCallback        callback ) const
{
    if( name.empty() || !callback ) {
        return nullptr;
    }
    lua_register( 
        EASY_LUA_CAST_LUA( this ), 
        name.data(), 
        reinterpret_cast<lua_CFunction>( callback )
    );

    return this;
}
bool CLuaModuleManager::RegisterFunction ( lua_State * luaVM, const char *szFunctionName, lua_CFunction Func )
{
    if ( luaVM )
    {
        //CLogger::LogPrintf ( "MODULE: Registering function \"%s\"\n", szFunctionName );
        if ( szFunctionName )
        {
            CLuaCFunctions::AddFunction ( szFunctionName, Func );
            lua_register ( luaVM, szFunctionName, Func );
        }
    } else {
        CLogger::LogPrintf ( "MODULE: Lua is not initialised.\n" );
    }
    return true;
}
Example #14
0
int luaopen_lualsp(lua_State *L)
{
#ifdef THREAD_SAFE
    lsp_io* io=(lsp_io*)lua_newuserdata(L,sizeof(lsp_io));
    memset((char*)io,0,sizeof(lsp_io));

    io->lctx=(void*)stdout;
    io->lputs=llsplib::lsp_def_puts;
    io->lputc=llsplib::lsp_def_putc;
    io->lwrite=llsplib::lsp_def_write;

    lua_setfield(L,LUA_REGISTRYINDEX,llsplib::lsp_io_type);
#endif
    
    lua_register(L,"dotmpl",llsplib::lua_include);
    lua_register(L,"dofile_lsp",llsplib::lua_include);
    lua_register(L,"echo",llsplib::lua_echo);
    lua_register(L,"write",llsplib::lua_echo);
    lua_register(L,"print",llsplib::lua_print);
    
    luaopen_lualspaux(L);
    
    return 0;
}
Example #15
0
 int reg_function(const char *name, lua_CFunction func)
 {
     if (L)
     {
         if (name
             && *name != 0
             && func)
         {
             lua_register(L, name, func);
             return 0;
         }
         return -1;
     }
     return -2;
 }
Example #16
0
int initSpells()
{
	std::cout << "Loading Spells...\n";
	LuaSpells = luaL_newstate(); //create new lua state
	luaL_openlibs(LuaSpells);

	lua_register(LuaSpells,"loadspell",loadspell); //register loadspell
	lua_register(LuaSpells,"loadsummon",loadsummon); //register loadsummon
	registerLua(LuaSpells); //register functions

	if(luaL_loadfile(LuaSpells, "Lua\\Spells.lua") || lua_pcall(LuaSpells, 0, 0, 0)) 
	{
        std::cout<<"Error: failed to load Spells.lua"<<std::endl;
		std::cout << lua_tostring(LuaSpells,-1) << "\n";
		getch();
		return -1;
    }

	lua_getglobal(LuaSpells,"loadSpells");
	lua_pcall(LuaSpells,0,0,0); //execute once to load units
	lua_pop(LuaSpells,1);
	
	return 0;
}
Example #17
0
bool Core::init()
{
    lua = luaL_newstate();
    assert(lua != 0);
    luaL_checkversion(lua);

    // Stop garbage collector.
    lua_gc(lua, LUA_GCSTOP, 0); 

    // Load Lua core libraries.
    // \todo maybe don't load lua libraries to save memory (and omit from build).
    luaL_openlibs(lua);

    // Register core function with Lua.
    lua_register(lua, "quit", Script::quit);
    lua_register(lua, "backgroundColor", Script::backgroundColor);
    lua_register(lua, "create", Script::create);
    lua_register(lua, "pos", Script::pos);
    lua_register(lua, "move", Script::move);
    lua_register(lua, "destroy", Script::destroy);
    lua_register(lua, "pc", Script::pc);
    lua_register(lua, "tone", Script::tone);

    // Restart garbage collector.
    lua_gc(lua, LUA_GCRESTART, 0);

    if (!Graphics::init())
    {
        return false;
    }

    if (!assetContainer.setContainerFilename("content.seng"))
    {
		Platform::error << "Failed to load content file: content.seng" << std::endl << std::endl;
		Platform::error << "AssetContainer error: " << assetContainer.getLastError() << std::endl << std::endl;
        return false;
    }
    char initScript[1024];
    if (!assetContainer.getString("scripts/init.lua", initScript, 1024))
    {
		Platform::error << "AssetContainer error: " << assetContainer.getLastError();
        return false;
    }
    doString(initScript);
    return true;
}
Example #18
0
void SE_funcs_register( lua_State *L )
{
	//lua_register( L, "test_func", test_func );
	lua_register( L, "l2h_delay", l2h_delay );
	lua_register( L, "l2h_print", l2h_print );
	lua_register( L, "l2h_console_enable", l2h_console_enable );
	lua_register( L, "l2h_soundAlert", l2h_soundAlert );
	lua_register( L, "l2h_time", l2h_time );
	lua_register( L, "l2h_timeMsec", l2h_timeMsec );
}
Example #19
0
void CLuaHTTPDefs::LoadFunctions ( lua_State* luaVM )
{
    // Register these funcs for that VM
    lua_register ( luaVM, "httpWrite", CLuaHTTPDefs::httpWrite );
	lua_register ( luaVM, "httpSetResponseHeader", CLuaHTTPDefs::httpSetResponseHeader );
	lua_register ( luaVM, "httpSetResponseCookie", CLuaHTTPDefs::httpSetResponseCookie );
	lua_register ( luaVM, "httpSetResponseCode", CLuaHTTPDefs::httpSetResponseCode );
	lua_register ( luaVM, "httpClear", CLuaHTTPDefs::httpClear );
	lua_register ( luaVM, "httpRequestLogin", CLuaHTTPDefs::httpRequestLogin );
}
Example #20
0
luaopen_gears_async_libluabridge(lua_State *L)
#endif
{
   /* Async I/O methods */
   lua_register(L, "aio_scan_directory" , lua_aio_scan_directory );
   lua_register(L, "aio_file_info"      , lua_aio_file_info      );
   lua_register(L, "aio_watch_gfile"    , lua_aio_watch_gfile    );
   lua_register(L, "aio_load_file"      , lua_aio_load_file      );
   lua_register(L, "aio_append_to_file" , lua_aio_append_to_file );
   lua_register(L, "aio_file_write"     , lua_aio_file_write     );

#ifdef ENABLE_GTK
   lua_register(L, "aio_load_icon"      , lua_aio_load_icon      );
   lua_register(L, "aio_file_icon"      , lua_aio_file_icon      );
#endif

   /* Request helper methods */
   lua_register(L, "request_connect"    , lua_request_connect    );

   return 0;
}
DnaManager::DnaManager() : Logger("DnaManager") {
	lua = new Lua();
	lua->init();
	lua_register(lua->getLuaState(), "addQualityTemplate", addQualityTemplate);

	lua->setGlobalInt("FORTITUDE", DnaManager::FORTITUDE);
	lua->setGlobalInt("ENDURANCE", DnaManager::ENDURANCE);
	lua->setGlobalInt("CLEVERNESS", DnaManager::CLEVERNESS);
	lua->setGlobalInt("COURAGE", DnaManager::COURAGE);
	lua->setGlobalInt("POWER", DnaManager::POWER);
	lua->setGlobalInt("DEPENDABILITY", DnaManager::DEPENDABILITY);
	lua->setGlobalInt("DEXTERITY", DnaManager::DEXTERITY);
	lua->setGlobalInt("FIERCENESS", DnaManager::FIERCENESS);
	lua->setGlobalInt("HARDINESS", DnaManager::HARDINESS);
	lua->setGlobalInt("INTELLIGENCE", DnaManager::INTELLIGENCE);
}
Example #22
0
/** Metoda uruchamia skrypt lua, ktory dodaje wszystkie informacje
 *  o spritach. W skrypcie dostepna jest metoda cxx_addSprite
 * @param void
 * @return void
 */
void SpriteManager::loadConfig() {

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

    // Rejestracja metody ktora jest wywolywna ze skryptu
    lua_register( L, "cxx_addSprite", SpriteManager::addSprite );

    //Wolanie skryptu
    if ( luaL_dofile( L, "data/sprite_config.lua" ) != 0 ) {
        gCritical(lua_tostring( L, -1 ));
        throw("SpriteManager::loadConfig");
    }

    lua_close(L);
}
Example #23
0
// Constructor
_Scripting::_Scripting() :
	Server(nullptr),
	LuaState(nullptr) {

	// Initialize lua object
	LuaState = luaL_newstate();
	luaopen_base(LuaState);
	luaopen_math(LuaState);

	// Set globals
	lua_pushlightuserdata(LuaState, this);
	lua_setglobal(LuaState, "param_scripting");

	// Register C++ functions used by lua
	lua_register(LuaState, "map_change", &MapChangeFunction);
}
Example #24
0
void exportLuaScriptAPI(lua_State* L)
{
	// geometric functions
	lua_register(L, "reflect", reflect);
	lua_register(L, "refract", refract);
	lua_register(L, "faceforward", faceforward);
	// shading functions
	lua_register(L, "ambient", ambient);
	lua_register(L, "diffuse", diffuse);
	lua_register(L, "specular", specular);
}
Example #25
0
		/// called by Register(), registers object-methods (see cLuaBind constructor for examples)
		virtual void RegisterMethods	(lua_State *L) { PROFILE
			// mlMethod.push_back((struct luaL_reg){"Meemba",		cWidget_L::Get});
			// lua_register(L,"MyGlobalFun",	MyGlobalFun);
			// lua_register(L,"MyStaticMethod",	&cSomeClass::MyStaticMethod);

			lua_register(L,"GetWidgetUnderPos",		&cWidget_L::GetWidgetUnderPos);

			#define REGISTER_METHOD(methodname) mlMethod.push_back(make_luaL_reg(#methodname,&cWidget_L::methodname));

			REGISTER_METHOD(Destroy);
			REGISTER_METHOD(CreateChild);
			REGISTER_METHOD(UpdateClip);
			REGISTER_METHOD(SetBitMask);
			REGISTER_METHOD(IsUnderPos);
			
			#undef REGISTER_METHOD
		}
Example #26
0
int main(int argc, const char * argv[]) {
    lua_State *lState;
    
    lState = luaL_newstate();
    luaL_openlibs( lState );
    
    lua_register( lState, "GetLockpickLevel", lua_GetLockpickLevel );
    
    int iStatus = luaL_loadstring( lState, szLua );
    if( iStatus )
    {
        std::cout << "Error: " << lua_tostring( lState, -1 );
        return 1;
    }
    
    iStatus = lua_pcall( lState, 0, 0, 0 );
    if( iStatus )
    {
        std::cout << "Error: " << lua_tostring( lState, -1 );
        return 1;
    }
    
    lua_getfield( lState, LUA_GLOBALSINDEX, "game_door_check" );
    CGameData Data( 8 );
    lua_pushlightuserdata( lState, (void *) &Data );
    iStatus = lua_pcall( lState, 1, 1, 0 );
    if( iStatus )
    {
        std::cout << "Error: " << lua_tostring( lState, -1 );
        return 1;
    }
    
    int iRet = (int) lua_toboolean( lState, -1 );
    if( iRet )
    {
        std::cout << "Door opened!" << std::endl;
    }
    else
    {
        std::cout << "Door still closed." << std::endl;
    }
    
    lua_close( lState );
    
    return 0;
}
Example #27
0
void KitsuneSwagConsole::LoadKSCLuaLib(){

	lua_sethook(L, luadiehook, LUA_MASKCOUNT, 10000);
	lua_register(L, "print", lua_putsmyprint);

	RegFunc( "Clear", lua_cls);
	RegFunc( "Exit", lua_die);
	RegFunc( "Close", lua_closesocket);
	RegFunc( "GetAll", lua_getall); 
	RegFunc( "GetInfo", lua_getinfo);
	RegFunc("Client", lua_connectclient);
	RegFunc("Server", lua_connectserver);
	RegFunc("SetVisible", lua_SetVisible);
	RegFunc("GetVisible", lua_GetVisible);
	RegFunc("Focus", lua_Focus);

	struct luaL_reg driver[] = {
		{ "Send", lua_send },
		{ "Close", lua_closesocket },
		{ "AsInt", lua_stoi },
		{ NULL, NULL },
	};

	struct luaL_reg ls_meta[] = {
		{ "__gc", ls__gc },
		{ "__tostring", ls__tostring },
		{ "__eq", ls__eq },
		{ "__lt", ls__lt },
		{ "__le", ls__le },
		//{ "__add", Foo_add },
		{ 0, 0 }
	};

	luaL_openlib(L, PROJECT_TABLENAME, driver, 0);

	luaL_newmetatable(L, PROJECT_TABLENAME);
	luaL_openlib(L, 0, ls_meta, 0);
	lua_pushliteral(L, "__index");
	lua_pushvalue(L, -3);
	lua_rawset(L, -3);
	lua_pushliteral(L, "__metatable");
	lua_pushvalue(L, -3);
	lua_rawset(L, -3);

	lua_setglobal(ASWN->L, PROJECT_TABLENAME);
}
Example #28
0
File: m.c Project: halx99/sherldb
int main() {
    int i;
    const char *file = "my.lua";

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

    lua_register(L, "c_break", c_break);

    ldb = ldb_new(L, reload);
    luaL_dofile(L, file);

    ldb_free(ldb);
    lua_close(L);

    return 0;
}
Example #29
0
    template<class T> void
    bind<T>::reg( lua_State* L, const std::string& name )
        {
        TUMBO_LUA_STACKASSERT(L,0);
        NAME = name;

        luaL_Reg meta[] =
            {
            { "__add", add },
            { "__unm", unary_minus },
            { "__sub", sub },
            { "__mul", mul },
            { "__div", div },
            { "__call", mat_call },
            { "__tostring", tostr },
            { "__index", mat_index },
            { "__newindex", mat_assign_index },
            { "__len", mat_size },
            { NULL, NULL }
            };
        luaL_Reg meth[] =
            {
            { "inverse", inverse },
            { NULL, NULL }
            };
        int metatable, methodtable;
        /* Create the metatable. */
        luaL_newmetatable( L, NAME.c_str() );
        metatable = lua_gettop(L);
        TUMBO_LUA_SETFUNCS( L, meta );

        /* Create methods table. */
        lua_newtable( L );
        methodtable = lua_gettop(L);
        TUMBO_LUA_SETFUNCS( L, meth );
        /* Set the method table as the meta __index table. */
        lua_pushstring(L, "methods");
        lua_pushvalue(L, methodtable);
        lua_rawset(L, metatable);

        /* Make the constructor available as a global. */
        lua_register(L, NAME.c_str(), create);
        /* Remove the metatable. */
        lua_pop(L,2);
        }
Example #30
0
void CustomSystem::Init()
{
	lua_State *L = csLua = lua_open();
	luaL_openlibs(L);
	OOLUA::setup_user_lua_state(L);

	PiLuaClasses::RegisterClasses(L);
	LuaConstants::Register(L);

	OOLUA::register_class<CustomSystem>(L);
	OOLUA::register_class<CustomSBody>(L);

	lua_register(L, "load_lua", pi_load_lua);

	pi_lua_dofile(L, "pisystems.lua");

	lua_close(L);
}