mirror of
				https://github.com/sammy-ette/Hilbish
				synced 2025-08-10 02:52:03 +00:00 
			
		
		
		
	fix: throw lua error if fs.cd fails
This commit is contained in:
		
							parent
							
								
									1d22e4cdc1
								
							
						
					
					
						commit
						5dd7ce382a
					
				| @ -13,6 +13,11 @@ func Loader(L *lua.LState) int { | ||||
|     return 1 | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| func LuaErr(L *lua.LState, code int) { | ||||
| 	L.Error(lua.LNumber(code), 1) | ||||
| } | ||||
| 
 | ||||
| var exports = map[string]lua.LGFunction{ | ||||
|     "cd": cd, | ||||
| } | ||||
| @ -20,7 +25,13 @@ var exports = map[string]lua.LGFunction{ | ||||
| func cd(L *lua.LState) int { | ||||
| 	path := L.ToString(1) | ||||
| 
 | ||||
| 	os.Chdir(path) | ||||
| 	err := os.Chdir(path) | ||||
| 	if err != nil { | ||||
| 		switch err.(*os.PathError).Err.Error() { | ||||
| 		case "no such file or directory": | ||||
| 			LuaErr(L, 1) | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	return 0 | ||||
| } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user