mirror of
				https://github.com/sammy-ette/Hilbish
				synced 2025-08-10 02:52:03 +00:00 
			
		
		
		
	fix(fs): make stat better
return a table with 4 values: name, size, mode and isDir name -> name of path size -> size (obviously) mode -> permissions mode in a string as octal format isDir -> whether path is a directory
This commit is contained in:
		
							parent
							
								
									df70082a81
								
							
						
					
					
						commit
						6b065dc035
					
				@ -3,6 +3,7 @@
 | 
			
		||||
package fs
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"strconv"
 | 
			
		||||
	"os"
 | 
			
		||||
	"strings"
 | 
			
		||||
 | 
			
		||||
@ -72,13 +73,17 @@ func fmkdir(L *lua.LState) int {
 | 
			
		||||
func fstat(L *lua.LState) int {
 | 
			
		||||
	path := L.CheckString(1)
 | 
			
		||||
 | 
			
		||||
	// TODO: handle error here
 | 
			
		||||
	pathinfo, err := os.Stat(path)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		luaErr(L, err.Error())
 | 
			
		||||
		return 0
 | 
			
		||||
	}
 | 
			
		||||
	L.Push(luar.New(L, pathinfo))
 | 
			
		||||
	statTbl := L.NewTable()
 | 
			
		||||
	L.SetField(statTbl, "name", lua.LString(pathinfo.Name()))
 | 
			
		||||
	L.SetField(statTbl, "size", lua.LNumber(pathinfo.Size()))
 | 
			
		||||
	L.SetField(statTbl, "mode", lua.LString("0" + strconv.FormatInt(int64(pathinfo.Mode().Perm()), 8)))
 | 
			
		||||
	L.SetField(statTbl, "isDir", lua.LBool(pathinfo.IsDir()))
 | 
			
		||||
	L.Push(statTbl)
 | 
			
		||||
 | 
			
		||||
	return 1
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user