| External Operator Demo Sample Code
void CallbackDemo( void )
{
char theExpression[ 128 ];
long expLength;
bool keepLooping = true;
LZObjectHandle hCurrentContext = 0;
bool bSetContextResult = false;
long lDefineOpResult = 0;
bool bIsSymbol = false;
bool bIsOp = false;
bool bIsVar = false;
lzCreatePublicContext( "CallbackDemo" );
hCurrentContext = lzSetContext( "CallbackDemo", false );
if ( !hCurrentContext )
{
cout << "Failed to set Elzed context.\r\n";
cout << lzGetLastErrorText() << "\r\n\n";
}
lDefineOpResult = lzLinkCallbackOp( kGlobalScope, // scope
"xfunc", // operator name
"prefix", // operator type
"boolean", // return type
"number first, string second, boolean third", // parm list
"/", // precedence matching operator
MyExternalFunction ); // function pointer
lDefineOpResult = lzLinkCallbackOp( kGlobalScope, // scope
"yfunc", // operator name
"prefix", // operator type
"number", // return type
"number first, number second", // variable parm list
"^", // precedence matching operator
MyOtherExternalFunction ); // function pointer
lDefineOpResult = lzDefineExpOp( kGlobalScope, // scope
"zfunc", // operator name
"prefix", // operator type
"number", // return type
"number first, number second", // parm list
"/", // precedence matching operator
"first^second" ); // expression
if ( lDefineOpResult )
{
cout << "Failed to load external operator.\r\n";
cout << lzGetLastErrorText() << "\r\n\n";
}
bIsSymbol = lzIsSymbol( kAnyScope, "+" );
bIsSymbol = lzIsSymbol( kCosmicScope, "zfunc" );
bIsSymbol = lzIsSymbol( kGlobalScope, "zfunc" );
bIsSymbol = lzIsSymbol( kAnyScope, "zfunc" );
bIsOp = lzIsOp( kCosmicScope, "zfunc" );
bIsOp = lzIsOp( kGlobalScope, "zfunc" );
bIsOp = lzIsOp( kAnyScope, "zfunc" );
bIsVar = lzIsVar( kAnyScope, "sauron" );
while ( keepLooping )
{
GetInputString( theExpression, 128 );
expLength = strlen( theExpression );
if ( expLength == 0 )
keepLooping = false;
else if ( (expLength == 1) && (theExpression[ 0 ] == '\r') )
keepLooping = false;
else if (theExpression[ 0 ] == '\\')
keepLooping = false;
else
{
cout << " " << lzEvalExpStrToStr( theExpression ) << '\n';
if ( lzGetLastErrorID() )
cout << lzGetLastErrorText() << '\n';
cout.flush();
}
}
bSetContextResult = lzDestroyPublicContext( "CallbackDemo" );
}
|