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 #define LUABIND_NO_HEADERS_ONLY
24 #include <luabind/luabind.hpp>
25 #include <boost/filesystem/operations.hpp>
26 #include <boost/filesystem/path.hpp>
28 #include "rtti_policy.hpp"
29 #include "directory_iterator.hpp"
31 const boost::filesystem::path
&
32 identity(const boost::filesystem::path
& x
)
37 void bind_filesystem(lua_State
* L
)
39 using namespace luabind
;
40 using namespace boost::filesystem
;
42 namespace fs
= boost::filesystem
;
44 module(L
, "filesystem")
46 class_
<fs::path
>("path")
48 .def(constructor
<const char*>())
49 .def("string", &fs::path::string
)
50 .def("native_file_string", &fs::path::native_file_string
)
51 .def("native_directory_string", &fs::path::native_directory_string
)
52 .def("root_path", &fs::path::root_path
)
53 .def("root_name", &fs::path::root_name
)
54 .def("root_directory", &fs::path::root_directory
)
55 .def("relative_path", &fs::path::relative_path
)
56 .def("leaf", &fs::path::leaf
)
57 .def("branch_path", &fs::path::branch_path
)
59 .def("empty", &fs::path::empty
)
60 .def("is_complete", &fs::path::is_complete
)
61 .def("is_directory", &fs::is_directory
)
62 .def("is_empty", &fs::is_empty
)
63 .def("has_root_path", &fs::path::has_root_path
)
64 .def("has_root_name", &fs::path::has_root_name
)
65 .def("has_root_directory", &fs::path::has_root_directory
)
66 .def("has_relative_path", &fs::path::has_relative_path
)
67 .def("has_leaf", &fs::path::has_leaf
)
68 .def("has_branch_path", &fs::path::has_branch_path
)
70 .def(const_self
/ const_self
)
71 .def(other
<const char*>() / const_self
)
72 .def(const_self
/ other
<const char*>())
74 .property("contents", &identity
, return_directory_iterator
)
77 def("exists", &fs::exists
),
78 def("is_directory", &fs::is_directory
),
79 def("is_empty", &fs::is_empty
),
80 def("create_directory", &fs::create_directory
),
81 def("remove", &fs::remove
),
82 def("remove_all", &fs::remove_all
),
83 def("rename", &fs::rename
),
84 def("copy_file", &fs::copy_file
),
86 def("initial_path", &fs::initial_path
),
87 def("current_path", &fs::current_path
),
88 def("complete", &fs::complete
),
89 def("system_complete", &fs::system_complete
)
93 int main(int argc
, const char* argv
[])
95 lua_State
* L
= lua_open();
105 std::cout
<< "usage: filesystem filename [args]\n";
109 using namespace luabind
;
115 object args
= newtable(L
);
117 for (int i
= 0; i
< argc
; ++i
)
119 args
[i
+ 1] = argv
[i
];
124 object globals
= get_globals(L
);
125 globals
["args"] = args
;
127 lua_dofile(L
, argv
[1]);
130 extern "C" int luaLM_import(lua_State
* L
)
132 using namespace luabind
;