From e545199fa6b6739ce68bb150ea5fbe84ea7d1add Mon Sep 17 00:00:00 2001 From: Jonathan Brodsky Date: Mon, 18 Nov 2013 06:10:23 -0800 Subject: [PATCH] cleaned out some incorrect return values. some are still hiding --- addon_config.mk | 80 ++++++++++ {src => ios_src}/bludAsyncCurl.h | 0 {src => ios_src}/bludAsyncCurl.mm | 0 {src => ios_src}/bludVideoPlayer.h | 0 {src => ios_src}/bludVideoPlayer.mm | 0 {src => ios_src}/bludWebview.h | 0 {src => ios_src}/bludWebview.mm | 0 src/bludAudioSync.h | 6 +- src/bludGraphics.cpp | 11 +- src/bludGraphics.h | 39 ++++- src/bludLock.cpp | 6 +- src/bludShapeBatch.cpp | 12 -- src/bludShapeBatch.h | 80 ---------- src/bludSpriteSheet.cpp | 10 +- src/bludSpriteSheet.h | 32 ++-- src/lunar.h | 224 ++++++++++++++++++++++++++++ src/ofxBlud.h | 2 +- src/ofxBlud.h~ | 64 ++++++++ 18 files changed, 435 insertions(+), 131 deletions(-) create mode 100644 addon_config.mk rename {src => ios_src}/bludAsyncCurl.h (100%) rename {src => ios_src}/bludAsyncCurl.mm (100%) rename {src => ios_src}/bludVideoPlayer.h (100%) rename {src => ios_src}/bludVideoPlayer.mm (100%) rename {src => ios_src}/bludWebview.h (100%) rename {src => ios_src}/bludWebview.mm (100%) delete mode 100644 src/bludShapeBatch.cpp delete mode 100644 src/bludShapeBatch.h create mode 100644 src/lunar.h create mode 100644 src/ofxBlud.h~ diff --git a/addon_config.mk b/addon_config.mk new file mode 100644 index 0000000..480e953 --- /dev/null +++ b/addon_config.mk @@ -0,0 +1,80 @@ +# All variables and this file are optional, if they are not present the PG and the +# makefiles will try to parse the correct values from the file system. +# +# Variables that specify exclusions can use % as a wildcard to specify that anything in +# that position will match. A partial path can also be specified to, for example, exclude +# a whole folder from the parsed paths from the file system +# +# Variables can be specified using = or += +# = will clear the contents of that variable both specified from the file or the ones parsed +# from the file system +# += will add the values to the previous ones in the file or the ones parsed from the file +# system +# +# The PG can be used to detect errors in this file, just create a new project with this addon +# and the PG will write to the console the kind of error and in which line it is + +meta: + ADDON_NAME = ofxBlud + ADDON_DESCRIPTION = various chunks of lua wrappers + ADDON_AUTHOR = Jonathan Brodsky + ADDON_TAGS = "lua" "scripting" + ADDON_URL = http://github.com/jonbro/ofxBlud + +common: + # dependencies with other addons, a list of them separated by spaces + # or use += in several lines + ADDON_DEPENDENCIES = ofxSpriteSheetRenderer ofxDspChain + + # include search paths, this will be usually parsed from the file system + # but if the addon or addon libraries need special search paths they can be + # specified here separated by spaces or one per line using += + # ADDON_INCLUDES = + + # any special flag that should be passed to the compiler when using this + # addon + # ADDON_CFLAGS = + + # any special flag that should be passed to the linker when using this + # addon, also used for system libraries with -lname + # ADDON_LDFLAGS = + + # linux only, any library that should be included in the project using + # pkg-config + # ADDON_PKG_CONFIG_LIBRARIES = + + # osx/iOS only, any framework that should be included in the project + # ADDON_FRAMEWORKS = + + # source files, these will be usually parsed from the file system looking + # in the src folders in libs and the root of the addon. if your addon needs + # to include files in different places or a different set of files per platform + # they can be specified here + # ADDON_SOURCES = + + # some addons need resources to be copied to the bin/data folder of the project + # specify here any files that need to be copied, you can use wildcards like * and ? + # ADDON_DATA = + + # when parsing the file system looking for libraries exclude this for all or + # a specific platform + # ADDON_LIBS_EXCLUDE = + + # when parsing the file system looking for sources exclude this for all or + # a specific platform + # ADDON_SOURCES_EXCLUDE = + + # when parsing the file system looking for include paths exclude this for all or + # a specific platform + # ADDON_INCLUDES_EXCLUDE = + +win_cb: + # when parsing the file system looking for sources exclude this for all or + # a specific platform + # ADDON_SOURCES_EXCLUDE = + + # when parsing the file system looking for include paths exclude this for all or + # a specific platform + # ADDON_INCLUDES_EXCLUDE = +ios: + ADDON_SOURCES = ios_src diff --git a/src/bludAsyncCurl.h b/ios_src/bludAsyncCurl.h similarity index 100% rename from src/bludAsyncCurl.h rename to ios_src/bludAsyncCurl.h diff --git a/src/bludAsyncCurl.mm b/ios_src/bludAsyncCurl.mm similarity index 100% rename from src/bludAsyncCurl.mm rename to ios_src/bludAsyncCurl.mm diff --git a/src/bludVideoPlayer.h b/ios_src/bludVideoPlayer.h similarity index 100% rename from src/bludVideoPlayer.h rename to ios_src/bludVideoPlayer.h diff --git a/src/bludVideoPlayer.mm b/ios_src/bludVideoPlayer.mm similarity index 100% rename from src/bludVideoPlayer.mm rename to ios_src/bludVideoPlayer.mm diff --git a/src/bludWebview.h b/ios_src/bludWebview.h similarity index 100% rename from src/bludWebview.h rename to ios_src/bludWebview.h diff --git a/src/bludWebview.mm b/ios_src/bludWebview.mm similarity index 100% rename from src/bludWebview.mm rename to ios_src/bludWebview.mm diff --git a/src/bludAudioSync.h b/src/bludAudioSync.h index 363cd45..59a1dc8 100644 --- a/src/bludAudioSync.h +++ b/src/bludAudioSync.h @@ -3,7 +3,7 @@ #include "lunar.h" #include "ofSoundUnit.h" #include "bludMixer.h" -#include "bludlock.h" +#include "bludLock.h" #include "ofTypes.h" /** @@ -37,7 +37,7 @@ class bludSyncContainer : public ofSoundSource { callback = c; } }; - vector triggers; + vector triggers; int counter; lua_State *L; ofMutex *mutex; @@ -45,7 +45,7 @@ class bludSyncContainer : public ofSoundSource { /** * interface to do sample accurate audio timing - * + * * allows for a callback to be called with sample accurate timing * don't exactly know how to manage the thread safety of this... tdb */ diff --git a/src/bludGraphics.cpp b/src/bludGraphics.cpp index 107702a..a2d4ff2 100644 --- a/src/bludGraphics.cpp +++ b/src/bludGraphics.cpp @@ -1,7 +1,9 @@ #include "bludGraphics.h" const char bludGraphics::className[] = "bludGraphics"; - +int bludGraphics::width = 800; +int bludGraphics::height = 600; +bool bludGraphics::needsFixRes = false; Lunar::RegType bludGraphics::methods[] = { method(bludGraphics, push), method(bludGraphics, pop), @@ -10,7 +12,7 @@ Lunar::RegType bludGraphics::methods[] = { method(bludGraphics, scale), method(bludGraphics, setColor), method(bludGraphics, setBackground), - method(bludGraphics, setFrameRate), + method(bludGraphics, setFrameRate), method(bludGraphics, drawRect), method(bludGraphics, drawCircle), method(bludGraphics, clear), @@ -22,5 +24,8 @@ Lunar::RegType bludGraphics::methods[] = { method(bludGraphics, noise), method(bludGraphics, openURL), method(bludGraphics, eraseMode), + method(bludGraphics, setWindowShape), + method(bludGraphics, setFullscreen), + method(bludGraphics, exit), {0,0} -}; \ No newline at end of file +}; diff --git a/src/bludGraphics.h b/src/bludGraphics.h index 829bb6e..476510e 100644 --- a/src/bludGraphics.h +++ b/src/bludGraphics.h @@ -5,13 +5,16 @@ #include "ofUtils.h" #include "ofAppRunner.h" #include "lunar.h" +#include "bludLock.h" class bludGraphics { public: static const char className[]; static Lunar::RegType methods[]; + static bool needsFixRes; + static int width; + static int height; bludGraphics(lua_State *L) {} - int push (lua_State *L) {ofPushMatrix(); return 1;} int pop(lua_State *L) {ofPopMatrix(); return 1;} @@ -37,7 +40,7 @@ class bludGraphics { case 5: mode = OF_BLENDMODE_SCREEN; break; - + default: mode = OF_BLENDMODE_DISABLED; break; @@ -49,7 +52,7 @@ class bludGraphics { int alpha = 255; if (lua_isnumber(L, 4)) { alpha = luaL_checknumber(L, 4); - } + } ofSetColor(luaL_checknumber(L, 1), luaL_checknumber(L, 2), luaL_checknumber(L, 3), alpha); return 1; } @@ -80,21 +83,41 @@ class bludGraphics { } return 1; } + int setWindowShape(lua_State *L){ + int w = luaL_checkinteger(L, 1); + int h = luaL_checkinteger(L, 2); + ofSetWindowShape(w, h); + +// width = luaL_checknumber(L, 1); +// height = luaL_checknumber(L, 2); +// needsFixRes = true; + return 0; + } + int setFullscreen(lua_State *L){ + ofSetFullscreen(lua_toboolean(L, 1)); + return 0; + } + int exit(lua_State *L){ + // release the mutex and + bludLock::getInstance()->unlock(); + ofExit(); + return 0; + } int openURL(lua_State *L){ -// [[UIApplication sharedApplication] openURL:[NSURL URLWithString: [[[[NSString alloc] initWithCString:luaL_checkstring(L, 1)] stringByAddingPercentEscapesUsingEncoding: NSASCIIStringEncoding] autorelease]]]; - return 1; + ofLaunchBrowser(luaL_checkstring(L, 1)); + return 0; } int eraseMode(lua_State *L){ #if defined TARGET_OF_IPHONE glBlendFuncSeparateOES(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA,GL_ONE,GL_SRC_ALPHA); #endif - return 1; + return 0; } int enableAlpha(lua_State *L){ #if defined TARGET_OF_IPHONE glBlendFuncSeparateOES(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA,GL_ONE,GL_ONE_MINUS_SRC_ALPHA); #endif - return 1; + return 0; } ~bludGraphics() {} -}; \ No newline at end of file +}; diff --git a/src/bludLock.cpp b/src/bludLock.cpp index 635629c..9e7e209 100644 --- a/src/bludLock.cpp +++ b/src/bludLock.cpp @@ -8,12 +8,12 @@ */ -#include "bludlock.h" +#include "bludLock.h" -ofMutex* bludLock::instance = NULL; +ofMutex* bludLock::instance = NULL; ofMutex* bludLock::getInstance(){ if (!instance) // Only allow one instance of class to be generated. instance = new ofMutex(); return instance; -} \ No newline at end of file +} diff --git a/src/bludShapeBatch.cpp b/src/bludShapeBatch.cpp deleted file mode 100644 index b5fcc75..0000000 --- a/src/bludShapeBatch.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include "bludShapeBatch.h" - -const char bludShapeBatch::className[] = "bludShapeBatch"; - -Lunar::RegType bludShapeBatch::methods[] = { - method(bludShapeBatch, addRect), - method(bludShapeBatch, addCircle), - method(bludShapeBatch, draw), - method(bludShapeBatch, clear), - method(bludShapeBatch, setColor), - {0,0} -}; diff --git a/src/bludShapeBatch.h b/src/bludShapeBatch.h deleted file mode 100644 index ff47b9e..0000000 --- a/src/bludShapeBatch.h +++ /dev/null @@ -1,80 +0,0 @@ -/* batch shape render wrapper */ - -#pragma once -#include "ofxShapeBatchRenderer.h" -#include "lunar.h" - -class bludShapeBatch{ -public: - static const char className[]; - static Lunar::RegType methods[]; - ofxShapeBatchRenderer *batch; - bludShapeBatch(lua_State *L) { - - int perLayer = 1000; - if (lua_isnumber(L, 1)) { - perLayer = luaL_checknumber(L, 1); - } - - int layers = 10; - if (lua_isnumber(L, 2)) { - layers = luaL_checknumber(L, 2); - } - - // TODO: allow for different settings to be passed in - batch = new ofxShapeBatchRenderer(SBR_TRIANGLE, perLayer, layers); - } - int addRect(lua_State *L){ - int layer = 0; - if (lua_isnumber(L, 6)) { - layer = luaL_checknumber(L, 6); - } - - batch->addRect(luaL_checknumber(L, 1), luaL_checknumber(L, 2), luaL_checknumber(L, 3), luaL_checknumber(L, 4), luaL_checknumber(L, 5), layer); - return 1; - } - int addCircle(lua_State *L){ - int layer = 0; - if (lua_isnumber(L, 5)) { - layer = luaL_checknumber(L, 5); - } - batch->addCircle(luaL_checknumber(L, 1), luaL_checknumber(L, 2), luaL_checknumber(L, 3), luaL_checknumber(L, 4), layer); - return 1; - } - int draw(lua_State *L){ - batch->draw(); - return 1; - } - int clear(lua_State *L){ - batch->clear(); - return 1; - } - int setColor(lua_State *L){ - int alpha = 255; - if (lua_isnumber(L, 4)) { - alpha = luaL_checknumber(L, 4); - } - batch->setColor(luaL_checknumber(L, 1), luaL_checknumber(L, 2), luaL_checknumber(L, 3), alpha); - return 1; - } - ~bludShapeBatch() { - delete batch; - printf("deleted shape batch (%p)\n", this); - } -}; - - -/* - bool addCircle(float x, float y, float z, float radius, int layer=DEFAULT_LAYER); - bool addElipse(float x, float y, float z, float w, float h, int layer=DEFAULT_LAYER); - - bool addRect(float x, float y, float z, float w, float h, int layer=DEFAULT_LAYER); - bool addCenteredRect(float x, float y, float z, float w, float h, int layer=DEFAULT_LAYER); - - //functional -- - void draw(); - void clear(); - - //features -- - void setColor(int r, int g, int b, int a=255); -*/ \ No newline at end of file diff --git a/src/bludSpriteSheet.cpp b/src/bludSpriteSheet.cpp index 314c73d..bcfc3a2 100644 --- a/src/bludSpriteSheet.cpp +++ b/src/bludSpriteSheet.cpp @@ -60,15 +60,15 @@ int bludSpriteSheet::loadTexture(lua_State *L){ if (lua_isnumber(L, 3)) { height = luaL_checknumber(L, 3); } - cout << "loading texture bludspritesheet" << endl; + cout << "loading texture bludspritesheet: " << luaL_checkstring(L, 1) << endl; texture->loadTexture(luaL_checkstring(L, 1)); - cout << "after loading" << endl; spriteRenderer->loadTexture(texture); - return 1; + cout << "after loading" << endl; + return 0; } int bludSpriteSheet::setupTexture(lua_State *L){ - spriteRenderer->loadTexture(texture); - return 1; + //spriteRenderer->loadTexture(texture); + return 0; } int bludSpriteSheet::addTile(lua_State *L) { // need to pull out the user data that was passed in on the first parameter diff --git a/src/bludSpriteSheet.h b/src/bludSpriteSheet.h index 7ed2fec..3eacdf9 100644 --- a/src/bludSpriteSheet.h +++ b/src/bludSpriteSheet.h @@ -23,17 +23,17 @@ class bludSprite { ani.loops = -1; ani.final_index = -1; ani.frame_skip = 1; - + ani.tex_y = 0; // how much offset from the top left of the sheet the texture is (no longer using the index for lookups) ani.tex_x = 0; // doing it this way so that we can have differently sized textures ani.tex_w = 0; // how big the texture is (on the sheet) ani.tex_h = 0; - + ani.sprite_x = 0; // how far offset the display of the sprite should be from the requested display position (how much alpha got trimmed when packing the sprite) ani.sprite_y = 0; ani.spritesource_w = 0; // the size of the sprite before the alpha trimming took place - ani.spritesource_h = 0; // used for doing rotations around the center of the sprite (maybe, used for nothing for now) - + ani.spritesource_h = 0; // used for doing rotations around the center of the sprite (maybe, used for nothing for now) + } // I think I need a copy constructor bludSprite(bludSprite &other){ @@ -135,11 +135,11 @@ class bludSprite { /// spriteSheet renderer. Only partially implemented class bludSpriteSheet { - + public: static const char className[]; static Lunar::RegType methods[]; - + bludSpriteSheet(lua_State *L); int loadTexture(lua_State *L); int setupTexture(lua_State *L); @@ -153,19 +153,19 @@ class bludSpriteSheet { } int setBlendMode(lua_State *L) { blendMode = luaL_checknumber(L, 1); - return 1; + return 0; } int clear(lua_State *L) { spriteRenderer->clear(); - return 1; + return 0; } int update(lua_State *L) { spriteRenderer->update(luaL_checknumber(L, 1)); - return 1; + return 0; } int draw(lua_State *L) { // spriteRenderer->draw(); - return 1; + return 0; } // TODO: extend this to support all of the different features (rotation, tinting, etc) int addCenteredTile(lua_State *L) { @@ -178,7 +178,7 @@ class bludSpriteSheet { if (lua_isnumber(L, 4)) { layer = luaL_checknumber(L, 4); } - + int flipDir = 0; if (lua_isnumber(L, 5)) { flipDir = luaL_checknumber(L, 5); @@ -204,7 +204,7 @@ class bludSpriteSheet { if (lua_isnumber(L, 10)) { alpha = luaL_checknumber(L, 10); } - + spriteRenderer->addCenteredTile(&s->ani, x, y, layer, (flipDirection)flipDir, scale, r, g, b, alpha); return 1; } @@ -213,17 +213,17 @@ class bludSpriteSheet { bludSprite *s = Lunar::check(L, 1); float x = luaL_checknumber(L, 2); float y = luaL_checknumber(L, 3); - + float layer = -1; if (lua_isnumber(L, 4)) { layer = luaL_checknumber(L, 4); } - + int flipDir = 0; if (lua_isnumber(L, 5)) { flipDir = luaL_checknumber(L, 5); } - + float scale = 1; if (lua_isnumber(L, 6)) { scale = luaL_checknumber(L, 6); @@ -262,7 +262,7 @@ class bludSpriteSheet { if (lua_isnumber(L,11)) { flipDir = luaL_checknumber(L,11); } - + int r = 255; if (lua_isnumber(L, 12)) { r = luaL_checknumber(L, 12); diff --git a/src/lunar.h b/src/lunar.h new file mode 100644 index 0000000..24d5849 --- /dev/null +++ b/src/lunar.h @@ -0,0 +1,224 @@ +#pragma once +#ifdef check +#undef check +#endif + +extern "C" { +#include "lua.h" +#include "lauxlib.h" +} + +template class Lunar { + typedef struct { T *pT; } userdataType; +public: + typedef int (T::*mfp)(lua_State *L); + typedef struct { const char *name; mfp mfunc; } RegType; + + static void Register(lua_State *L) { + lua_newtable(L); + int methods = lua_gettop(L); + + luaL_newmetatable(L, T::className); + int metatable = lua_gettop(L); + + // store method table in globals so that + // scripts can add functions written in Lua. + lua_pushvalue(L, methods); + set(L, LUA_GLOBALSINDEX, T::className); + + // hide metatable from Lua getmetatable() + lua_pushvalue(L, methods); + set(L, metatable, "__metatable"); + + lua_pushvalue(L, methods); + set(L, metatable, "__index"); + + lua_pushcfunction(L, tostring_T); + set(L, metatable, "__tostring"); + + lua_pushcfunction(L, gc_T); + set(L, metatable, "__gc"); + + ///////adding this should work + lua_pushvalue(L, methods); + set(L, metatable, "__newindex"); + ////////// + + lua_newtable(L); // mt for method table + lua_pushcfunction(L, new_T); + lua_pushvalue(L, -1); // dup new_T function + set(L, methods, "new"); // add new_T to method table + set(L, -3, "__call"); // mt.__call = new_T + lua_setmetatable(L, methods); + + // fill method table with methods from class T + for (RegType *l = T::methods; l->name; l++) { + lua_pushstring(L, l->name); + lua_pushlightuserdata(L, (void*)l); + lua_pushcclosure(L, thunk, 1); + lua_settable(L, methods); + } + + lua_pop(L, 2); // drop metatable and method table + } + + // call named lua method from userdata method table + static int call(lua_State *L, const char *method, + int nargs=0, int nresults=LUA_MULTRET, int errfunc=0) + { + int base = lua_gettop(L) - nargs; // userdata index + if (!luaL_checkudata(L, base, T::className)) { + lua_settop(L, base-1); // drop userdata and args + lua_pushfstring(L, "not a valid %s userdata", T::className); + return -1; + } + + lua_pushstring(L, method); // method name + lua_gettable(L, base); // get method from userdata + if (lua_isnil(L, -1)) { // no method? + lua_settop(L, base-1); // drop userdata and args + lua_pushfstring(L, "%s missing method '%s'", T::className, method); + return -1; + } + lua_insert(L, base); // put method under userdata, args + + int status = lua_pcall(L, 1+nargs, nresults, errfunc); // call method + if (status) { + const char *msg = lua_tostring(L, -1); + if (msg == NULL) msg = "(error with no message)"; + lua_pushfstring(L, "%s:%s status = %d\n%s", + T::className, method, status, msg); + lua_remove(L, base); // remove old message + return -1; + } + return lua_gettop(L) - base + 1; // number of results + } + + // push onto the Lua stack a userdata containing a pointer to T object + static int push(lua_State *L, T *obj, bool gc=false) { + if (!obj) { lua_pushnil(L); return 0; } + luaL_getmetatable(L, T::className); // lookup metatable in Lua registry + if (lua_isnil(L, -1)) luaL_error(L, "%s missing metatable", T::className); + int mt = lua_gettop(L); + subtable(L, mt, "userdata", "v"); + userdataType *ud = + static_cast(pushuserdata(L, obj, sizeof(userdataType))); + if (ud) { + ud->pT = obj; // store pointer to object in userdata + lua_pushvalue(L, mt); + lua_setmetatable(L, -2); + if (gc == false) { + lua_checkstack(L, 3); + subtable(L, mt, "do not trash", "k"); + lua_pushvalue(L, -2); + lua_pushboolean(L, 1); + lua_settable(L, -3); + lua_pop(L, 1); + } + } + lua_replace(L, mt); + lua_settop(L, mt); + return mt; // index of userdata containing pointer to T object + } + + // get userdata from Lua stack and return pointer to T object + static T *check(lua_State *L, int narg) { + userdataType *ud = + static_cast(luaL_checkudata(L, narg, T::className)); + if(!ud) { + luaL_typerror(L, narg, T::className); + return NULL; + } + return ud->pT; // pointer to T object + } + +private: + Lunar(); // hide default constructor + + // member function dispatcher + static int thunk(lua_State *L) { + // stack has userdata, followed by method args + T *obj = check(L, 1); // get 'self', or if you prefer, 'this' + lua_remove(L, 1); // remove self so member function args start at index 1 + // get member function from upvalue + RegType *l = static_cast(lua_touserdata(L, lua_upvalueindex(1))); + return (obj->*(l->mfunc))(L); // call member function + } + + // create a new T object and + // push onto the Lua stack a userdata containing a pointer to T object + static int new_T(lua_State *L) { + lua_remove(L, 1); // use classname:new(), instead of classname.new() + T *obj = new T(L); // call constructor for T objects + push(L, obj, true); // gc_T will delete this object + return 1; // userdata containing pointer to T object + } + + // garbage collection metamethod + static int gc_T(lua_State *L) { + if (luaL_getmetafield(L, 1, "do not trash")) { + lua_pushvalue(L, 1); // dup userdata + lua_gettable(L, -2); + if (!lua_isnil(L, -1)) return 0; // do not delete object + } + userdataType *ud = static_cast(lua_touserdata(L, 1)); + T *obj = ud->pT; + if (obj) delete obj; // call destructor for T objects + return 0; + } + + static int tostring_T (lua_State *L) { + char buff[32]; + userdataType *ud = static_cast(lua_touserdata(L, 1)); + T *obj = ud->pT; + sprintf(buff, "%p", (void*)obj); + lua_pushfstring(L, "%s (%s)", T::className, buff); + + return 1; + } + + static void set(lua_State *L, int table_index, const char *key) { + lua_pushstring(L, key); + lua_insert(L, -2); // swap value and key + lua_settable(L, table_index); + } + + static void weaktable(lua_State *L, const char *mode) { + lua_newtable(L); + lua_pushvalue(L, -1); // table is its own metatable + lua_setmetatable(L, -2); + lua_pushliteral(L, "__mode"); + lua_pushstring(L, mode); + lua_settable(L, -3); // metatable.__mode = mode + } + + static void subtable(lua_State *L, int tindex, const char *name, const char *mode) { + lua_pushstring(L, name); + lua_gettable(L, tindex); + if (lua_isnil(L, -1)) { + lua_pop(L, 1); + lua_checkstack(L, 3); + weaktable(L, mode); + lua_pushstring(L, name); + lua_pushvalue(L, -2); + lua_settable(L, tindex); + } + } + + static void *pushuserdata(lua_State *L, void *key, size_t sz) { + void *ud = 0; + lua_pushlightuserdata(L, key); + lua_gettable(L, -2); // lookup[key] + if (lua_isnil(L, -1)) { + lua_pop(L, 1); // drop nil + lua_checkstack(L, 3); + ud = lua_newuserdata(L, sz); // create new userdata + lua_pushlightuserdata(L, key); + lua_pushvalue(L, -2); // dup userdata + lua_settable(L, -4); // lookup[key] = userdata + } + return ud; + } +}; + +#define method(class, name) {#name, &class::name} \ No newline at end of file diff --git a/src/ofxBlud.h b/src/ofxBlud.h index 50129b5..0188073 100644 --- a/src/ofxBlud.h +++ b/src/ofxBlud.h @@ -8,7 +8,7 @@ #include "ofLog.h" #include "ofUtils.h" #include "ofEvents.h" -#include "bludlock.h" +#include "bludLock.h" #include "bludRenderInstance.h" #include "tinyxml.h" #include "bludImage.h" diff --git a/src/ofxBlud.h~ b/src/ofxBlud.h~ new file mode 100644 index 0000000..50129b5 --- /dev/null +++ b/src/ofxBlud.h~ @@ -0,0 +1,64 @@ +#pragma once + +// bring in the lua stuff +#include "lua.hpp" +#include "lunar.h" + +// bring in the required OF stuff +#include "ofLog.h" +#include "ofUtils.h" +#include "ofEvents.h" +#include "bludlock.h" +#include "bludRenderInstance.h" +#include "tinyxml.h" +#include "bludImage.h" +#include "bludGraphics.h" +#include "bludSpriteSheet.h" +#include "bludFont.h" +#include "bludLine.h" +#include "bhComponentManager.h" + +int luaErrorHandler(lua_State *L); + +class ofxBlud{ + public: + void setup(); + void draw(ofEventArgs &e); + void draw(); + void update(ofEventArgs &e); + void update(); + void exit(ofEventArgs &e); + + std::string execute(std::string code); // returns an error if there is one + std::string executeFile(std::string filename); // executes a file, returns error if there is one + + // event callbacks + void keyPressed(ofKeyEventArgs &e); + void keyReleased(ofKeyEventArgs &e); + + void mousePressed(ofMouseEventArgs &e); + void mouseMoved(ofMouseEventArgs &e); + void mouseDragged(ofMouseEventArgs &e); + void mouseReleased(ofMouseEventArgs &e); + + void touchDown(ofTouchEventArgs &e); + void touchMoved(ofTouchEventArgs &e); + void touchUp(ofTouchEventArgs &e); + void touchDoubleTap(ofTouchEventArgs &e); + + void audioRequested(ofAudioEventArgs &e); + lua_State* luaVM; + bludRenderSingleton *renderer; + static const char *blud_boot; + private: + ofMutex *mutex; + ofMesh mesh; + ofFbo *fbo; + ofTexture texScreen; + ofColor feedbackColor; + int errorHandle; +}; + +void RegisterLuaXML (lua_State *L); +static int LuaXML_ParseFile (lua_State *L); +static int LuaXML_ParseString (lua_State *L);