25#include <simgear/misc/sg_path.hxx>
27#include <simgear/nasal/cppbind/NasalHash.hxx>
28#include <simgear/nasal/cppbind/Ghost.hxx>
37 return ctx.to_nasal(
SGPathRef(
new SGPath(
p.utf8Str(),
38 &SGPath::NasalIORulesChecker)));
52 return p.create_dir(ctx.getArg<mode_t>(0, 0755) & 0775);
55static void f_path_set(SGPath&
p,
const nasal::CallContext& ctx)
57 p = SGPath::fromUtf8(ctx.getArg<std::string>(0),
p.getPermissionChecker());
63static naRef
f_desktop(
const nasal::CallContext& ctx)
66 ctx, SGPath::desktop(SGPath(&SGPath::NasalIORulesChecker)));
74 const std::string type_str = ctx.requireArg<std::string>(0);
75 SGPath::StandardLocation type = SGPath::HOME;
76 if( type_str ==
"DESKTOP" )
77 type = SGPath::DESKTOP;
78 else if( type_str ==
"DOWNLOADS" )
79 type = SGPath::DOWNLOADS;
80 else if( type_str ==
"DOCUMENTS" )
81 type = SGPath::DOCUMENTS;
82 else if( type_str ==
"PICTURES" )
83 type = SGPath::PICTURES;
84 else if( type_str !=
"HOME" )
87 "os.path.standardLocation: unknown type %s", type_str.c_str()
99 NasalSGPath::init(
"os.path")
101 .method(
"append", &SGPath::append)
102 .method(
"concat", &SGPath::concat)
104 .member(
"realpath", &SGPath::realpath)
105 .member(
"file", &SGPath::file)
106 .member(
"dir", &SGPath::dir)
107 .member(
"base", &SGPath::base)
108 .member(
"file_base", &SGPath::file_base)
109 .member(
"extension", &SGPath::extension)
110 .member(
"lower_extension", &SGPath::lower_extension)
111 .member(
"complete_lower_extension", &SGPath::complete_lower_extension)
112 .member(
"str", &SGPath::utf8Str)
113 .member(
"mtime", &SGPath::modTime)
115 .method(
"exists", &SGPath::exists)
116 .method(
"canRead", &SGPath::canRead)
117 .method(
"canWrite", &SGPath::canWrite)
118 .method(
"isFile", &SGPath::isFile)
119 .method(
"isDir", &SGPath::isDir)
120 .method(
"isRelative", &SGPath::isRelative)
121 .method(
"isAbsolute", &SGPath::isAbsolute)
122 .method(
"isNull", &SGPath::isNull)
125 .method(
"remove", &SGPath::remove)
126 .method(
"rename", &SGPath::rename);
128 nasal::Hash globals_module(
globals, c),
129 path = globals_module.createHash(
"os")
static naRef f_new_path(const nasal::CallContext &ctx)
os.path.new()
static naRef validatedPathToNasal(const nasal::CallContext &ctx, const SGPath &p)
static void f_path_set(SGPath &p, const nasal::CallContext &ctx)
naRef initNasalSGPath(naRef globals, naContext c)
static naRef f_standardLocation(const nasal::CallContext &ctx)
os.path.standardLocation(type)
static int f_path_create_dir(SGPath &p, const nasal::CallContext &ctx)
nasal::Ghost< SGPathRef > NasalSGPath
std::shared_ptr< SGPath > SGPathRef
static naRef f_desktop(const nasal::CallContext &ctx)
os.path.desktop()