Home Tutorials Download Beta Store Forum Documentation KnowledgeBase Wiki Blog

ShiVa3D

Return to Plugins

How to get data returned from C/C++ from shiva3d script

ShiVa Plugin Development

How to get data returned from C/C++ from shiva3d script

Postby dddu88 » 29 Dec 2011, 05:12

Hi, all,

I have a C plugin called MyPlugin with the function MyFunctionOne as in cpp:

Code: Select all
int Callback_APIPackName_MyFunctionOne ( int _iInCount, const S3DX::AIVariable *_pIn, S3DX::AIVariable *_pOut )
{
    S3DX_API_PROFILING_START( "APIPackName.MyFunctionOne" ) ;

    // Input Parameters
    int iInputCount = 0 ;
    S3DX::AIVariable nParm1 = ( iInputCount < _iInCount ) ? _pIn[iInputCount++] : S3DX::AIVariable ( ) ;
    S3DX::AIVariable nParm2 = ( iInputCount < _iInCount ) ? _pIn[iInputCount++] : S3DX::AIVariable ( ) ;

    // Output Parameters
    S3DX::AIVariable nCount ;
    S3DX::AIVariable sStr ;


//#   pragma TODO( write the code for nCount, sStr = APIPackName.MyFunctionOne ( nParm1, nParm2 ) )
   nCount = 10;
   sStr = nParm1+nParm2;

    // Return output Parameters
    int iReturnCount = 0 ;
    _pOut[iReturnCount++] = nCount ;
    _pOut[iReturnCount++] = sStr ;

    S3DX_API_PROFILING_STOP( ) ;
    return iReturnCount;
}


Now how can I retrieve the two values of _pOut, which contains nCount and sStr from shiva3d script?

I did this:
Code: Select all
local val = APIPackName.MyFunctionOne("day", "hi")
    log.message ("returned value from cpp:", val )


I only got 12 back for nCount, I am not sure how to get the sStr?

Thanks

Dave
dddu88
Fresh Boarder
Fresh Boarder
 
Posts: 5

Re: How to get data returned from C/C++ from shiva3d script

Postby dddu88 » 13 Jan 2012, 14:27

Hi, all,

Anybody has an idea about the answer? I have been googling around, still could not get an answer, if somebody happens to know, please share with me.

Thanks
Dave
dddu88
Fresh Boarder
Fresh Boarder
 
Posts: 5

Re: How to get data returned from C/C++ from shiva3d script

Postby dreamora » 13 Jan 2012, 14:40

instead of local val, you need to write local val, name = xxxx then the two variables are fed in it.
I'm no stonetrip representative, just a happy board member like you :)

If you find my portfolio interesting, feel free to contact me or follow my shares on my twitter stream or my game development blog
User avatar
dreamora
Platinum Boarder
Platinum Boarder
 
Posts: 844

Re: How to get data returned from C/C++ from shiva3d script

Postby dddu88 » 14 Jan 2012, 02:23

Oh, got you, interesting, then what happen if the returned is an array of strings? which is either very long or you do not know the array size?

Thanks very much.

Dave
dddu88
Fresh Boarder
Fresh Boarder
 
Posts: 5

Re: How to get data returned from C/C++ from shiva3d script

Postby dreamora » 14 Jan 2012, 10:10

you can't return arrays as such its no problem (StoneScript does not support LUA tables)
Also don't forget that you specify the number of parameters returned, that will define it on both ends.
I'm no stonetrip representative, just a happy board member like you :)

If you find my portfolio interesting, feel free to contact me or follow my shares on my twitter stream or my game development blog
User avatar
dreamora
Platinum Boarder
Platinum Boarder
 
Posts: 844

Re: How to get data returned from C/C++ from shiva3d script

Postby NiCoX » 14 Jan 2012, 10:28

You can also create a ShiVa table (which is not a Lua table), add the strings, and return it:

Code: Select all
S3DX::AIVariable tStrings = S3DX::table.newInstance ( ) ;

S3DX::table.add ( tStrings, "foo" ) ;
S3DX::table.add ( tStrings, "bar" ) ;
S3DX::table.add ( tStrings, "gee" ) ;

_pOut[iReturnCount++] = tStrings ;


From the script, you can then retrieve the values using the table API.

(no need to release/destroy the created table, it will be done automatically by the engine/runtime).
User avatar
NiCoX
Platinum Boarder
Platinum Boarder
 
Posts: 5644
Location: France

Re: How to get data returned from C/C++ from shiva3d script

Postby dreamora » 14 Jan 2012, 13:52

I tend to forget about these tables. But I assume the old limitations of the StoneScript side on what datatypes you can store in also hold for the C++ side right? you can only put in the 'basic types' or the memory management will destroy them at the end of the frame
I'm no stonetrip representative, just a happy board member like you :)

If you find my portfolio interesting, feel free to contact me or follow my shares on my twitter stream or my game development blog
User avatar
dreamora
Platinum Boarder
Platinum Boarder
 
Posts: 844

Re: How to get data returned from C/C++ from shiva3d script

Postby NiCoX » 14 Jan 2012, 15:14

Indeed. We have written a more generic AI variable management for the 2.0 editor kernel, with true reference counting, serialization, etc. but still have to make similar changes for the engine kernel.
User avatar
NiCoX
Platinum Boarder
Platinum Boarder
 
Posts: 5644
Location: France

Re: How to get data returned from C/C++ from shiva3d script

Postby dreamora » 14 Jan 2012, 18:14

That sounds great :)
Really looking forward to that to store more complex, nested data objects without trashing the RAM with XML intermediates
I'm no stonetrip representative, just a happy board member like you :)

If you find my portfolio interesting, feel free to contact me or follow my shares on my twitter stream or my game development blog
User avatar
dreamora
Platinum Boarder
Platinum Boarder
 
Posts: 844


Return to Plugins