3737// --------------------------------------------------------------
3838LuaScript::LuaScript () : PatchObject(" lua script" ){
3939
40- this ->numInlets = 1 ;
40+ this ->numInlets = 2 ;
4141 this ->numOutlets = 3 ;
4242
4343 _inletParams[0 ] = new vector<float >(); // data
4444
45+ _inletParams[1 ] = new string (); // string
46+ *static_cast <string *>(_inletParams[1 ]) = " " ;
47+
4548 _outletParams[0 ] = new ofTexture (); // output
4649 _outletParams[1 ] = new LiveCoding (); // lua script reference (for keyboard and mouse events on external windows)
4750 _outletParams[2 ] = new vector<float >(); // outlet vector from lua
@@ -62,8 +65,9 @@ LuaScript::LuaScript() : PatchObject("lua script"){
6265 output_width = STANDARD_TEXTURE_WIDTH;
6366 output_height = STANDARD_TEXTURE_HEIGHT;
6467
65- mosaicTableName = " _mosaic_data_inlet" ;
66- luaTablename = " _mosaic_data_outlet" ;
68+ mosaicTableName = " _mosaic_data_inlet" ;
69+ luaTablename = " _mosaic_data_outlet" ;
70+ mosaicStringName = " _mosaic_string_inlet" ;
6771 tempstring = " " ;
6872
6973 needToLoadScript= true ;
@@ -94,6 +98,7 @@ void LuaScript::newObject(){
9498 PatchObject::setName ( this ->objectName );
9599
96100 this ->addInlet (VP_LINK_ARRAY," data" );
101+ this ->addInlet (VP_LINK_STRING," string" );
97102
98103 this ->addOutlet (VP_LINK_TEXTURE," generatedTexture" );
99104 this ->addOutlet (VP_LINK_SPECIAL," mouseKeyboardInteractivity" );
@@ -210,6 +215,15 @@ void LuaScript::drawObjectContent(ofxFontStash *font, shared_ptr<ofBaseGLRendere
210215 }
211216
212217
218+ if (this ->inletsConnected [1 ]){
219+ string temp = mosaicStringName+" = '" ;
220+ temp.append (*static_cast <string *>(_inletParams[1 ]));
221+ temp.append (" '" );
222+ static_cast <LiveCoding *>(_outletParams[1 ])->lua .doString (temp);
223+ }else {
224+ string temp = mosaicStringName+" = ''" ;
225+ static_cast <LiveCoding *>(_outletParams[1 ])->lua .doString (temp);
226+ }
213227
214228 // send internal data
215229 size_t len = static_cast <LiveCoding *>(_outletParams[1 ])->lua .tableSize (luaTablename);
@@ -312,7 +326,7 @@ void LuaScript::drawObjectNodeGui( ImGuiEx::NodeCanvas& _nodeCanvas ){
312326 prevW = this ->width ;
313327 this ->setCustomVar (static_cast <float >(prevW)," WIDTH" );
314328 }
315- if (this ->width != prevH){
329+ if (this ->height != prevH){
316330 prevH = this ->height ;
317331 this ->setCustomVar (static_cast <float >(prevH)," HEIGHT" );
318332 }
@@ -472,6 +486,10 @@ void LuaScript::resetResolution(int fromID, int newWidth, int newHeight){
472486 tempstring = " USING_DATA_INLET = false" ;
473487 }
474488 static_cast <LiveCoding *>(_outletParams[1 ])->lua .doString (tempstring);
489+
490+ tempstring = mosaicStringName+" = ''" ;
491+ static_cast <LiveCoding *>(_outletParams[1 ])->lua .doString (tempstring);
492+
475493 ofFile tempFileScript (filepath);
476494 tempstring = " SCRIPT_PATH = '" +tempFileScript.getEnclosingDirectory ().substr (0 ,tempFileScript.getEnclosingDirectory ().size ()-1 )+" '" ;
477495 static_cast <LiveCoding *>(_outletParams[1 ])->lua .doString (tempstring);
@@ -555,6 +573,10 @@ void LuaScript::loadScript(string scriptFile){
555573 tempstring = " function _getLUAOutletTableAt(i) return " +luaTablename+" [i] end" ;
556574 static_cast <LiveCoding *>(_outletParams[1 ])->lua .doString (tempstring);
557575
576+ // inject incoming string
577+ tempstring = mosaicStringName+" = ''" ;
578+ static_cast <LiveCoding *>(_outletParams[1 ])->lua .doString (tempstring);
579+
558580 // set Mosaic scripting vars
559581 tempstring = " OUTPUT_WIDTH = " +ofToString (output_width);
560582 static_cast <LiveCoding *>(_outletParams[1 ])->lua .doString (tempstring);
@@ -623,6 +645,10 @@ void LuaScript::clearScript(){
623645 tempstring = " function _getLUAOutletTableAt(i) return " +luaTablename+" [i] end" ;
624646 static_cast <LiveCoding *>(_outletParams[1 ])->lua .doString (tempstring);
625647
648+ // inject incoming string
649+ tempstring = mosaicStringName+" = ''" ;
650+ static_cast <LiveCoding *>(_outletParams[1 ])->lua .doString (tempstring);
651+
626652 // set Mosaic scripting vars
627653 tempstring = " OUTPUT_WIDTH = " +ofToString (output_width);
628654 static_cast <LiveCoding *>(_outletParams[1 ])->lua .doString (tempstring);
0 commit comments