-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLuaStateOutFile.cpp
More file actions
85 lines (65 loc) · 1.58 KB
/
Copy pathLuaStateOutFile.cpp
File metadata and controls
85 lines (65 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
///////////////////////////////////////////////////////////////////////////////
// This source file is part of the LuaPlus source distribution and is Copyright
// 2001-2010 by Joshua C. Jensen (jjensen@workspacewhiz.com).
//
// The latest version may be obtained from http://luaplus.org/.
//
// The code presented in this file may be used in any environment it is
// acceptable to use Lua.
///////////////////////////////////////////////////////////////////////////////
#ifndef BUILDING_LUAPLUS
#define BUILDING_LUAPLUS
#endif
#include "LuaLink.h"
LUA_EXTERN_C_BEGIN
#include "src/lobject.h"
LUA_EXTERN_C_END
#include "LuaPlus.h"
namespace LuaPlus {
LuaStateOutFile::LuaStateOutFile() :
m_file( NULL ),
m_fileOwner( false )
{
}
LuaStateOutFile::LuaStateOutFile(const char* fileName) :
m_file( NULL ),
m_fileOwner( false )
{
Open(fileName);
}
LuaStateOutFile::~LuaStateOutFile()
{
if ( m_file && m_fileOwner )
fclose( m_file );
}
bool LuaStateOutFile::Open( const char* fileName )
{
Close();
if (fileName[0] == '+')
m_file = fopen( fileName + 1, "a+b" );
else
m_file = fopen( fileName, "wb" );
m_fileOwner = true;
return m_file != NULL;
}
void LuaStateOutFile::Close()
{
if ( m_file && m_fileOwner )
fclose( m_file );
}
void LuaStateOutFile::Print( const char* str, ... )
{
char message[ 800 ];
va_list arglist;
va_start( arglist, str );
vsprintf( message, str, arglist );
va_end( arglist );
fputs( message, m_file );
}
bool LuaStateOutFile::Assign( FILE* file )
{
m_file = file;
m_fileOwner = false;
return true;
}
} // namespace LuaPlus