2011-09-28 21:45:16 +02:00
|
|
|
// Copyright (c) 2011, Thomas Goyne <plorkyeran@aegisub.org>
|
2007-05-01 23:51:49 +02:00
|
|
|
//
|
2011-09-28 21:45:16 +02:00
|
|
|
// Permission to use, copy, modify, and distribute this software for any
|
|
|
|
// purpose with or without fee is hereby granted, provided that the above
|
|
|
|
// copyright notice and this permission notice appear in all copies.
|
2007-05-01 23:51:49 +02:00
|
|
|
//
|
2011-09-28 21:45:16 +02:00
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
2009-07-29 07:43:02 +02:00
|
|
|
|
|
|
|
/// @file auto4_lua_scriptreader.cpp
|
|
|
|
/// @brief Script-file reader for Lua 5.1-based scripting engine
|
|
|
|
/// @ingroup scripting
|
|
|
|
///
|
2007-05-01 23:51:49 +02:00
|
|
|
|
2009-01-04 07:31:48 +01:00
|
|
|
#include "config.h"
|
|
|
|
|
2008-03-05 00:17:07 +01:00
|
|
|
#ifdef WITH_AUTO4_LUA
|
2007-12-31 07:46:22 +01:00
|
|
|
|
2007-05-01 23:51:49 +02:00
|
|
|
#include "auto4_lua_scriptreader.h"
|
|
|
|
|
2011-09-28 21:45:16 +02:00
|
|
|
#include <libaegisub/io.h>
|
|
|
|
#include <libaegisub/charset_conv.h>
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
2011-09-28 21:45:16 +02:00
|
|
|
#include "charset_detect.h"
|
|
|
|
#include "compat.h"
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
2011-09-28 21:45:16 +02:00
|
|
|
namespace Automation4 {
|
|
|
|
LuaScriptReader::LuaScriptReader(wxString const& filename)
|
|
|
|
: conv(new agi::charset::IconvWrapper(CharSetDetect::GetEncoding(filename).c_str(), "utf-8", false))
|
|
|
|
, file(agi::io::Open(STD_STR(filename)))
|
2007-05-01 23:51:49 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-09-28 21:45:16 +02:00
|
|
|
LuaScriptReader::~LuaScriptReader() { }
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
2011-09-28 21:45:16 +02:00
|
|
|
const char *LuaScriptReader::Read(size_t *bytes_read) {
|
|
|
|
char in_buf[512];
|
|
|
|
file->read(in_buf, sizeof(in_buf));
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
2011-09-28 21:45:16 +02:00
|
|
|
const char *in = in_buf;
|
|
|
|
char *out = buf;
|
|
|
|
size_t in_bytes = file->gcount();
|
|
|
|
size_t out_bytes = sizeof(buf);
|
2007-05-01 23:51:49 +02:00
|
|
|
|
2011-09-28 21:45:16 +02:00
|
|
|
conv->Convert(&in, &in_bytes, &out, &out_bytes);
|
|
|
|
*bytes_read = out - buf;
|
2007-05-01 23:51:49 +02:00
|
|
|
|
2011-09-28 21:45:16 +02:00
|
|
|
// Skip the bom
|
|
|
|
if (*bytes_read >= 3 && buf[0] == -17 && buf[1] == -69 && buf[2] == -65) {
|
|
|
|
*bytes_read -= 3;
|
|
|
|
return buf + 3;
|
2007-05-01 23:51:49 +02:00
|
|
|
}
|
2011-09-28 21:45:16 +02:00
|
|
|
return buf;
|
2007-05-01 23:51:49 +02:00
|
|
|
}
|
|
|
|
|
2011-09-28 21:45:16 +02:00
|
|
|
const char* LuaScriptReader::reader_func(lua_State *, void *data, size_t *size) {
|
|
|
|
return static_cast<LuaScriptReader*>(data)->Read(size);
|
|
|
|
}
|
2011-12-28 22:27:06 +01:00
|
|
|
}
|
2007-12-31 07:46:22 +01:00
|
|
|
|
2008-03-05 00:17:07 +01:00
|
|
|
#endif // WITH_AUTO4_LUA
|