class CCompiledScript
{
public:
CCompiledScript();
~CCompiledScript();
bool LoadScript(const std::string filename, const std::string scriptname);
bool ReLoadScript();
void Execute();
private:
std::string m_ScriptName;
std::string m_FileName;
PBYTE m_Script;
DWORD m_dwScriptLenghth;
};
CCompiledScript::CCompiledScript(): m_Script(NULL), m_dwScriptLenghth(0)
{
m_ScriptName.clear();
m_FileName.clear();
}
CCompiledScript::~CCompiledScript()
{
if(m_Script)
{
delete [] m_Script;
m_Script = NULL;
}
}
bool CCompiledScript::ReLoadScript()
{
if(!m_ScriptName.empty())
{
return( LoadScript( m_FileName, m_ScriptName ) );
}
return(false); // was the script loaded???
}
bool CCompiledScript::LoadScript(const std::string filename, const std::string scriptname)
{
if(m_Script)
{
delete [] m_Script;
m_Script = NULL;
}
m_FileName = filename;
m_ScriptName = scriptname;
HANDLE hInFile = CreateFile( filename.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (hInFile == INVALID_HANDLE_VALUE)
{
return(false);
}
// Get the filesize and allocate memory for the script
m_dwScriptLenghth = GetFileSize (hInFile, NULL);
m_Script = new BYTE[m_dwScriptLenghth];
ZeroMemory(m_Script, m_dwScriptLenghth);
// Load up the file into the uncompressed buffer.
DWORD dwBytesRead = 0;
if(!ReadFile(hInFile, m_Script, m_dwScriptLenghth, &dwBytesRead, NULL))
{
// We had a problem loading the uncompressed file - clean up and return false
CloseHandle(hInFile);
delete [] m_Script;
m_Script = NULL;
m_ScriptName.clear();
return(false);
}
CloseHandle(hInFile);
return(true);
}
-edited code tag to source
-Bumped
Dave "Dak Lozar" Loeser
[edited by - Dak Lozar on June 3, 2003 3:06:26 PM]
[edited by - Dak Lozar on December 9, 2003 10:42:26 PM]
Scriptable Classes class
I've been comtemplating a class that scriptable classes will contain or be derived from... what is the general consensus of something like the following:
Dave Dak Lozar Loeser
"Software Engineering is a race between the programmers, trying to make bigger and better fool-proof software, and the universe trying to make bigger fools. So far the Universe in winning."--anonymous
"Software Engineering is a race between the programmers, trying to make bigger and better fool-proof software, and the universe trying to make bigger fools. So far the Universe in winning."--anonymous
Bump, OK, this post is old and I''d really like some feedback. I''m getting ready to implement scripting into my engine and want to know if something such as this would be useful or would it come back to bite me in the future. Any of you guys that have implemented scripting with Lua have any tips from the trenches?
Thanks,
Dave Dak Lozar Loeser
The WM_NULL message performs no operation. An application sends the WM_NULL message if it wants to post a message that the recipient window will ignore. - MSDN
Thanks,
Dave Dak Lozar Loeser
The WM_NULL message performs no operation. An application sends the WM_NULL message if it wants to post a message that the recipient window will ignore. - MSDN
Dave Dak Lozar Loeser
"Software Engineering is a race between the programmers, trying to make bigger and better fool-proof software, and the universe trying to make bigger fools. So far the Universe in winning."--anonymous
"Software Engineering is a race between the programmers, trying to make bigger and better fool-proof software, and the universe trying to make bigger fools. So far the Universe in winning."--anonymous
Ya know, i must say this forum is about dead. I''d recommend posting this under game programming or general programming. You might get some answers
. Sorry I can''t answer you.
![](wink.gif)
December 11, 2003 07:04 PM
I''d suggest just going out and trying it. That''s the only way you''re ever going to get an answer for your question. As it is, the code you''ve written is pretty generic and doesn''t have anything to do with scripting.
Dak Lozar - Check this out. It''s pretty much what you want to do
“Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.” — Brian W. Kernighan (C programming language co-inventor)
![](smile.gif)
“Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.” — Brian W. Kernighan (C programming language co-inventor)
[ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | C++ FAQ Lite | Function Ptrs | CppTips Archive ]
[ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Free C++ IDE | Boost C++ Lib | MSVC6 Lib Fixes ]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
quote: Original post by Fruny
Dak Lozar - Check this out. It''s pretty much what you want to do
Thanks for the link - I''ve already seen this and I prefer to use Lua over Python. Thanks again.
Dave Dak Lozar Loeser
The WM_NULL message performs no operation. An application sends the WM_NULL message if it wants to post a message that the recipient window will ignore. - MSDN
Dave Dak Lozar Loeser
"Software Engineering is a race between the programmers, trying to make bigger and better fool-proof software, and the universe trying to make bigger fools. So far the Universe in winning."--anonymous
"Software Engineering is a race between the programmers, trying to make bigger and better fool-proof software, and the universe trying to make bigger fools. So far the Universe in winning."--anonymous
December 12, 2003 05:05 PM
http://catmother.sf.net
They have embedded LUA in their game and they have taken an interesting approach even though it is kinda messy.
I''d say go for it, and see how it turns out. You only really learn stuff, by trying it out and then tuning it and such.
Good Luck.
They have embedded LUA in their game and they have taken an interesting approach even though it is kinda messy.
I''d say go for it, and see how it turns out. You only really learn stuff, by trying it out and then tuning it and such.
Good Luck.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement