mirror of
				https://github.com/sammy-ette/Hilbish
				synced 2025-08-10 02:52:03 +00:00 
			
		
		
		
	fix: read file manually in DoFile to avoid shebang
This commit is contained in:
		
							parent
							
								
									e91cf98634
								
							
						
					
					
						commit
						48ab7c13ac
					
				
							
								
								
									
										42
									
								
								util/util.go
									
									
									
									
									
								
							
							
						
						
									
										42
									
								
								util/util.go
									
									
									
									
									
								
							@ -1,6 +1,8 @@
 | 
				
			|||||||
package util
 | 
					package util
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
 | 
						"bufio"
 | 
				
			||||||
 | 
						"io"
 | 
				
			||||||
	"os"
 | 
						"os"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	rt "github.com/arnodel/golua/runtime"
 | 
						rt "github.com/arnodel/golua/runtime"
 | 
				
			||||||
@ -49,13 +51,47 @@ func DoString(rtm *rt.Runtime, code string) error {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// DoFile runs the contents of the file in the Lua runtime.
 | 
					// DoFile runs the contents of the file in the Lua runtime.
 | 
				
			||||||
func DoFile(rtm *rt.Runtime, filename string) error {
 | 
					func DoFile(rtm *rt.Runtime, path string) error {
 | 
				
			||||||
	data, err := os.ReadFile(filename)
 | 
						f, err := os.Open(path)
 | 
				
			||||||
 | 
						defer f.Close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						reader := bufio.NewReader(f)
 | 
				
			||||||
 | 
						c, err := reader.ReadByte()
 | 
				
			||||||
 | 
						if err != nil && err != io.EOF {
 | 
				
			||||||
 | 
							return err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						err = reader.UnreadByte()
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return err
 | 
							return err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return DoString(rtm, string(data))
 | 
						if c == byte('#') {
 | 
				
			||||||
 | 
							// shebang - skip that line
 | 
				
			||||||
 | 
							_, err := reader.ReadBytes('\n')
 | 
				
			||||||
 | 
							if err != nil && err != io.EOF {
 | 
				
			||||||
 | 
								return err
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						var buf []byte
 | 
				
			||||||
 | 
						for {
 | 
				
			||||||
 | 
							line, err := reader.ReadBytes('\n')
 | 
				
			||||||
 | 
							if err != nil {
 | 
				
			||||||
 | 
								if err == io.EOF {
 | 
				
			||||||
 | 
									break
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								return err
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							buf = append(buf, line...)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return DoString(rtm, string(buf))
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// HandleStrCallback handles function parameters for Go functions which take
 | 
					// HandleStrCallback handles function parameters for Go functions which take
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user