![]() |
wxIScan
|
An extended class to handle Lua scripting. More...
#include <wxiscanluascript.h>
Public Member Functions | |
| wxIScanLuaScript (const wxString &strScript=wxEmptyString, wxEvtHandler *poParent=NULL, const wxString &strDomain=wxEmptyString, bool *pbParentState=NULL) | |
| Standard constructor. | |
Static Private Member Functions | |
| static int | OCR (lua_State *L) |
| Do OCR on the loaded/scanned image and return the text (to Lua). | |
| static int | OpenImage (lua_State *L) |
| Open an image file in Lua using a given name. | |
| static int | SaveImage (lua_State *L) |
| Save an image file in Lua using a given name. | |
| static int | CopyText2Clipboard (lua_State *L) |
| Copy a given text to the clipboard in Lua. | |
| static int | Image2Mono (lua_State *L) |
| Replace the program's image by its monochrome version. | |
| static int | Image2Grey (lua_State *L) |
| Replace the program's image by its greyscale version. | |
| static int | CropImage (lua_State *L) |
| Replace the program's image by its cropped version. | |
| static int | EnhenceColours (lua_State *L) |
| Replace the program's image by a new version that is colour enhenced. | |
| static int | EnhenceOpticalContrast (lua_State *L) |
| Replace white colour by yellow. | |
| static int | RotateImage (lua_State *L) |
| (Fine) Rotate an image by a given angle. | |
| static int | RotateImage90 (lua_State *L) |
| Rotate an image by a given angle by 90 degrees. | |
| static int | ResizeImage (lua_State *L) |
| Resize an image to the given size. | |
| static int | Execute (lua_State *L) |
| Fork an external process. | |
| static int | ResetFileName (lua_State *L) |
| Set the filename of the image to "unknown.XXX". | |
An extended class to handle Lua scripting.
wxIScanLuaScript is a friend class to the frame window class wxIScanFrame an is intended to control the frame window remotely.
Definition at line 37 of file wxiscanluascript.h.
| wxIScanLuaScript::wxIScanLuaScript | ( | const wxString & | strScript = wxEmptyString, |
| wxEvtHandler * | poParent = NULL, |
||
| const wxString & | strDomain = wxEmptyString, |
||
| bool * | pbParentState = NULL |
||
| ) |
Standard constructor.
| strScript | The Lua source code of the script to execute. Default is the empty string. |
| poParent | a pointer to the parent event handler (mostly a window), may be NULL |
| strDomain | ... Default is the empty string. |
| pbParentState | a pointer to a boolean to get the error state, may be NULL |
Definition at line 32 of file wxiscanluascript.cpp.
References CopyText2Clipboard(), CropImage(), EnhenceColours(), EnhenceOpticalContrast(), Execute(), Image2Grey(), Image2Mono(), wxLuaScript::IsOk(), OCR(), OpenImage(), wxLuaScript::RegisterFunction(), ResetFileName(), RotateImage(), RotateImage90(), and SaveImage().
: wxLuaScript( strScript, poParent, strDomain, pbParentState ) { #if __WXLUASCRIPT_DYNAMIC__ // Check if the dynamic library is initialized correctly. if( !IsOk() ) { #if __DEBUG__ // Log waring message in DEBUG mode. wxLogWarning( wxString( wxT( "wxIScanLuaScript::wxIScanLuaScript -- " ) ) + _( "Base class was not correctly initialized." ) ); #endif // __DEBUG__ // Abort further initialization. return; } #endif // __WXLUASCRIPT_DYNAMIC__ // Register "OCR" as Lua function. RegisterFunction( wxT( "OCR" ), OCR ); // Register "OpenImage" (and its alias "LoadImage") as Lua function. RegisterFunction( wxT( "OpenImage" ), OpenImage ); RegisterFunction( wxT( "LoadImage" ), OpenImage ); // Register "SaveImage" as Lua function. RegisterFunction( wxT( "SaveImage" ), SaveImage ); // Register "CopyText2Clipboard" as Lua function. RegisterFunction( wxT( "CopyText2Clipboard" ), CopyText2Clipboard ); // Register "Image2Mono" as Lua function. RegisterFunction( wxT( "Image2Mono" ), Image2Mono ); // Register "Image2Grey" as Lua function. RegisterFunction( wxT( "Image2Grey" ), Image2Grey ); // Register "CropImage" as Lua function. RegisterFunction( wxT( "CropImage" ), CropImage ); // Register "EnhenceColours" as Lua function. RegisterFunction( wxT( "EnhenceColours" ), EnhenceColours ); // Register "EnhanceOpticalContrast" as Lua function. RegisterFunction( wxT( "EnhenceOpticalContrast" ), EnhenceOpticalContrast ); // Register "RotateImage" as Lua function. RegisterFunction( wxT( "RotateImage" ), RotateImage ); // Register "RotateImage90" as Lua function. RegisterFunction( wxT( "RotateImage90" ), RotateImage90 ); // Register "Execute" as Lua function. RegisterFunction( wxT( "Execute" ), Execute ); // Register "ResetFileName" as Lua function. RegisterFunction( wxT( "ResetFileName" ), ResetFileName ); }
| int wxIScanLuaScript::CopyText2Clipboard | ( | lua_State * | L | ) | [static, private] |
Copy a given text to the clipboard in Lua.
| L | a pointer to the Lua context. |
Definition at line 227 of file wxiscanluascript.cpp.
References wxLuaScript::lua_error, wxLuaScript::lua_gettop, wxLuaScript::lua_isstring, wxLuaScript::lua_pushboolean, and wxLuaScript::lua_pushstring.
Referenced by wxIScanLuaScript().
{
// Check the number of argument(s) and the type(s).
if( ( lua_gettop( L ) != 1 ) || !lua_isstring( L, 1 ) )
{
// Signal error.
lua_pushstring( L, "Incorrect argument or incorrect number of arguments." );
lua_error( L );
}
// Get the text.
wxString strText( (const char *)lua_tostring( L, 1 ), wxConvISO8859_1 );
// Copy the text to the clipboard and return the status to Lua.
lua_pushboolean( L, ::CopyText2Clipboard( strText ) );
// Return the number of (Lua) results.
return 1;
}
| int wxIScanLuaScript::CropImage | ( | lua_State * | L | ) | [static, private] |
Replace the program's image by its cropped version.
| L | a pointer to the Lua context. |
Definition at line 313 of file wxiscanluascript.cpp.
References wxLuaScript::GetThis(), wxLuaScript::lua_error, wxLuaScript::lua_gettop, wxLuaScript::lua_isnumber, wxLuaScript::lua_pushstring, wxLuaScript::lua_tointeger, wxIScanFrame::m_oImage, wxLuaScript::m_poParent, and wxIScanFrame::UpdateBitmap().
Referenced by wxIScanLuaScript().
{
// Check the number of argument(s) and the type(s).
int nNoOfArgs= lua_gettop( L );
if( !( nNoOfArgs == 4 )
|| !lua_isnumber( L, 1 )
|| !lua_isnumber( L, 2 )
|| !lua_isnumber( L, 3 )
|| !lua_isnumber( L, 4 )
)
{
// Signal error.
lua_pushstring( L, "Incorrect argument or incorrect number of arguments." );
lua_error( L );
}
// Get the this pointer to the current wxLuaScript object.
wxIScanLuaScript *poThis= (wxIScanLuaScript *)GetThis( L );
// Get the pointer to the event handler (the frame window).
wxIScanFrame *poParent= (wxIScanFrame *)poThis->m_poParent;
// Crop the image.
poParent->m_oImage= ::CropImage( poParent->m_oImage,
lua_tointeger( L, 1 ),
lua_tointeger( L, 2 ),
lua_tointeger( L, 3 ),
lua_tointeger( L, 4 ) );
poParent->UpdateBitmap();
// Return the number of (Lua) results.
return 0;
}
| int wxIScanLuaScript::EnhenceColours | ( | lua_State * | L | ) | [static, private] |
Replace the program's image by a new version that is colour enhenced.
| L | a pointer to the Lua context. |
Definition at line 350 of file wxiscanluascript.cpp.
References wxLuaScript::GetThis(), wxLuaScript::lua_error, wxLuaScript::lua_gettop, wxLuaScript::lua_isnumber, wxLuaScript::lua_pushstring, wxLuaScript::lua_tointeger, wxIScanFrame::m_oImage, wxLuaScript::m_poParent, and wxIScanFrame::UpdateBitmap().
Referenced by wxIScanLuaScript().
{
int anParam[]= { 0, 0, 100, 0, 0, 0 };
int nNoOfArgs= lua_gettop( L );
// Check the number of argument(s), and ...
if( ( nNoOfArgs < 0 ) || ( nNoOfArgs > 6 ) )
{
// Signal error.
lua_pushstring( L, "Incorrect number of arguments." );
lua_error( L );
}
// ... the type(s), and ...
for( int i= 0; i < nNoOfArgs; i++ )
{
// ... get the value from Lua;
if( lua_isnumber( L, i + 1 ) )
{
anParam[i]= lua_tointeger( L, i + 1 );
}
else
{
// Signal error.
lua_pushstring( L, "Incorrect argument type." );
lua_error( L );
}
}
// Get the this pointer to the current wxLuaScript object.
wxIScanLuaScript *poThis= (wxIScanLuaScript *)GetThis( L );
// Get the pointer to the event handler (the frame window).
wxIScanFrame *poParent= (wxIScanFrame *)poThis->m_poParent;
// Replace the program's image by the colour enhenced one.
poParent->m_oImage= ::EnhenceColours( poParent->m_oImage,
anParam[0], anParam[1], anParam[2],
anParam[3], anParam[4], anParam[5] );
poParent->UpdateBitmap();
// Return the number of (Lua) results.
return 0;
}
| int wxIScanLuaScript::EnhenceOpticalContrast | ( | lua_State * | L | ) | [static, private] |
Replace white colour by yellow.
| L | a pointer to the Lua context. |
Definition at line 398 of file wxiscanluascript.cpp.
References wxIScanFrame::EnhenceOpticalContrast(), wxLuaScript::GetThis(), wxLuaScript::lua_error, wxLuaScript::lua_gettop, wxLuaScript::lua_pushstring, and wxLuaScript::m_poParent.
Referenced by wxIScanLuaScript().
{
// Check the number of argument(s) and the type(s).
if( lua_gettop( L ) != 0 )
{
// Signal error.
lua_pushstring( L, "Incorrect number of arguments." );
lua_error( L );
}
// Get the this pointer to the current wxLuaScript object.
wxIScanLuaScript *poThis= (wxIScanLuaScript *)GetThis( L );
// Get the pointer to the event handler (the frame window).
wxIScanFrame *poParent= (wxIScanFrame *)poThis->m_poParent;
// Replace white colour by yellow.
poParent->EnhenceOpticalContrast();
// Return the number of (Lua) results.
return 0;
}
| int wxIScanLuaScript::Execute | ( | lua_State * | L | ) | [static, private] |
Fork an external process.
| L | a pointer to the Lua context. |
Definition at line 505 of file wxiscanluascript.cpp.
References wxIScanFrame::Execute(), wxLuaScript::GetThis(), wxLuaScript::lua_error, wxLuaScript::lua_gettop, wxLuaScript::lua_isstring, wxLuaScript::lua_pushboolean, wxLuaScript::lua_pushstring, wxLuaScript::lua_toboolean, and wxLuaScript::m_poParent.
Referenced by wxIScanLuaScript().
{
// Check the number of argument(s) and the type(s).
int nNoOfArgs= lua_gettop( L );
if( !( ( nNoOfArgs == 1 ) && lua_isstring( L, 1 ) )
&& !( ( nNoOfArgs == 2 ) && lua_isstring( L, 1 ) && lua_isboolean( L, 2 ) )
&& !( ( nNoOfArgs == 3 ) && lua_isstring( L, 1 ) && lua_isboolean( L, 2 ) && lua_isstring( L, 3 ) )
)
{
// Signal error.
lua_pushstring( L, "Incorrect argument or incorrect number of arguments." );
lua_error( L );
}
// Get the this pointer to the current wxLuaScript object.
wxIScanLuaScript *poThis= (wxIScanLuaScript *)GetThis( L );
// Get the pointer to the event handler (the frame window).
wxIScanFrame *poParent= (wxIScanFrame *)poThis->m_poParent;
// Execute the command.
bool bRetC= false;
switch( nNoOfArgs )
{
case 1: bRetC= poParent->Execute(
wxString( (const char *)lua_tostring( L, 1 ), wxConvISO8859_1 )
);
break;
case 2: bRetC= poParent->Execute(
wxString( (const char *)lua_tostring( L, 1 ), wxConvISO8859_1 ),
lua_toboolean( L, 2 )
);
break;
case 3: bRetC= poParent->Execute(
wxString( (const char *)lua_tostring( L, 1 ), wxConvISO8859_1 ),
lua_toboolean( L, 2 ),
wxString( (const char *)lua_tostring( L, 3 ), wxConvISO8859_1 )
);
break;
}
// Return a boolean that flags success (true) or failure (false).
lua_pushboolean( L, bRetC );
// Return the number of (Lua) results.
return 1;
}
| int wxIScanLuaScript::Image2Grey | ( | lua_State * | L | ) | [static, private] |
Replace the program's image by its greyscale version.
| L | a pointer to the Lua context. |
Definition at line 285 of file wxiscanluascript.cpp.
References wxLuaScript::GetThis(), wxLuaScript::lua_error, wxLuaScript::lua_gettop, wxLuaScript::lua_pushstring, wxIScanFrame::m_oImage, wxLuaScript::m_poParent, and wxIScanFrame::UpdateBitmap().
Referenced by wxIScanLuaScript().
{
// Check the number of argument(s) and the type(s).
int nNoOfArgs= lua_gettop( L );
if( !( nNoOfArgs == 0 ) )
{
// Signal error.
lua_pushstring( L, "Incorrect number of arguments." );
lua_error( L );
}
// Get the this pointer to the current wxLuaScript object.
wxIScanLuaScript *poThis= (wxIScanLuaScript *)GetThis( L );
// Get the pointer to the event handler (the frame window).
wxIScanFrame *poParent= (wxIScanFrame *)poThis->m_poParent;
// Convert the image to a monochrome image.
poParent->m_oImage= ::Image2Grey( poParent->m_oImage );
poParent->UpdateBitmap();
// Return the number of (Lua) results.
return 0;
}
| int wxIScanLuaScript::Image2Mono | ( | lua_State * | L | ) | [static, private] |
Replace the program's image by its monochrome version.
| L | a pointer to the Lua context. |
Definition at line 249 of file wxiscanluascript.cpp.
References wxLuaScript::GetThis(), wxLuaScript::lua_error, wxLuaScript::lua_gettop, wxLuaScript::lua_isnumber, wxLuaScript::lua_pushstring, wxLuaScript::lua_tointeger, wxIScanFrame::m_oImage, wxLuaScript::m_poParent, and wxIScanFrame::UpdateBitmap().
Referenced by wxIScanLuaScript().
{
// Check the number of argument(s) and the type(s).
int nNoOfArgs= lua_gettop( L );
if( !( nNoOfArgs == 0 )
&& !( ( nNoOfArgs == 1 ) && lua_isnumber( L, 1 ) ) )
{
// Signal error.
lua_pushstring( L, "Incorrect argument or incorrect number of arguments." );
lua_error( L );
}
// Get the this pointer to the current wxLuaScript object.
wxIScanLuaScript *poThis= (wxIScanLuaScript *)GetThis( L );
// Get the pointer to the event handler (the frame window).
wxIScanFrame *poParent= (wxIScanFrame *)poThis->m_poParent;
// Convert the image to a monochrome image.
if( nNoOfArgs == 1 )
{
poParent->m_oImage= ::Image2Mono( poParent->m_oImage, lua_tointeger( L, 1 ) );
}
else
{
poParent->m_oImage= ::Image2Mono( poParent->m_oImage );
}
poParent->UpdateBitmap();
// Return the number of (Lua) results.
return 0;
}
| int wxIScanLuaScript::OCR | ( | lua_State * | L | ) | [static, private] |
Do OCR on the loaded/scanned image and return the text (to Lua).
| L | a pointer to the Lua context. |
Definition at line 93 of file wxiscanluascript.cpp.
References wxIScanFrame::GetImageSelection(), GetTextFromFile(), wxLuaScript::GetThis(), wxLuaScript::lua_error, wxLuaScript::lua_gettop, wxLuaScript::lua_pushstring, wxLuaScript::lua_toboolean, wxLuaScript::m_poParent, wxIScanFrame::m_strBitmapMimeType, and wxIScanFrame::OCR().
Referenced by wxIScanLuaScript().
{
int nNoOfArgs= lua_gettop( L );
// Check the number of argument(s) and the type(s).
if( ( nNoOfArgs != 0 )
&& ( ( nNoOfArgs != 1 ) || !lua_isboolean( L, 1 ) ) )
{
// Signal error.
lua_pushstring( L, "Incorrect argument or incorrect number of arguments." );
lua_error( L );
}
// Get the flag if hOCR processing should be used.
bool bUseHocr= ( nNoOfArgs == 1 ) ? lua_toboolean( L, 1 ) : false;
// Get the this pointer to the current wxLuaScript object.
wxIScanLuaScript *poThis= (wxIScanLuaScript *)GetThis( L );
// Get the pointer to the event handler (the frame window).
wxIScanFrame *poParent= (wxIScanFrame *)poThis->m_poParent;
// Save image in a temporary file.
wxString strTempFileName= wxFileName::CreateTempFileName( wxT( "" ) );
poParent->GetImageSelection().SaveFile( strTempFileName, poParent->m_strBitmapMimeType );
// Do OCR (and get the file name of the generated temporary text/hOCR file).
wxString strOcrTextFileName= poParent->OCR( strTempFileName, bUseHocr );
// Remove the temporary JPEG file.
::wxRemoveFile( strTempFileName );
// Return the text.
if( !strOcrTextFileName.IsEmpty() )
{
// Get the text from the temporary text file, ...
wxString strText= ::GetTextFromFile( strOcrTextFileName );
// ... return it, and ...
lua_pushstring( L, strText.char_str( wxConvISO8859_1 ) );
// ... remove the temporary text file.
::wxRemoveFile( strOcrTextFileName );
}
else
{
// Signal error.
lua_pushstring( L, "OCR failed." );
lua_error( L );
}
// Return the number of (Lua) results.
return 1;
}
| int wxIScanLuaScript::OpenImage | ( | lua_State * | L | ) | [static, private] |
Open an image file in Lua using a given name.
| L | a pointer to the Lua context. |
Definition at line 151 of file wxiscanluascript.cpp.
References wxLuaScript::GetThis(), wxLuaScript::lua_error, wxLuaScript::lua_gettop, wxLuaScript::lua_isstring, wxLuaScript::lua_pushboolean, wxLuaScript::lua_pushstring, wxLuaScript::lua_toboolean, wxLuaScript::m_poParent, and wxIScanFrame::OpenImage().
Referenced by wxIScanLuaScript().
{
// Check the number of argument(s) and the type(s).
int nNoOfArgs= lua_gettop( L );
if( !( ( nNoOfArgs == 1 ) && lua_isstring( L, 1 ) )
&& !( ( nNoOfArgs == 2 ) && lua_isstring( L, 1 ) && lua_isboolean( L, 2 ) )
)
{
// Signal error.
lua_pushstring( L, "Incorrect argument or incorrect number of arguments." );
lua_error( L );
}
// Get the filename.
wxString strFileName( (const char *)lua_tostring( L, 1 ), wxConvISO8859_1 );
// Get ...
bool bSetFileName= ( nNoOfArgs == 2 ) ? lua_toboolean( L, 2 ) : false;
// Get the this pointer to the current wxLuaScript object.
wxIScanLuaScript *poThis= (wxIScanLuaScript *)GetThis( L );
// Get the pointer to the event handler (the frame window).
wxIScanFrame *poParent= (wxIScanFrame *)poThis->m_poParent;
// Open the image and return the status to Lua.
lua_pushboolean( L, poParent->OpenImage( strFileName, bSetFileName ) );
// Return the number of (Lua) results.
return 1;
}
| int wxIScanLuaScript::ResetFileName | ( | lua_State * | L | ) | [static, private] |
Set the filename of the image to "unknown.XXX".
| L | a pointer to the Lua context. |
Definition at line 557 of file wxiscanluascript.cpp.
References wxLuaScript::GetThis(), wxLuaScript::lua_error, wxLuaScript::lua_gettop, wxLuaScript::lua_pushstring, wxLuaScript::m_poParent, and wxIScanFrame::ResetFileName().
Referenced by wxIScanLuaScript().
{
// Check the number of argument(s) and the type(s).
if( lua_gettop( L ) != 0 )
{
// Signal error.
lua_pushstring( L, "Incorrect number of arguments." );
lua_error( L );
}
// Get the this pointer to the current wxLuaScript object.
wxIScanLuaScript *poThis= (wxIScanLuaScript *)GetThis( L );
// Get the pointer to the event handler (the frame window).
wxIScanFrame *poParent= (wxIScanFrame *)poThis->m_poParent;
// Set the filename of the image to "unknown.XXX".
poParent->ResetFileName();
// Return the number of (Lua) results.
return 0;
}
| int wxIScanLuaScript::ResizeImage | ( | lua_State * | L | ) | [static, private] |
Resize an image to the given size.
| L | a pointer to the Lua context. |
Definition at line 478 of file wxiscanluascript.cpp.
References wxLuaScript::GetThis(), wxLuaScript::lua_error, wxLuaScript::lua_gettop, wxLuaScript::lua_isnumber, wxLuaScript::lua_pushstring, wxLuaScript::lua_tointeger, wxLuaScript::lua_tonumber, wxIScanFrame::m_oImage, wxLuaScript::m_poParent, and wxIScanFrame::UpdateBitmap().
{
// Check the number of argument(s) and the type(s).
if( ( lua_gettop( L ) != 2 ) || !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) )
{
// Signal error.
lua_pushstring( L, "Incorrect argument or incorrect number of arguments." );
lua_error( L );
}
// Get the this pointer to the current wxLuaScript object.
wxIScanLuaScript *poThis= (wxIScanLuaScript *)GetThis( L );
// Get the pointer to the event handler (the frame window).
wxIScanFrame *poParent= (wxIScanFrame *)poThis->m_poParent;
// Rosize the image an replace it by the output.
poParent->m_oImage= ::ResizeImage( poParent->m_oImage,
lua_tonumber( L, 1 ), lua_tointeger( L, 2 ) );
poParent->UpdateBitmap();
// Return the number of (Lua) results.
return 0;
}
| int wxIScanLuaScript::RotateImage | ( | lua_State * | L | ) | [static, private] |
(Fine) Rotate an image by a given angle.
| L | a pointer to the Lua context. |
Definition at line 423 of file wxiscanluascript.cpp.
References wxLuaScript::GetThis(), wxLuaScript::lua_error, wxLuaScript::lua_gettop, wxLuaScript::lua_isnumber, wxLuaScript::lua_pushstring, wxLuaScript::lua_tonumber, wxIScanFrame::m_oImage, wxLuaScript::m_poParent, and wxIScanFrame::UpdateBitmap().
Referenced by wxIScanLuaScript().
{
// Check the number of argument(s) and the type(s).
if( ( lua_gettop( L ) != 1 ) || !lua_isnumber( L, 1 ) )
{
// Signal error.
lua_pushstring( L, "Incorrect argument or incorrect number of arguments." );
lua_error( L );
}
// Get the this pointer to the current wxLuaScript object.
wxIScanLuaScript *poThis= (wxIScanLuaScript *)GetThis( L );
// Get the pointer to the event handler (the frame window).
wxIScanFrame *poParent= (wxIScanFrame *)poThis->m_poParent;
// Rotate the image an replace it by the output.
poParent->m_oImage= ::RotateImage( poParent->m_oImage, lua_tonumber( L, 1 ) );
poParent->UpdateBitmap();
// Return the number of (Lua) results.
return 0;
}
| int wxIScanLuaScript::RotateImage90 | ( | lua_State * | L | ) | [static, private] |
Rotate an image by a given angle by 90 degrees.
| L | a pointer to the Lua context. |
Definition at line 449 of file wxiscanluascript.cpp.
References wxLuaScript::GetThis(), wxLuaScript::lua_error, wxLuaScript::lua_gettop, wxLuaScript::lua_pushstring, wxLuaScript::lua_toboolean, wxIScanFrame::m_oImage, wxLuaScript::m_poParent, and wxIScanFrame::UpdateBitmap().
Referenced by wxIScanLuaScript().
{
// Check the number of argument(s) and the type(s).
int nNoOfArgs= lua_gettop( L );
if( !( nNoOfArgs == 0 )
&& !( ( nNoOfArgs == 1 ) && lua_isboolean( L, 1 ) ) )
{
// Signal error.
lua_pushstring( L, "Incorrect argument or incorrect number of arguments." );
lua_error( L );
}
// Get the this pointer to the current wxLuaScript object.
wxIScanLuaScript *poThis= (wxIScanLuaScript *)GetThis( L );
// Get the pointer to the event handler (the frame window).
wxIScanFrame *poParent= (wxIScanFrame *)poThis->m_poParent;
// Rotate the image and replace it by the output.
poParent->m_oImage= poParent->m_oImage.Rotate90( ( nNoOfArgs == 1 ) ? lua_toboolean( L, 1 ) : true );
poParent->UpdateBitmap();
// Return the number of (Lua) results.
return 0;
}
| int wxIScanLuaScript::SaveImage | ( | lua_State * | L | ) | [static, private] |
Save an image file in Lua using a given name.
| L | a pointer to the Lua context. |
Definition at line 186 of file wxiscanluascript.cpp.
References wxIScanFrame::GetImageSelection(), wxLuaScript::GetThis(), wxLuaScript::lua_error, wxLuaScript::lua_gettop, wxLuaScript::lua_isstring, wxLuaScript::lua_pushboolean, wxLuaScript::lua_pushstring, and wxLuaScript::m_poParent.
Referenced by wxIScanLuaScript().
{
// Check the number of argument(s) and the type(s).
int nNoOfArgs= lua_gettop( L );
if( !( ( nNoOfArgs == 1 ) && lua_isstring( L, 1 ) )
&& !( ( nNoOfArgs == 2 ) && lua_isstring( L, 1 ) && lua_isstring( L, 2 ) )
)
{
// Signal error.
lua_pushstring( L, "Incorrect argument or incorrect number of arguments." );
lua_error( L );
}
// Get the this pointer to the current wxLuaScript object.
wxIScanLuaScript *poThis= (wxIScanLuaScript *)GetThis( L );
// Get the pointer to the event handler (the frame window).
wxIScanFrame *poParent= (wxIScanFrame *)poThis->m_poParent;
// Get the filename.
wxString strFileName( (const char *)lua_tostring( L, 1 ), wxConvISO8859_1 );
// Save the image and return the status to Lua.
if( nNoOfArgs == 2 )
{
wxString strMimeType( (const char *)lua_tostring( L, 2 ), wxConvISO8859_1 );
lua_pushboolean( L, poParent->GetImageSelection().SaveFile( strFileName, strMimeType ) );
}
else
{
lua_pushboolean( L, poParent->GetImageSelection().SaveFile( strFileName ) );
}
// Return the number of (Lua) results.
return 1;
}