10 bool dostring(lua_State
* L
, const char* str
)
12 if (luaL_loadbuffer(L
, str
, std::strlen(str
), str
) || lua_pcall(L
, 0, 0, 0))
14 const char* a
= lua_tostring(L
, -1);
15 std::cout
<< a
<< "\n";
22 #include <luabind/luabind.hpp>
23 #include <luabind/operator.hpp>
24 #include <boost/filesystem/operations.hpp>
25 #include <boost/filesystem/path.hpp>
27 #include "directory_iterator.hpp"
29 const boost::filesystem::path
&
30 identity(const boost::filesystem::path
& x
)
35 void bind_filesystem(lua_State
* L
)
37 using namespace luabind
;
38 using namespace boost::filesystem
;
40 namespace fs
= boost::filesystem
;
42 module(L
, "filesystem")
44 class_
<fs::path
>("path")
46 .def(constructor
<const char*>())
47 .def("string", &fs::path::string
)
48 .def("native_file_string", &fs::path::native_file_string
)
49 .def("native_directory_string", &fs::path::native_directory_string
)
50 .def("root_path", &fs::path::root_path
)
51 .def("root_name", &fs::path::root_name
)
52 .def("root_directory", &fs::path::root_directory
)
53 .def("relative_path", &fs::path::relative_path
)
54 .def("leaf", &fs::path::leaf
)
55 .def("branch_path", &fs::path::branch_path
)
57 .def("empty", &fs::path::empty
)
58 .def("is_complete", &fs::path::is_complete
)
59 .def("is_directory", &fs::is_directory
)
60 .def("is_empty", &fs::is_empty
)
61 .def("has_root_path", &fs::path::has_root_path
)
62 .def("has_root_name", &fs::path::has_root_name
)
63 .def("has_root_directory", &fs::path::has_root_directory
)
64 .def("has_relative_path", &fs::path::has_relative_path
)
65 .def("has_leaf", &fs::path::has_leaf
)
66 .def("has_branch_path", &fs::path::has_branch_path
)
68 .def(const_self
/ const_self
)
69 .def(other
<const char*>() / const_self
)
70 .def(const_self
/ other
<const char*>())
72 .property("contents", &identity
, return_directory_iterator
)
75 def("exists", &fs::exists
),
76 def("is_directory", &fs::is_directory
),
77 def("is_empty", &fs::is_empty
),
78 def("create_directory", &fs::create_directory
),
79 def("remove", &fs::remove
),
80 def("remove_all", &fs::remove_all
),
81 def("rename", &fs::rename
),
82 def("copy_file", &fs::copy_file
),
84 def("initial_path", &fs::initial_path
),
85 def("current_path", &fs::current_path
),
86 def("complete", &fs::complete
),
87 def("system_complete", &fs::system_complete
)
91 int main(int argc
, const char* argv
[])
93 lua_State
* L
= lua_open();
103 std::cout
<< "usage: filesystem filename [args]\n";
107 using namespace luabind
;
113 object args
= newtable(L
);
115 for (int i
= 0; i
< argc
; ++i
)
117 args
[i
+ 1] = argv
[i
];
122 object globals
= get_globals(L
);
123 globals
["args"] = args
;
125 lua_dofile(L
, argv
[1]);