mirror of
				https://github.com/KoboldAI/KoboldAI-Client.git
				synced 2025-06-05 21:59:24 +02:00 
			
		
		
		
	Add support for multiple library paths in bridge.lua
This commit is contained in:
		| @@ -1461,7 +1461,7 @@ bridged = { | |||||||
|     "corescript_path": os.path.join(os.path.dirname(os.path.realpath(__file__)), "cores"), |     "corescript_path": os.path.join(os.path.dirname(os.path.realpath(__file__)), "cores"), | ||||||
|     "userscript_path": os.path.join(os.path.dirname(os.path.realpath(__file__)), "userscripts"), |     "userscript_path": os.path.join(os.path.dirname(os.path.realpath(__file__)), "userscripts"), | ||||||
|     "config_path": os.path.join(os.path.dirname(os.path.realpath(__file__)), "userscripts"), |     "config_path": os.path.join(os.path.dirname(os.path.realpath(__file__)), "userscripts"), | ||||||
|     "lib_path": os.path.join(os.path.dirname(os.path.realpath(__file__)), "extern", "lualibs"), |     "lib_paths": vars.lua_state.table(os.path.join(os.path.dirname(os.path.realpath(__file__)), "lualibs"), os.path.join(os.path.dirname(os.path.realpath(__file__)), "extern", "lualibs")), | ||||||
|     "load_callback": load_callback, |     "load_callback": load_callback, | ||||||
|     "print": lua_print, |     "print": lua_print, | ||||||
|     "warn": lua_warn, |     "warn": lua_warn, | ||||||
|   | |||||||
							
								
								
									
										28
									
								
								bridge.lua
									
									
									
									
									
								
							
							
						
						
									
										28
									
								
								bridge.lua
									
									
									
									
									
								
							| @@ -40,16 +40,23 @@ return function(_python, _bridged) | |||||||
|         return original |         return original | ||||||
|     end |     end | ||||||
|  |  | ||||||
|     ---@param path string |     ---@param paths string|table<integer, string> | ||||||
|     ---@return nil |     ---@return nil | ||||||
|     local function set_require_path(path) |     local function set_require_path(paths) | ||||||
|  |         if type(paths) == "string" then | ||||||
|  |             paths = {paths} | ||||||
|  |         end | ||||||
|         local config = {} |         local config = {} | ||||||
|         local i = 1 |         local i = 1 | ||||||
|         for substring in string.gmatch(package.config, "[^\n]+") do |         for substring in string.gmatch(package.config, "[^\n]+") do | ||||||
|             config[i] = substring |             config[i] = substring | ||||||
|             i = i + 1 |             i = i + 1 | ||||||
|         end |         end | ||||||
|         package.path = path .. config[1] .. config[3] .. ".lua" .. config[2] .. path .. config[1] .. config[3] .. config[1] .. "init.lua" |         local _paths = {} | ||||||
|  |         for i, path in ipairs(paths) do | ||||||
|  |             _paths[i] = path .. config[1] .. config[3] .. ".lua" .. config[2] .. path .. config[1] .. config[3] .. config[1] .. "init.lua" | ||||||
|  |         end | ||||||
|  |         package.path = table.concat(_paths, config[2]) | ||||||
|         package.cpath = "" |         package.cpath = "" | ||||||
|     end |     end | ||||||
|  |  | ||||||
| @@ -70,7 +77,7 @@ return function(_python, _bridged) | |||||||
|         local v = _bridged[k] |         local v = _bridged[k] | ||||||
|         bridged[k] = type(v) == "userdata" and _python.as_attrgetter(v) or v |         bridged[k] = type(v) == "userdata" and _python.as_attrgetter(v) or v | ||||||
|     end |     end | ||||||
|     set_require_path(bridged.lib_path) |     set_require_path(bridged.lib_paths) | ||||||
|  |  | ||||||
|  |  | ||||||
|     --========================================================================== |     --========================================================================== | ||||||
| @@ -1523,11 +1530,11 @@ return function(_python, _bridged) | |||||||
|     local old_package_searchers = package.searchers |     local old_package_searchers = package.searchers | ||||||
|     ---@param modname string |     ---@param modname string | ||||||
|     ---@param env table<string, any> |     ---@param env table<string, any> | ||||||
|     ---@param search_path? string |     ---@param search_paths? string|table<integer, string> | ||||||
|     ---@return any, string? |     ---@return any, string? | ||||||
|     local function requirex(modname, env, search_path) |     local function requirex(modname, env, search_paths) | ||||||
|         if search_path == nil then |         if search_paths == nil then | ||||||
|             search_path = bridged.lib_path |             search_paths = bridged.lib_paths | ||||||
|         end |         end | ||||||
|         if modname == "bridge" then |         if modname == "bridge" then | ||||||
|             return function() return env.kobold, env.koboldcore end |             return function() return env.kobold, env.koboldcore end | ||||||
| @@ -1545,7 +1552,7 @@ return function(_python, _bridged) | |||||||
|         local loader, path |         local loader, path | ||||||
|         local errors = {} |         local errors = {} | ||||||
|         local n_errors = 0 |         local n_errors = 0 | ||||||
|         set_require_path(search_path) |         set_require_path(search_paths) | ||||||
|         for k, v in ipairs(old_package_searchers) do |         for k, v in ipairs(old_package_searchers) do | ||||||
|             loader, path = v(modname) |             loader, path = v(modname) | ||||||
|             if allowsearch and type(loader) == "function" then |             if allowsearch and type(loader) == "function" then | ||||||
| @@ -1555,7 +1562,7 @@ return function(_python, _bridged) | |||||||
|                 errors[n_errors] = "\n\t" .. loader |                 errors[n_errors] = "\n\t" .. loader | ||||||
|             end |             end | ||||||
|         end |         end | ||||||
|         set_require_path(bridged.lib_path) |         set_require_path(bridged.lib_paths) | ||||||
|         if not allowsearch or type(loader) ~= "function" then |         if not allowsearch or type(loader) ~= "function" then | ||||||
|             error("module '" .. modname .. "' not found:" .. table.concat(errors)) |             error("module '" .. modname .. "' not found:" .. table.concat(errors)) | ||||||
|             return |             return | ||||||
| @@ -1770,7 +1777,6 @@ return function(_python, _bridged) | |||||||
|  |  | ||||||
|     ---@return nil |     ---@return nil | ||||||
|     function koboldbridge.load_userscripts(filenames, modulenames, descriptions) |     function koboldbridge.load_userscripts(filenames, modulenames, descriptions) | ||||||
|         set_require_path(bridged.userscript_path) |  | ||||||
|         config_files = {} |         config_files = {} | ||||||
|         config_file_filename_map = {} |         config_file_filename_map = {} | ||||||
|         koboldbridge.userscripts = {} |         koboldbridge.userscripts = {} | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Gnome Ann
					Gnome Ann