Add chmod to file
package vm
-import "path/filepath"
+import (
+ "os"
+ "path/filepath"
+)
func initializeFileClass(vm *VM) {
class := initializeClass("File", false)
@@ -22,4 +25,22 @@ var builtinFileClassMethods = []*BuiltInMethod{
}
},
},
+ {
+ Name: "chmod",
+ Fn: func(receiver Object) builtinMethodBody {
+ return func(v *VM, args []Object, blockFrame *callFrame) Object {
+ filemod := args[0].(*IntegerObject).Value
+
+ for i := 1; i < len(args)-1; i++ {
+ filename := args[i].(*StringObject).Value
+ err := os.Chmod(filename, os.FileMode(uint32(filemod)))
+ if err != nil {
+ panic(err)
+ }
+ }
+
+ return initilaizeInteger(len(args) - 1)
+ }
+ },
+ },
}
