mirror of https://github.com/Hilbis/Hilbish
feat: add fs.abs
parent
bca89197ad
commit
1714aeac36
|
@ -1,6 +1,7 @@
|
||||||
package fs
|
package fs
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -22,6 +23,7 @@ func loaderFunc(rtm *rt.Runtime) (rt.Value, func()) {
|
||||||
"mkdir": util.LuaExport{fmkdir, 2, false},
|
"mkdir": util.LuaExport{fmkdir, 2, false},
|
||||||
"stat": util.LuaExport{fstat, 1, false},
|
"stat": util.LuaExport{fstat, 1, false},
|
||||||
"readdir": util.LuaExport{freaddir, 1, false},
|
"readdir": util.LuaExport{freaddir, 1, false},
|
||||||
|
"abs": util.LuaExport{fabs, 1, false},
|
||||||
}
|
}
|
||||||
mod := rt.NewTable()
|
mod := rt.NewTable()
|
||||||
util.SetExports(rtm, mod, exports)
|
util.SetExports(rtm, mod, exports)
|
||||||
|
@ -132,3 +134,20 @@ func freaddir(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
|
||||||
|
|
||||||
return c.PushingNext1(t.Runtime, rt.TableValue(names)), nil
|
return c.PushingNext1(t.Runtime, rt.TableValue(names)), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// abs(path)
|
||||||
|
// Gives an absolute version of `path`.
|
||||||
|
// --- @param path string
|
||||||
|
func fabs(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
|
||||||
|
path, err := c.StringArg(0)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
abspath, err := filepath.Abs(path)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.PushingNext1(t.Runtime, rt.StringValue(abspath)), nil
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue