2
2
mirror of https://github.com/Hilbis/Hilbish synced 2025-07-01 16:52:03 +00:00

feat: add missing functions, os.setenv

clua now starts with no errors.
This commit is contained in:
sammyette 2025-06-14 13:59:25 -04:00
parent 19938fa8ef
commit 6d793f35eb
Signed by: sammyette
GPG Key ID: 904FC49417B44DCD
4 changed files with 39 additions and 12 deletions

View File

@ -213,8 +213,8 @@ func (b *Bait) callRecoverer(event string, handler *Listener, err interface{}) {
func (b *Bait) Loader(rtm *moonlight.Runtime) moonlight.Value { func (b *Bait) Loader(rtm *moonlight.Runtime) moonlight.Value {
exports := map[string]moonlight.Export{ exports := map[string]moonlight.Export{
/*
"catch": {b.bcatch, 2, false}, "catch": {b.bcatch, 2, false},
/*
"catchOnce": util.LuaExport{b.bcatchOnce, 2, false}, "catchOnce": util.LuaExport{b.bcatchOnce, 2, false},
"throw": util.LuaExport{b.bthrow, 1, true}, "throw": util.LuaExport{b.bthrow, 1, true},
"release": util.LuaExport{b.brelease, 2, false}, "release": util.LuaExport{b.brelease, 2, false},
@ -261,15 +261,15 @@ bait.catch('hilbish.exit', function()
end) end)
#example #example
*/ */
func (b *Bait) bcatch(mlr *moonlight.Runtime, c *moonlight.GoCont) (moonlight.Cont, error) { func (b *Bait) bcatch(mlr *moonlight.Runtime) error {
name, catcher, err := util.HandleStrCallback(mlr) name, catcher, err := util.HandleStrCallback(mlr)
if err != nil { if err != nil {
return nil, err return err
} }
b.OnLua(name, catcher) b.OnLua(name, catcher)
return c.Next(), nil return nil
} }
/* /*

View File

@ -2,10 +2,6 @@
package moonlight package moonlight
import (
"fmt"
)
type Callable interface { type Callable interface {
Continuation(*Runtime, Cont) Cont Continuation(*Runtime, Cont) Cont
} }
@ -16,8 +12,6 @@ type Closure struct {
} }
func (mlr *Runtime) ClosureArg(num int) (*Closure, error) { func (mlr *Runtime) ClosureArg(num int) (*Closure, error) {
fmt.Println("type at ", num, "is", mlr.state.LTypename(num))
return &Closure{ return &Closure{
refIdx: -1, refIdx: -1,
}, nil }, nil

View File

@ -4,6 +4,7 @@ package moonlight
import ( import (
"fmt" "fmt"
"os"
"github.com/aarzilli/golua/lua" "github.com/aarzilli/golua/lua"
) )
@ -17,9 +18,39 @@ func NewRuntime() *Runtime {
L := lua.NewState() L := lua.NewState()
L.OpenLibs() L.OpenLibs()
return &Runtime{ mlr := &Runtime{
state: L, state: L,
} }
mlr.Extras()
return mlr
}
func (mlr *Runtime) Extras() {
mlr.state.GetGlobal("os")
mlr.pushToState(FunctionValue(mlr.GoFunction(setenv)))
mlr.state.SetField(-2, "setenv")
}
func setenv(mlr *Runtime) error {
if err := mlr.CheckNArgs(2); err != nil {
return err
}
env, err := mlr.StringArg(0)
if err != nil {
return err
}
varr, err := mlr.StringArg(1)
if err != nil {
return err
}
os.Setenv(env, varr)
return nil
} }
func (mlr *Runtime) PushNext1(v Value) { func (mlr *Runtime) PushNext1(v Value) {

View File

@ -1,7 +1,7 @@
-- Prelude initializes everything else for our shell -- Prelude initializes everything else for our shell
local _ = require 'succulent' -- Function additions local _ = require 'succulent' -- Function additions
local bait = require 'bait' local bait = require 'bait'
--local fs = require 'fs' local fs = require 'fs'
package.path = package.path .. ';' .. hilbish.dataDir .. '/?/init.lua' package.path = package.path .. ';' .. hilbish.dataDir .. '/?/init.lua'
.. ';' .. hilbish.dataDir .. '/?/?.lua' .. ";" .. hilbish.dataDir .. '/?.lua' .. ';' .. hilbish.dataDir .. '/?/?.lua' .. ";" .. hilbish.dataDir .. '/?.lua'
@ -66,6 +66,7 @@ do
}) })
end end
--[[
do do
local startSearchPath = hilbish.userDir.data .. '/hilbish/start/?/init.lua;' local startSearchPath = hilbish.userDir.data .. '/hilbish/start/?/init.lua;'
.. hilbish.userDir.data .. '/hilbish/start/?.lua' .. hilbish.userDir.data .. '/hilbish/start/?.lua'
@ -82,6 +83,7 @@ do
package.path = package.path .. ';' .. startSearchPath package.path = package.path .. ';' .. startSearchPath
end end
]]--
bait.catch('error', function(event, handler, err) bait.catch('error', function(event, handler, err)
print(string.format('Encountered an error in %s handler\n%s', event, err:sub(8))) print(string.format('Encountered an error in %s handler\n%s', event, err:sub(8)))