Code Search for Developers
 
 
  

wtkmsghook.cpp from NeoEngineNG at Krugle


Show wtkmsghook.cpp syntax highlighted

/***************************************************************************
      wtkmsghook.cpp  -  Bindings for WTK message hook objects and chunks
                             -------------------
    begin                : Fri Jan 16 2004
    copyright            : (C) 2004 by Mattias Jansson
    email                : mattias@realityrift.com
 ***************************************************************************

 The contents of this file are subject to the Mozilla Public License Version
 1.1 (the "License"); you may not use this file except in compliance with
 the License. You may obtain a copy of the License at 
 http://www.mozilla.org/MPL/

 Software distributed under the License is distributed on an "AS IS" basis,
 WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 for the specific language governing rights and limitations under the
 License.

 The Original Code is the NeoEngine, NeoLua, wtkmsghook.cpp

 The Initial Developer of the Original Code is Mattias Jansson.
 Portions created by Mattias Jansson are Copyright (C) 2004
 Reality Rift Studios. All Rights Reserved.

 ***************************************************************************/

#include "wtkmsghook.h"
#include "core.h"
#include "script.h"

#include <neoengine/logstream.h>
#include <neoengine/util.h>


#ifdef HAVE_NEOWTK

#ifdef HAVE_NEOCHUNKIO
#include <neochunkio/stdstring.h>
#endif

using namespace std;
using namespace NeoEngine;
using namespace NeoWTK;


namespace NeoLua
{


const char LuaMsgHookMethod::className[] = "MsgHookMethod";

Lunar< LuaMsgHookMethod >::RegType LuaMsgHookMethod::methods[] = { 
	
	{ 0, 0 }

};


LuaMsgHookMethod::~LuaMsgHookMethod()
{
	delete m_pkScript;
}


void LuaMsgHookMethod::ProcessHook( NeoWTK::MsgHook *pkHook, NeoWTK::Msg *pkMsg )
{
	int iArg = Lunar< LuaMsgHookMethod >::push( m_pkScript->m_pkLua, this, false );

	lua_pushvalue( m_pkScript->m_pkLua, iArg );

	Lunar< LuaMsgHookMethod >::call( m_pkScript->m_pkLua, "ProcessHook" );
}



#ifdef HAVE_NEOCHUNKIO

using namespace NeoChunkIO;


int LuaMsgHookChunk::ParseData( unsigned int uiFlags, NeoEngine::FileManager *pkFileManager )
{
	MsgHookChunk::ParseData( uiFlags, pkFileManager );

	Chunk *pkChunk;
	LuaMsgHookMethod *pkMethod = new LuaMsgHookMethod( 0 );

	m_pkHook->m_pkProcessor = pkMethod;


	if( ( pkChunk = FindChunk( "scriptfile", NeoChunkIO::ChunkType::STRING ) ) )
	{
		pkMethod->m_pkScript = Core::Get()->CreateScript();

		string &rstrFile = dynamic_cast< StringChunk* >( pkChunk )->m_strData;

		if( !pkMethod->m_pkScript->Load( rstrFile ) )
		{
			neolog << LogLevel( ERROR ) << "*** Unable to load script [" << rstrFile << "]" << endl;
			return -1;
		}
	}
	else if( ( pkChunk = FindChunk( "script", NeoChunkIO::ChunkType::STRING ) ) )
	{
		pkMethod->m_pkScript = Core::Get()->CreateScript();

		string &rstrSource = dynamic_cast< StringChunk* >( pkChunk )->m_strData;

		unsigned int uiSize = rstrSource.length();

		unsigned char *pucBuffer = new unsigned char[ uiSize + 1 ];
		fmemcpy( pucBuffer, rstrSource.c_str(), uiSize );

		pucBuffer[ uiSize ] = 0;

		BufferFile kFile( pucBuffer, uiSize, "", "__buffer.lua", ios_base::in, false, 0 );

		if( !pkMethod->m_pkScript->Load( &kFile ) )
		{
			neolog << LogLevel( ERROR ) << "*** Unable to load script from string source" << endl;
			return -1;
		}
	}

	return 1;
}


#endif


};


#endif






See more files for this project here

NeoEngineNG

NeoenEngine NG (Next Generation) is the evolution of neoengine one,it\'s a different development from NeoEngine2, it\'s a direct inherits from NeoEngine one.\n

Project homepage: http://sourceforge.net/projects/neoengineng
Programming language(s): C,C++
License: other

  lua/
    src/
      lib/
        lauxlib.c
        lbaselib.c
        ldblib.c
        liolib.c
        lmathlib.c
        loadlib.c
        lstrlib.c
        ltablib.c
      lapi.c
      lapi.h
      lcode.c
      lcode.h
      ldebug.c
      ldebug.h
      ldo.c
      ldo.h
      ldump.c
      lfunc.c
      lfunc.h
      lgc.c
      lgc.h
      llex.c
      llex.h
      llimits.h
      lmem.c
      lmem.h
      lobject.c
      lobject.h
      lopcodes.c
      lopcodes.h
      lparser.c
      lparser.h
      lstate.c
      lstate.h
      lstring.c
      lstring.h
      ltable.c
      ltable.h
      ltests.c
      ltm.c
      ltm.h
      lundump.c
      lundump.h
      lvm.c
      lvm.h
      lzio.c
      lzio.h
    COPYRIGHT
    lauxlib.h
    lua.h
    lualib.h
    lunar.h
  Makefile.am
  SConscript
  base.cpp
  base.h
  bindings.cpp
  bindings.h
  chunktype.h
  console.cpp
  console.h
  core.cpp
  core.h
  neolua-static.dev
  neolua.cbp
  neolua.dev
  neolua.dsp
  neolua.layout
  neolua.vcproj
  script.cpp
  script.h
  wtkmsghook.cpp
  wtkmsghook.h