mirror of
				https://github.com/sammy-ette/Hilbish
				synced 2025-08-10 02:52:03 +00:00 
			
		
		
		
	idk how to explain this man in code `hilbish` is now a module, which can also be required like others. but it is already a global export as the variable of the same name. also
		
			
				
	
	
		
			47 lines
		
	
	
		
			831 B
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			47 lines
		
	
	
		
			831 B
		
	
	
	
		
			Go
		
	
	
	
	
	
| // Here is the core api for the hilbi shell itself
 | |
| // Basically, stuff about the shell itself and other functions
 | |
| // go here.
 | |
| package main
 | |
| 
 | |
| import (
 | |
| 	"os"
 | |
| 
 | |
| 	"github.com/yuin/gopher-lua"
 | |
| 	"mvdan.cc/sh/v3/interp"
 | |
| )
 | |
| 
 | |
| var exports = map[string]lua.LGFunction {
 | |
| 	"run": run,
 | |
| }
 | |
| 
 | |
| func HilbishLoader(L *lua.LState) int {
 | |
| 	mod := L.SetFuncs(L.NewTable(), exports)
 | |
| 
 | |
| 	host, _ := os.Hostname()
 | |
| 
 | |
| 	L.SetField(mod, "ver", lua.LString(version))
 | |
| 	L.SetField(mod, "user", lua.LString(curuser.Username))
 | |
| 	L.SetField(mod, "host", lua.LString(host))
 | |
| 
 | |
| 	L.Push(mod)
 | |
| 
 | |
| 	return 1
 | |
| }
 | |
| 
 | |
| // Runs a command
 | |
| func run(L *lua.LState) int {
 | |
| 	var exitcode uint8 = 0
 | |
| 	cmd := L.CheckString(1)
 | |
| 	err := execCommand(cmd)
 | |
| 
 | |
| 	if code, ok := interp.IsExitStatus(err); ok {
 | |
| 		exitcode = code
 | |
| 	} else if err != nil {
 | |
| 		exitcode = 1
 | |
| 	}
 | |
| 
 | |
| 	L.Push(lua.LNumber(exitcode))
 | |
| 	return 1
 | |
| }
 | |
| 
 |