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