Click here to Skip to main content
15,883,531 members
Articles / Containers / Virtual Machine

TOOL

Rate me:
Please Sign up or sign in to vote.
4.98/5 (52 votes)
23 Oct 200676 min read 230.1K   5.4K   147  
TOOL (Tiny Object Oriented Language) is an easily-embedded, object-oriented, C++-like-language interpreter. The purpose of this article is to introduce the TOOL interpreter and language from the perspective of a person who has a desire to include a scripting solution as part of his project.
#ifndef SCRIPT_WRAPPER_H_INCLUDED
#define SCRIPT_WRAPPER_H_INCLUDED
/*****************************************************************************/
/*                              HEADER FILE                                  */
/*****************************************************************************/
/*
       $Archive:   $

      $Revision:   $
          $Date:   $
        $Author:   $

    Description:   Declaration of the secipt engine wrapper classes for all map
                   script driven system I/O

                      TOOL And XML FORMS License
                      ==========================

                      Except where otherwise noted, all of the documentation 
                      and software included in the TOOL package is 
                      copyrighted by Michael Swartzendruber.

                      Copyright (C) 2005 Michael John Swartzendruber. 
                      All rights reserved.

                      Access to this code, whether intentional or accidental,
                      does NOT IMPLY any transfer of rights.

                      This software is provided "as-is," without any express 
                      or implied warranty. In no event shall the author be held
                      liable for any damages arising from the use of this software.

                      Permission is granted to anyone to use this software for 
                      any purpose, including commercial applications, and to 
                      alter and redistribute it, provided that the following 
                      conditions are met:

                      1. All redistributions of source code files must retain 
                         all copyright notices that are currently in place, 
                         and this list of conditions without modification.

                      2. The origin of this software must not be misrepresented;
                         you must not claim that you wrote the original software.

                      3. If you use this software in another product, an acknowledgment
                         in the product documentation would be appreciated but is
                         not required.

                      4. Modified versions in source or binary form must be plainly 
                         marked as such, and must not be misrepresented as being 
                         the original software.
*/
/*****************************************************************************/

#include <map>
#include <string>

#include <fstream>	// 2b|!2b==?

#include "./InterpreterCore/APIClasses/VMString.h"
#include "./InterpreterCore/APIClasses/VMByteArray.h"
#include "./InterpreterCore/VMCore.h"



///////////////////////////////////////////////////////////////////////////////
//
// declaration of the script instance wrapper
//
class VMFacade : public CThreadSafeAppContext
{
friend class VMThreadRunnableObject;

public:
  VMFacade( bool bCreateConsole = false, HWND hWndOuput = NULL );
  virtual ~VMFacade( void );

private:
  VMFacade& operator = ( VMFacade& roOther ){ return( *this ); };
  VMFacade( VMFacade& roOther ){;};
 
public:
  bool Load( const char* pchScriptName );
  bool CompileFile( const char* pchFileToRun );
  bool CompileText( const char* pchTextToRun );
  bool Execute( const char* pchEntryPoint );

  void ForceShowLines( void )
  {
    m_oScriptEngine.m_oCompiler.ForceShowLines();
  };

  void SetVar( SCRIPT_ARGUMENTS* poArguments, bool bThisOwnsArgPointers = false );

  void AttachToSharedAppVars( CThreadSafeAppContext* poOwner )
  {
    if ( NULL != poOwner )
    {
      CThreadSafeAppContext::m_poScriptArguments = poOwner->m_poScriptArguments;

      if ( CThreadSafeAppContext::m_bThisOwnsCriticalSection == true )
      {
        DeleteCriticalSection( &m_xCriticalSection );

        CThreadSafeAppContext::m_xCriticalSection         = poOwner->m_xCriticalSection;
        CThreadSafeAppContext::m_bThisOwnsCriticalSection = false;
      }
    }
  };

  SCRIPT_ARGUMENTS* GetVar( void ) { return( CThreadSafeAppContext::m_poScriptArguments ); };

  bool OwnsVariablesOwner( void ) { return( m_bThisOwnsArgPointers ); };

  void CloneArguments( SCRIPT_ARGUMENTS* poArguments, bool bOverWrite );

  void ClearAllVars( void );

  bool RunTemplateFile( const char* pchTemplateFileName, char* pchOutFileName = NULL );

  bool ProcessCmdLine( const char* pchCmd, std::ofstream& roOutFile, std::ifstream& roTemplate );				  // 2b|!2b==?
  bool OutputProcessedContent( std::ofstream& roOutFile, std::ifstream& roTemplate, const char* pchCmd );	// 2b|!2b==?

  void SetOutputObserver( VMOutputObserver* poObserver )
  {
    m_oScriptEngine.SetOutputObserver( poObserver );
  };

  void SetVMPageInitInfo( VMPageInitInfo*  poPageInitInfo )
  {
     m_oScriptEngine.SetVMPageInitInfo( poPageInitInfo );
  };

  void SetVmXmlFormInfo( CXMLFormFacade*  poXmlFormFacade )
  {
    m_oScriptEngine.SetVmXmlFormInfo( poXmlFormFacade );
  };

  void SetCurrentThread( VMThreadRunnableObject* poCurrentThread )
  {
    m_oScriptEngine.SetCurrentThread( poCurrentThread );
  };

  void SetDebuggerHook( VMDebuggerHook* poDebugger )
  {
    m_oScriptEngine.m_oInterpreter.SetDebuggerHook( poDebugger );

    if ( NULL != poDebugger )
    {
      poDebugger->m_poVMChip = &m_oScriptEngine.m_oVirtualChip;
    }
    m_poDebugger = poDebugger;
  };

  void SetAppCommandTarget( HWND hWnd )
  {
    m_oScriptEngine.SetAppCommandTarget( hWnd );
  };

  // scripting engine interface methods
  //
  virtual bool  SetFieldByName( const char* pchFieldName, const CAppContextVariant* poFieldValue );
  virtual const CAppContextVariant* GetFieldByName( const char* pchFieldName );
  virtual bool  WriteDirectToTemplateContext( const char* pchToWrite );

protected:
  VMString          m_oScriptName;
  VMString          m_oScriptText;
  VMString          m_oScriptResult;
  VMString          m_oErrorText;
  VMCore            m_oScriptEngine;
  bool              m_bIsGood;
  bool              m_bIsLoaded;
  bool              m_bIsCompiled;
  bool              m_bThisOwnsArgPointers;
  std::ofstream     m_oOutFile;   // 2b|!2b==?
  VMDebuggerHook*   m_poDebugger;
};

#endif


/*****************************************************************************/
/* Check-in history */
/*
 *$Log:  $
*/
/*****************************************************************************/


By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions