Permalink
Browse files

add readme and license

  • Loading branch information...
1 parent 85bb00e commit edabe265ab0e994c63ce9b689f9e8bf67fe8c3f7 jpike committed Jan 6, 2011
Showing with 108 additions and 0 deletions.
  1. +13 −0 LICENSE
  2. +95 −0 README.markdown
View
13 LICENSE
@@ -0,0 +1,13 @@
+Copyright (c) 2010-2011 TS-Associates
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge,
+publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
+subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
+FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
View
@@ -0,0 +1,95 @@
+# vu8
+
+vu8 is a project that allows one to give JavaScript access to C++ classes and methods. The binding library is a header only library that uses template-metaprogramming extensively to make binding as easy as possible for the library user.
+
+## vu8 also provides
+
+* libvu8.a - a static library to add "loadmodule" to the v8 javascript context. loadmodule is a system for loading plugins from shared libraries.
+* v8 cmake - cmake modules to make it easy to build modules for use with loadmodule. It is recommended that modules use the vu8 meta-programming library to bind C++ to JavaScript but this is not mandatory.
+
+## vu8 class binding example
+ struct FileBase {
+ bool IsOpen() { return stream_.is_open(); }
+ bool Good() { return stream_.good(); }
+ bool Eof() { return stream_.eof(); }
+ void Close() { stream_.close(); }
+
+ protected:
+ std::fstream stream_;
+ };
+
+ struct FileWriter : FileBase {
+ bool Open(char const *str) { ... }
+ void Print(const v8::Arguments& args) { ... }
+ FileWriter(const v8::Arguments& args) { ... }
+ };
+
+ struct FileReader : FileBase { ... };
+
+ static inline v8::Handle<v8::Value> Open() {
+ v8::HandleScope scope;
+ vu8::BasicClass<FileBase> fileBase;
+ fileBase.Method<void (), &FileBase::Close>("close")
+ .Method<bool (), &FileBase::Good>("good")
+ .Method<bool (), &FileBase::IsOpen>("is_open")
+ .Method<bool (), &FileBase::Eof>("eof")
+ ;
+
+ // FileWriter inherits from FileBase
+ vu8::Class<FileWriter> fileWriter(fileBase);
+ fileWriter.Method<bool (char const *), &FileWriter::Open>("open")
+ .Method<void, &FileWriter::Print>("print")
+ .Method<void, &FileWriter::Println>("println")
+ ;
+ // Print takes v8::Arguments directly so only the return type
+ // needs to be specified rather than the signature
+
+ vu8::Class<FileReader> fileReader(fileBase);
+ // ... more code
+
+
+ // Create a module to add the classes to and return a new
+ // instance of the module to be embedded into the v8 context
+ vu8::Module mod;
+ return mod("Writer", fileWriter)
+ ("Reader", fileReader).NewInstance();
+ }
+
+## vu8 module example
+ #include <vu8/Module.hpp>
+ #include <iostream>
+
+ namespace vu8 { namespace console {
+
+ v8::Handle<v8::Value> Println(const v8::Arguments& args) { ... }
+
+ static inline v8::Handle<v8::Value> Open() {
+ v8::HandleScope scope;
+ Module mod;
+ mod("println", &Println);
+ return mod.NewInstance();
+ }
+
+ } }
+
+ extern "C" {
+ // vu8_module_<modname> is the entry point
+ v8::Handle<v8::Value> vu8_module_console() {
+ return vu8::console::Open();
+ }
+ }
+
+## Building a vu8 module using vu8 cmake
+ find(Vu8)
+ set(CMAKE_MODULE_PATH ${VU8_MODULE_PATH})
+ include(Vu8)
+ vu8_plugin(console "file1.cpp;file2.cpp")
+ # the above will add the make target and cause the module to be
+ # installed into the vu8 module path
+
+## Creating a v8 Context capable of using loadmodule
+ #include <vu8/Context.hpp>
+ vu8::Context ctxt;
+ // script at location jsFile can now use loadmodule. An application
+ // that uses vu8::Context must link against libvu8.a
+ ctxt.RunFile(jsFile);

0 comments on commit edabe26

Please sign in to comment.