From 8682feb9e9a89006db7bee43d4a4b3f4f1166e98 Mon Sep 17 00:00:00 2001 From: Luis Blanco Date: Sun, 31 Dec 2017 22:02:20 +0300 Subject: [PATCH] initial --- .gitignore | 12 +++++ .npmignore | 12 +++++ LICENSES | 59 ++++++++++++++++++++++ README.md | 2 + include/addon-tools.hpp | 107 ++++++++++++++++++++++++++++++++++++++++ index.js | 6 +++ package.json | 25 ++++++++++ 7 files changed, 223 insertions(+) create mode 100644 .gitignore create mode 100644 .npmignore create mode 100644 LICENSES create mode 100644 README.md create mode 100644 include/addon-tools.hpp create mode 100644 index.js create mode 100644 package.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0ff37a9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,12 @@ +.idea +.cproject,.project +.cproject +.project +.lock-wscript +build* +.DS_Store +Debug +node_modules +package-lock.json +bin_* +*.log diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..0ff37a9 --- /dev/null +++ b/.npmignore @@ -0,0 +1,12 @@ +.idea +.cproject,.project +.cproject +.project +.lock-wscript +build* +.DS_Store +Debug +node_modules +package-lock.json +bin_* +*.log diff --git a/LICENSES b/LICENSES new file mode 100644 index 0000000..5ad29e8 --- /dev/null +++ b/LICENSES @@ -0,0 +1,59 @@ +This document lists all the licenses used in this node-webgl repository: + +- Part I - node-webgl distributed under BSD license +- Part II - LightGL.js from Evan Wallace under MIT license + +No specific license found for: +- Some tests adapted from LearningWebGL.com lessons, themselves adapted from NeHe lessons. +- Travelling wavefront demo adapted from https://github.com/webos-commons/com.creationix.minimason webOS demo, itself adapted from the minimason nko2 demo. + +node-webgl depends on node-glfw, also under BSD license. + +------------------------------------------------------------------------------ +Part I - node-webgl distributed under BSD license + +Copyright (c) 2011-2012, Mikael Bourges-Sevenier +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +------------------------------------------------------------------------------ +Part II - LightGL.js from Evan Wallace under MIT license + +Copyright (C) 2011 by Evan Wallace + +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. diff --git a/README.md b/README.md new file mode 100644 index 0000000..445c2fa --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +# node-addon-tools +A set of extra macros for node addons, shipped as C++ header file. diff --git a/include/addon-tools.hpp b/include/addon-tools.hpp new file mode 100644 index 0000000..70e4301 --- /dev/null +++ b/include/addon-tools.hpp @@ -0,0 +1,107 @@ +#ifndef _COMMON_HPP_ +#define _COMMON_HPP_ + + +#include +#include +#include + + +#include + +#define JS_STR(...) Nan::New(__VA_ARGS__).ToLocalChecked() +#define JS_INT(val) Nan::New(val) +#define JS_NUM(val) Nan::New(val) +#define JS_BOOL(val) (val) ? Nan::True() : Nan::False() +#define JS_RETHROW(tc) v8::Local::New(tc.Exception()); + +#define REQ_ARGS(N) \ + if (info.Length() < (N)) \ + Nan::ThrowTypeError("Expected at least " #N " arguments"); + +#define REQ_STR_ARG(I, VAR) \ + if (info.Length() <= (I) || ! info[I]->IsString()) \ + Nan::ThrowTypeError("Argument " #I " must be a string"); \ + String::Utf8Value _v8_##VAR(info[I]->ToString()); \ + std::string _std_##VAR = std::string(*_v8_##VAR); \ + const char *VAR = _std_##VAR.c_str(); + +#define REQ_UTF8_ARG(I, VAR) \ + if (info.Length() <= (I) || ! info[I]->IsString()) \ + Nan::ThrowTypeError("Argument " #I " must be a string"); \ + String::Utf8Value VAR(info[I]); + +#define REQ_INT32_ARG(I, VAR) \ + if (info.Length() <= (I) || ! info[I]->IsInt32()) \ + Nan::ThrowTypeError("Argument " #I " must be an int32"); \ + int VAR = info[I]->Int32Value(); + +#define LET_INT32_ARG(I, VAR) \ + if ( ! (info[I]->IsNull() || info[I]->IsInt32()) ) \ + Nan::ThrowTypeError("Argument " #I " must be an int32 or null");\ + int VAR = info[I]->IsNull() ? 0 : info[I]->Int32Value(); + +#define REQ_BOOL_ARG(I, VAR) \ + if (info.Length() <= (I) || ! info[I]->IsBoolean()) \ + Nan::ThrowTypeError("Argument " #I " must be a bool"); \ + int VAR = info[I]->BooleanValue(); + +#define REQ_UINT32_ARG(I, VAR) \ + if (info.Length() <= (I) || ! info[I]->IsUint32()) \ + Nan::ThrowTypeError("Argument " #I " must be a uint32"); \ + unsigned int VAR = info[I]->Uint32Value(); + +#define USE_UINT32_ARG(I, VAR, DEF) \ + if ( ! (info[I]->IsNull() || info[I]->IsUint32()) ) \ + Nan::ThrowTypeError("Argument " #I " must be an uint32 or null");\ + unsigned int VAR = info[I]->IsNull() ? (DEF) : info[I]->Uint32Value(); + +#define LET_UINT32_ARG(I, VAR) \ + USE_UINT32_ARG(I, VAR, 0) + +#define REQ_INT_ARG(I, VAR) \ + if (info.Length() <= (I) || ! info[I]->IsNumber()) \ + Nan::ThrowTypeError("Argument " #I " must be a int"); \ + size_t VAR = static_cast(info[I]->IntegerValue()); + +#define REQ_DOUBLE_ARG(I, VAR) \ + if (info.Length() <= (I) || ! info[I]->IsNumber()) \ + Nan::ThrowTypeError("Argument " #I " must be a int"); \ + double VAR = static_cast(info[I]->NumberValue()); + +#define REQ_FLOAT_ARG(I, VAR) \ + if (info.Length() <= (I) || ! info[I]->IsNumber()) \ + Nan::ThrowTypeError("Argument " #I " must be a int"); \ + float VAR = static_cast(info[I]->NumberValue()); + +#define REQ_EXT_ARG(I, VAR) \ + if (info.Length() <= (I) || ! info[I]->IsExternal()) \ + Nan::ThrowTypeError("Argument " #I " invalid"); \ + Local VAR = Local::Cast(info[I]); + +#define REQ_FUN_ARG(I, VAR) \ + if (info.Length() <= (I) || ! info[I]->IsFunction()) \ + Nan::ThrowTypeError("Argument " #I " must be a function"); \ + Local VAR = Local::Cast(info[I]); + +#define REQ_OBJ_ARG(I, VAR) \ + if (info.Length() <= (I) || ! info[I]->IsObject()) \ + Nan::ThrowTypeError("Argument " #I " must be an object"); \ + Local VAR = Local::Cast(info[I]); + +#define REQ_ARRV_ARG(I, VAR) \ + REQ_OBJ_ARG(I, _obj_##VAR); \ + if( ! _obj_##VAR->IsArrayBufferView() ) \ + Nan::ThrowTypeError("Argument " #I " must be an array buffer"); \ + Local VAR = Local::Cast(_obj_##VAR); + +#define REQ_ERROR_THROW(error) \ + if (ret == error) \ + Nan::ThrowError(String::New(#error)); + +#define NAN_HS Nan::HandleScope scope; + +#define RET_VALUE(VAL) info.GetReturnValue().Set(VAL); +#define RET_UNDEFINED info.GetReturnValue().Set(Nan::Undefined()); + +#endif // _COMMON_HPP_ diff --git a/index.js b/index.js new file mode 100644 index 0000000..0ea604d --- /dev/null +++ b/index.js @@ -0,0 +1,6 @@ +'use strict'; + + +module.exports = { + root : __dirname, +}; diff --git a/package.json b/package.json new file mode 100644 index 0000000..ee63ab1 --- /dev/null +++ b/package.json @@ -0,0 +1,25 @@ +{ + "name": "node-addon-tools", + "author": "Luis Blanco ", + "description": "WebGL for nodejs", + "version": "0.0.1", + "main": "index.js", + "keywords": [ + "node", + "addon", + "header", + "include" + ], + "maintainers": [ + { + "name": "Luis Blanco", + "email": "raubtierxxx@gmail.com", + "skype": "rauber666" + } + ], + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/raub/node-addon-tools.git" + }, +}