Reimplemented build system.
[luabind.git] / examples / filesystem / filesystem.cpp
blob5d6915ee875712593c1317ce506205096af9803d
1 #include <iostream>
3 extern "C"
5 #include "lua.h"
6 #include "lauxlib.h"
7 #include "lualib.h"
10 #include <luabind/luabind.hpp>
11 #include <luabind/operator.hpp>
12 #include <boost/filesystem/operations.hpp>
13 #include <boost/filesystem/path.hpp>
15 #include "directory_iterator.hpp"
17 const boost::filesystem::path&
18 identity(const boost::filesystem::path& x)
20 return x;
23 void bind_filesystem(lua_State* L)
25 using namespace luabind;
26 using namespace boost::filesystem;
28 namespace fs = boost::filesystem;
30 module(L, "filesystem")
32 class_<fs::path>("path")
33 .def(constructor<>())
34 .def(constructor<const char*>())
35 .def("string", &fs::path::string)
36 .def("native_file_string", &fs::path::native_file_string)
37 .def("native_directory_string", &fs::path::native_directory_string)
38 .def("root_path", &fs::path::root_path)
39 .def("root_name", &fs::path::root_name)
40 .def("root_directory", &fs::path::root_directory)
41 .def("relative_path", &fs::path::relative_path)
42 .def("leaf", &fs::path::leaf)
43 .def("branch_path", &fs::path::branch_path)
45 .def("empty", &fs::path::empty)
46 .def("is_complete", &fs::path::is_complete)
47 .def("is_directory", &fs::is_directory)
48 .def("is_empty", &fs::is_empty)
49 .def("has_root_path", &fs::path::has_root_path)
50 .def("has_root_name", &fs::path::has_root_name)
51 .def("has_root_directory", &fs::path::has_root_directory)
52 .def("has_relative_path", &fs::path::has_relative_path)
53 .def("has_leaf", &fs::path::has_leaf)
54 .def("has_branch_path", &fs::path::has_branch_path)
56 .def(const_self / const_self)
57 .def(other<const char*>() / const_self)
58 .def(const_self / other<const char*>())
60 // .property("contents", &identity, return_directory_iterator)
63 def("exists", &fs::exists),
64 def("is_directory", &fs::is_directory),
65 def("is_empty", &fs::is_empty),
66 def("create_directory", &fs::create_directory),
67 def("remove", &fs::remove),
68 def("remove_all", &fs::remove_all),
69 def("rename", &fs::rename),
70 def("copy_file", &fs::copy_file),
72 def("initial_path", &fs::initial_path),
73 def("current_path", &fs::current_path),
74 def("complete", &fs::complete),
75 def("system_complete", &fs::system_complete)
79 int main(int argc, const char* argv[])
81 lua_State* L = lua_open();
82 luaopen_base(L);
83 luaopen_string(L);
84 luaopen_table(L);
85 luaopen_math(L);
86 luaopen_io(L);
87 luaopen_debug(L);
89 if (argc < 2)
91 std::cout << "This example will bind parts of the boost.Filesystem library\n"
92 "and then run the given lua file.\n\n"
93 "usage: filesystem filename [args]\n";
94 return 1;
97 using namespace luabind;
99 open(L);
101 bind_filesystem(L);
103 object args = newtable(L);
105 for (int i = 0; i < argc; ++i)
107 args[i + 1] = argv[i];
110 args["n"] = argc;
111 globals(L)["args"] = args;
113 luaL_dofile(L, argv[1]);