示例#1
0
文件: module_load.c 项目: c10ud/CHDK
// Unload module by name
void module_unload(const char* name)
{
    // Get full path to module file, and hash of path
    char path[60];
    unsigned int hash = get_module_path(path, name);

    // Find loaded module, and unload it
    module_unload_idx(module_find(hash));
}
示例#2
0
文件: modprobe.c 项目: dbittman/sea
int load(char *name, char *args, int force)
{
	if(!force && !check_depend(name))
		return -EINVAL;
	char *path = get_module_path(name);
	int r = sea_load_module(path, args, force ? SEA_MODULE_FORCE : 0);
	free(path);
	return r;
}
示例#3
0
文件: module_load.c 项目: c10ud/CHDK
//-----------------------------------------------
// Load module file and return ModuleInfo data
void get_module_info(const char *name, ModuleInfo *mi, char *modName, int modNameLen)
{
    memset(mi, 0, sizeof(ModuleInfo));
    if (modName)
        modName[0] = 0;     // Only used if module name stored in file (not a LANG string)

    // Get full path to module file, and hash of path
    char path[60];
    get_module_path(path, name);

    // open file
    int fd = open(path, O_RDONLY, 0777);
    if (fd < 0)
        return;

    // Read module header only to get size info
    flat_hdr flat;
    read(fd, (char*)&flat, sizeof(flat_hdr));

    // Check version and magic number - make sure it is a CHDK module file
    if ((flat.rev == FLAT_VERSION) && (flat.magic == FLAT_MAGIC_NUMBER))
    {
        lseek(fd, flat._module_info_offset, SEEK_SET);
        read(fd, mi, sizeof(ModuleInfo));

        if ((mi->moduleName >= 0) && modName)
        {
            // Load module name string
            lseek(fd, mi->moduleName, SEEK_SET);
            read(fd, modName, modNameLen-1);
            modName[modNameLen-1] = 0;
        }
    }

    close(fd);
}
示例#4
0
文件: module_load.c 项目: c10ud/CHDK
// Load a module referenced by a 'module_handler_t' structure
// Returns index into modules array if successful (or module already loaded)
// otherwise returns -1
static int _module_load(module_handler_t* hMod)
{
    int idx;

    // Get full path to module file, and hash of path
    char path[60];
    unsigned int hash = get_module_path(path, hMod->name);

    // Check if module already loaded
    idx = module_find(hash);
    if (idx >= 0)
        return idx;

    // Reset lib (should not be needed, loader should only be called from 'default' lib)
    *hMod->lib = hMod->default_lib;

    // Simple lock to prevent multiple attempts to load modules simultaneously (in different tasks)
    // Not perfect; but should be sufficient
    static int isLoading = 0;
    while (isLoading != 0) msleep(10);
    isLoading = 1;

    // Find empty slot   
    for (idx=0; idx<MAX_NUM_LOADED_MODULES && modules[idx].hdr; idx++) ;

    // If no slot found return error
    if  (idx == MAX_NUM_LOADED_MODULES)
    {
        moduleload_error(hMod->name, "too many modules loaded");
        idx = -1;
    }
    else
    {
        // Load and relocate module (returns 0 if error)
        flat_hdr* mod = module_preload(path, hMod->name, hMod->version);

        if (mod != 0)
        {
            // Module is valid. Finalize binding
            modules[idx].hdr = mod;
            modules[idx].hName = hash;
            modules[idx].hMod = hMod;

            int bind_err = bind_module(hMod, mod->_module_info->lib);

            // Call module loader if required
            if (!bind_err && mod->_module_info->lib->loader)
            {
                bind_err = mod->_module_info->lib->loader();
            }

            // If any errors, unload module and display error message
            if (bind_err)
            {
                module_unload_idx(idx);
                moduleload_error(hMod->name, "loader error");
                idx = -1;
            }
        }
        else
        {
            // module did not load, return invalid index
            idx = -1;
        }
    }

    // Release lock
    isLoading = 0;

    return idx;
}
示例#5
0
文件: util.cpp 项目: morinori/bitbox
/// @brief
bool get_current_module_path(_Out_ std::wstring& module_path)
{
    return get_module_path(NULL, module_path);
}
示例#6
0
//should report error if no Lua and kill object creation
void lua_setup_lua(t_jit_gl_lua *x)
{
	//load lua_listener class
	jit_lua_listener_init();

	x->lua = lua_open();
	luaL_openlibs(x->lua);			//standard Lua libs
	
	// get traceback function
	lua_getglobal(x->lua, "debug");
		lua_pushliteral(x->lua, "traceback");
		lua_gettable(x->lua, -2);

		lua_setfield(x->lua, LUA_REGISTRYINDEX, JIT_GL_LUA_TRACEBACK);
	lua_pop(x->lua, 1);
	
	//append package search path
	{
		char path[1024];
		char new_cpath[1024];
		const char *cpath;
		get_module_path(path);
		
		lua_getglobal(x->lua, "package");
		lua_pushstring(x->lua, "cpath");
		lua_rawget(x->lua, -2);
		
		cpath = lua_tostring(x->lua, -1);
		strcpy(new_cpath, cpath);
		
		strcat(new_cpath, ";");				//add delimiter
		strcat(new_cpath, path);			//add module path

#if TARGET_RT_MAC_MACHO
		strcat(new_cpath, "?.so");			//add so matcher
#else
		strcat(new_cpath, "?.dll");			//add dll matcher
#endif
		lua_pop(x->lua, 1);					//get rid of old cpath
		lua_pushstring(x->lua, "cpath");
		lua_pushstring(x->lua, new_cpath);
		
		lua_rawset(x->lua, -3);
		
		lua_pop(x->lua, 1);				//pop table from stack
	}
	
	
	luaopen_opengl(x->lua);			//LuaGL for OpenGL API bindings
	luaopen_glu(x->lua);			//LuaGLU for glu* OpenGL functions
	luaopen_jit(x->lua);			//Jitlib bindings jit.*
	luaopen_vecmath(x->lua);		//jit.vecmath.c bindings vec2.*/vec3.*/vec4.*/quat.*/mat3.*/mat4.*
	
	//print function from Lua that uses post()
	lua_pushcfunction(x->lua, lua_post);
	lua_setglobal(x->lua, "print");
	
	//outlet() function
	lua_pushcfunction(x->lua, lua_outlet);
	lua_setglobal(x->lua, "outlet");
	
	//importfile() function for loading in scripts within scripts
	lua_pushcfunction(x->lua, lua_importfile);
	lua_setglobal(x->lua, "importfile");
	
	//stackdump for printing the Lua stack
//	lua_pushcfunction(x->lua, stackDump);
//	lua_setglobal(x->lua, "stackdump");
		
	//setting global "this" variable to this instance of jit.gl.lua
	Jitobj_push(x->lua, x, 0);
	lua_setglobal(x->lua, "this");
	
	//put "this" in the global registry so it wont be garbage collected
	lua_pushstring(x->lua, x->lua_unique_name->s_name);
	lua_getglobal(x->lua, "this");
	lua_settable(x->lua, LUA_REGISTRYINDEX);
	
	//create a meta-patcher-message handler
	lua_getglobal(x->lua, "_G");					//get globals table
	luaL_newmetatable(x->lua, "_G_meta");			//create a new metatable
	lua_setmetatable(x->lua, -2);					//set the new metatable to be the globals metatable
	lua_pop(x->lua, 1);								//pop globals table from stack
	
	luaopen_jit_gl(x->lua);
}