Add in-repo copy of Lua and use it rather than the system copy
Aegisub needs Lua built as C++ (for stack unwinding on errors). No one packages it like that, so at the moment we can't actually use systme packages for Lua. Fixes a bunch of memory leaks on Automation errors.
This commit is contained in:
parent
33a4a056a4
commit
843e71331f
76 changed files with 17441 additions and 120 deletions
7
.gitmodules
vendored
7
.gitmodules
vendored
|
@ -45,12 +45,7 @@
|
|||
path = vendor/boost
|
||||
url = https://github.com/boostorg/boost.git
|
||||
ignore = dirty
|
||||
[submodule "aegisub/vendor/lua"]
|
||||
path = vendor/lua
|
||||
url = git://github.com/ittner/Lua-experimentation.git
|
||||
branch = lua51
|
||||
ignore = dirty
|
||||
[submodule "aegisub/vendor/fftw"]
|
||||
[submodule "deps/fftw"]
|
||||
path = vendor/fftw
|
||||
url = https://github.com/Aegisub/fftw3.git
|
||||
ignore = dirty
|
||||
|
|
1
Makefile
1
Makefile
|
@ -1,6 +1,7 @@
|
|||
include Makefile.inc
|
||||
|
||||
SUBDIRS += \
|
||||
vendor/lua \
|
||||
vendor/universalchardet \
|
||||
libaegisub \
|
||||
tools \
|
||||
|
|
|
@ -85,12 +85,12 @@ CFLAGS_ICONV = @ICONV_CFLAGS@
|
|||
CFLAGS_ICU = @ICU_I18N_CFLAGS@
|
||||
CFLAGS_LIBASS = @LIBASS_CFLAGS@
|
||||
CFLAGS_LIBCURL = @LIBCURL_CFLAGS@
|
||||
CFLAGS_LUA = @LUA_CFLAGS@
|
||||
CFLAGS_LIBPULSE = @LIBPULSE_CFLAGS@
|
||||
CFLAGS_LUA = -I../vendor/lua/src
|
||||
CFLAGS_OPENAL = @OPENAL_CFLAGS@
|
||||
CFLAGS_OSS = @OSS_CFLAGS@
|
||||
CFLAGS_PORTAUDIO = @PORTAUDIO_CFLAGS@
|
||||
CFLAGS_PTHREAD = @PTHREAD_CFLAGS@
|
||||
CFLAGS_LIBPULSE = @LIBPULSE_CFLAGS@
|
||||
CFLAGS_UCHARDET = -I../vendor/universalchardet
|
||||
|
||||
LIBS_ALSA = @ALSA_LIBS@
|
||||
|
@ -105,7 +105,7 @@ LIBS_ICU = @ICU_UC_LIBS@ @ICU_I18N_LIBS@
|
|||
LIBS_LIBASS = @LIBASS_LIBS@
|
||||
LIBS_LIBCURL = @LIBCURL_LIBS@
|
||||
LIBS_LIBPULSE = @LIBPULSE_LIBS@
|
||||
LIBS_LUA = @LUA_LIBS@
|
||||
LIBS_LUA = ../vendor/lua/liblua-aegisub.a
|
||||
LIBS_OPENAL = @OPENAL_LIBS@
|
||||
LIBS_PORTAUDIO = @PORTAUDIO_LIBS@
|
||||
LIBS_PTHREAD = @PTHREAD_LIBS@
|
||||
|
|
|
@ -139,8 +139,8 @@ $(SUBDIRS):
|
|||
$(MAKE) -C $@ $(MAKECMDGOALS)
|
||||
|
||||
# Set relations to ensure dependencies are built before their targets during parallel builds.
|
||||
automation: libaegisub
|
||||
src: vendor/universalchardet tools libaegisub
|
||||
automation: libaegisub vendor/lua
|
||||
src: vendor/universalchardet vendor/lua tools libaegisub
|
||||
tests: libaegisub
|
||||
tools: libaegisub
|
||||
reporter: src
|
||||
|
|
|
@ -4,11 +4,11 @@ LIB_SHARED = aegisub.so
|
|||
LIB_VERSION = 0.1.0
|
||||
BUILD_LIB = no
|
||||
|
||||
CXXFLAGS += -I../libaegisub/include -I../src $(CXXFLAGS_WX)
|
||||
CXXFLAGS += -I../libaegisub/include -I../src -I ../vendor/lua/src $(CXXFLAGS_WX)
|
||||
CPPFLAGS += $(CPPFLAGS_BOOST)
|
||||
|
||||
LIBS := -L../libaegisub -laegisub $(LIBS)
|
||||
LIBS += $(LIBS_WX) $(LIBS_BOOST) $(LIBS_ICU) $(LIBS_LUA)
|
||||
LIBS := -L../libaegisub -laegisub -L../vendor/lua -llua-aegisub $(LIBS)
|
||||
LIBS += $(LIBS_WX) $(LIBS_BOOST) $(LIBS_ICU)
|
||||
|
||||
SRC += tests/aegisub.cpp ../src/auto4_regex.cpp
|
||||
|
||||
|
|
|
@ -392,10 +392,7 @@
|
|||
<ClCompile Include="$(SrcDir)hotkey.cpp" />
|
||||
<ClCompile Include="$(SrcDir)hotkey_data_view_model.cpp" />
|
||||
<ClCompile Include="$(SrcDir)initial_line_state.cpp" />
|
||||
<ClCompile Include="$(SrcDir)lpeg.c">
|
||||
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||
<ForcedIncludeFiles></ForcedIncludeFiles>
|
||||
</ClCompile>
|
||||
<ClCompile Include="$(SrcDir)lpeg.cpp" />
|
||||
<ClCompile Include="$(SrcDir)main.cpp" />
|
||||
<ClCompile Include="$(SrcDir)menu.cpp" />
|
||||
<ClCompile Include="$(SrcDir)mkv_wrap.cpp" />
|
||||
|
|
|
@ -1226,7 +1226,7 @@
|
|||
<ClCompile Include="$(SrcDir)auto4_regex.cpp">
|
||||
<Filter>Automation\Lua</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="$(SrcDir)lpeg.c">
|
||||
<ClCompile Include="$(SrcDir)lpeg.cpp">
|
||||
<Filter>Automation\Lua</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="$(SrcDir)resolution_resampler.cpp">
|
||||
|
|
|
@ -23,35 +23,35 @@
|
|||
|
||||
<!-- Source files -->
|
||||
<ItemGroup>
|
||||
<ClCompile Include="$(SrcDir)lapi.c" />
|
||||
<ClCompile Include="$(SrcDir)lauxlib.c" />
|
||||
<ClCompile Include="$(SrcDir)lbaselib.c" />
|
||||
<ClCompile Include="$(SrcDir)lcode.c" />
|
||||
<ClCompile Include="$(SrcDir)ldblib.c" />
|
||||
<ClCompile Include="$(SrcDir)ldebug.c" />
|
||||
<ClCompile Include="$(SrcDir)ldo.c" />
|
||||
<ClCompile Include="$(SrcDir)ldump.c" />
|
||||
<ClCompile Include="$(SrcDir)lfunc.c" />
|
||||
<ClCompile Include="$(SrcDir)lgc.c" />
|
||||
<ClCompile Include="$(SrcDir)linit.c" />
|
||||
<ClCompile Include="$(SrcDir)liolib.c" />
|
||||
<ClCompile Include="$(SrcDir)llex.c" />
|
||||
<ClCompile Include="$(SrcDir)lmathlib.c" />
|
||||
<ClCompile Include="$(SrcDir)lmem.c" />
|
||||
<ClCompile Include="$(SrcDir)loadlib.c" />
|
||||
<ClCompile Include="$(SrcDir)lobject.c" />
|
||||
<ClCompile Include="$(SrcDir)lopcodes.c" />
|
||||
<ClCompile Include="$(SrcDir)loslib.c" />
|
||||
<ClCompile Include="$(SrcDir)lparser.c" />
|
||||
<ClCompile Include="$(SrcDir)lstate.c" />
|
||||
<ClCompile Include="$(SrcDir)lstring.c" />
|
||||
<ClCompile Include="$(SrcDir)lstrlib.c" />
|
||||
<ClCompile Include="$(SrcDir)ltable.c" />
|
||||
<ClCompile Include="$(SrcDir)ltablib.c" />
|
||||
<ClCompile Include="$(SrcDir)ltm.c" />
|
||||
<ClCompile Include="$(SrcDir)lundump.c" />
|
||||
<ClCompile Include="$(SrcDir)lvm.c" />
|
||||
<ClCompile Include="$(SrcDir)lzio.c" />
|
||||
<ClCompile Include="$(SrcDir)lapi.cpp" />
|
||||
<ClCompile Include="$(SrcDir)lauxlib.cpp" />
|
||||
<ClCompile Include="$(SrcDir)lbaselib.cpp" />
|
||||
<ClCompile Include="$(SrcDir)lcode.cpp" />
|
||||
<ClCompile Include="$(SrcDir)ldblib.cpp" />
|
||||
<ClCompile Include="$(SrcDir)ldebug.cpp" />
|
||||
<ClCompile Include="$(SrcDir)ldo.cpp" />
|
||||
<ClCompile Include="$(SrcDir)ldump.cpp" />
|
||||
<ClCompile Include="$(SrcDir)lfunc.cpp" />
|
||||
<ClCompile Include="$(SrcDir)lgc.cpp" />
|
||||
<ClCompile Include="$(SrcDir)linit.cpp" />
|
||||
<ClCompile Include="$(SrcDir)liolib.cpp" />
|
||||
<ClCompile Include="$(SrcDir)llex.cpp" />
|
||||
<ClCompile Include="$(SrcDir)lmathlib.cpp" />
|
||||
<ClCompile Include="$(SrcDir)lmem.cpp" />
|
||||
<ClCompile Include="$(SrcDir)loadlib.cpp" />
|
||||
<ClCompile Include="$(SrcDir)lobject.cpp" />
|
||||
<ClCompile Include="$(SrcDir)lopcodes.cpp" />
|
||||
<ClCompile Include="$(SrcDir)loslib.cpp" />
|
||||
<ClCompile Include="$(SrcDir)lparser.cpp" />
|
||||
<ClCompile Include="$(SrcDir)lstate.cpp" />
|
||||
<ClCompile Include="$(SrcDir)lstring.cpp" />
|
||||
<ClCompile Include="$(SrcDir)lstrlib.cpp" />
|
||||
<ClCompile Include="$(SrcDir)ltable.cpp" />
|
||||
<ClCompile Include="$(SrcDir)ltablib.cpp" />
|
||||
<ClCompile Include="$(SrcDir)ltm.cpp" />
|
||||
<ClCompile Include="$(SrcDir)lundump.cpp" />
|
||||
<ClCompile Include="$(SrcDir)lvm.cpp" />
|
||||
<ClCompile Include="$(SrcDir)lzio.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="$(SrcDir)lapi.h" />
|
||||
|
@ -81,7 +81,7 @@
|
|||
|
||||
<Target Name="CopyHeaders" BeforeTargets="Build">
|
||||
<Copy
|
||||
SourceFiles="$(SrcDir)lua.h;$(SrcDir)lualib.h;$(SrcDir)lauxlib.h;$(SrcDir)luaconf.h;$(SrcDir)..\etc\lua.hpp"
|
||||
SourceFiles="$(SrcDir)lua.h;$(SrcDir)lualib.h;$(SrcDir)lauxlib.h;$(SrcDir)luaconf.h"
|
||||
DestinationFolder="$(AegisubSourceBase)include"
|
||||
SkipUnchangedFiles="true"
|
||||
/>
|
||||
|
|
|
@ -15,91 +15,91 @@
|
|||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="$(SrcDir)lapi.c">
|
||||
<ClCompile Include="$(SrcDir)lapi.cpp">
|
||||
<Filter>Core</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="$(SrcDir)lcode.c">
|
||||
<ClCompile Include="$(SrcDir)lcode.cpp">
|
||||
<Filter>Core</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="$(SrcDir)ldo.c">
|
||||
<ClCompile Include="$(SrcDir)ldo.cpp">
|
||||
<Filter>Core</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="$(SrcDir)ldump.c">
|
||||
<ClCompile Include="$(SrcDir)ldump.cpp">
|
||||
<Filter>Core</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="$(SrcDir)lfunc.c">
|
||||
<ClCompile Include="$(SrcDir)lfunc.cpp">
|
||||
<Filter>Core</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="$(SrcDir)lgc.c">
|
||||
<ClCompile Include="$(SrcDir)lgc.cpp">
|
||||
<Filter>Core</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="$(SrcDir)linit.c">
|
||||
<ClCompile Include="$(SrcDir)linit.cpp">
|
||||
<Filter>Core</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="$(SrcDir)llex.c">
|
||||
<ClCompile Include="$(SrcDir)llex.cpp">
|
||||
<Filter>Core</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="$(SrcDir)lmem.c">
|
||||
<ClCompile Include="$(SrcDir)lmem.cpp">
|
||||
<Filter>Core</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="$(SrcDir)lobject.c">
|
||||
<ClCompile Include="$(SrcDir)lobject.cpp">
|
||||
<Filter>Core</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="$(SrcDir)lopcodes.c">
|
||||
<ClCompile Include="$(SrcDir)lopcodes.cpp">
|
||||
<Filter>Core</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="$(SrcDir)lparser.c">
|
||||
<ClCompile Include="$(SrcDir)lparser.cpp">
|
||||
<Filter>Core</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="$(SrcDir)lstate.c">
|
||||
<ClCompile Include="$(SrcDir)lstate.cpp">
|
||||
<Filter>Core</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="$(SrcDir)lstring.c">
|
||||
<ClCompile Include="$(SrcDir)lstring.cpp">
|
||||
<Filter>Core</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="$(SrcDir)ldebug.c">
|
||||
<ClCompile Include="$(SrcDir)ldebug.cpp">
|
||||
<Filter>Core</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="$(SrcDir)ltable.c">
|
||||
<ClCompile Include="$(SrcDir)ltable.cpp">
|
||||
<Filter>Core</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="$(SrcDir)ltm.c">
|
||||
<ClCompile Include="$(SrcDir)ltm.cpp">
|
||||
<Filter>Core</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="$(SrcDir)lundump.c">
|
||||
<ClCompile Include="$(SrcDir)lundump.cpp">
|
||||
<Filter>Core</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="$(SrcDir)lvm.c">
|
||||
<ClCompile Include="$(SrcDir)lvm.cpp">
|
||||
<Filter>Core</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="$(SrcDir)lzio.c">
|
||||
<ClCompile Include="$(SrcDir)lzio.cpp">
|
||||
<Filter>Core</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="$(SrcDir)lbaselib.c">
|
||||
<ClCompile Include="$(SrcDir)lbaselib.cpp">
|
||||
<Filter>Standard library</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="$(SrcDir)ltablib.c">
|
||||
<ClCompile Include="$(SrcDir)ltablib.cpp">
|
||||
<Filter>Standard library</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="$(SrcDir)ldblib.c">
|
||||
<ClCompile Include="$(SrcDir)ldblib.cpp">
|
||||
<Filter>Standard library</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="$(SrcDir)liolib.c">
|
||||
<ClCompile Include="$(SrcDir)liolib.cpp">
|
||||
<Filter>Standard library</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="$(SrcDir)lmathlib.c">
|
||||
<ClCompile Include="$(SrcDir)lmathlib.cpp">
|
||||
<Filter>Standard library</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="$(SrcDir)loslib.c">
|
||||
<ClCompile Include="$(SrcDir)loslib.cpp">
|
||||
<Filter>Standard library</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="$(SrcDir)lstrlib.c">
|
||||
<ClCompile Include="$(SrcDir)lstrlib.cpp">
|
||||
<Filter>Standard library</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="$(SrcDir)loadlib.c">
|
||||
<ClCompile Include="$(SrcDir)loadlib.cpp">
|
||||
<Filter>Core</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="$(SrcDir)lauxlib.c">
|
||||
<ClCompile Include="$(SrcDir)lauxlib.cpp">
|
||||
<Filter>Standard library</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
|
@ -174,4 +174,4 @@
|
|||
<Filter>Internal headers</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
</Project>
|
||||
|
|
32
configure.ac
32
configure.ac
|
@ -383,38 +383,6 @@ AGI_OPT_PKG(ffms2, [build without ffms2 A/V provider [auto]], [Enable FFMS2 supp
|
|||
AGI_OPT_PKG(fftw3, [build without fftw support [auto]], [Enable fftw support])
|
||||
AGI_OPT_PKG(hunspell, [build without hunspell spell-checking [auto]], [Enable Hunspell support])
|
||||
|
||||
############
|
||||
# Automation
|
||||
############
|
||||
# First try pkg-config with several names
|
||||
PKG_CHECK_MODULES(LUA, lua5.1 >= 5.1 lua5.1 < 5.2, [], [
|
||||
PKG_CHECK_MODULES(LUA, lua-5.1 >= 5.1 lua-5.1 < 5.2, [], [
|
||||
PKG_CHECK_MODULES(LUA, lua >= 5.1 lua < 5.2, [], [
|
||||
# Still not found so try to autodetect
|
||||
AS_IF([test -z "$LUA_CFLAGS"],
|
||||
[AGI_FIND_HEADER([LUA], [lua.hpp],
|
||||
[/usr/include/lua5.1 /usr/include/lua51 /usr/local/include/lua51 /usr/local/include/lua5.1 /usr/include /usr/local/include])])
|
||||
|
||||
AS_IF([test -z "$LUA_LIBS"],
|
||||
[AGI_FIND_LIB([LUA], [lua51 lua-5.1 lua5.1 lua], [])])
|
||||
|
||||
AC_AGI_COMPILE([Lua 5.1 (auto4)], [lua], [$LUA_CFLAGS], [$LUA_LIBS],[
|
||||
#include <lua.hpp>
|
||||
|
||||
int main () {
|
||||
lua_State *L = luaL_newstate();
|
||||
lua_pushstring(L, "test");
|
||||
int res = lua_objlen(L, -1) == 4;
|
||||
lua_close(L);
|
||||
return !res;
|
||||
}])
|
||||
AS_IF([test x$agi_cv_with_lua = xno],
|
||||
[AC_MSG_FAILURE([Lua 5.1 could not be found. Try setting LUA_CLFAGS and LUA_LIBS manually])])
|
||||
])])])
|
||||
|
||||
AC_SUBST(LUA_CFLAGS)
|
||||
AC_SUBST(LUA_LIBS)
|
||||
|
||||
######################################################
|
||||
# Debugging support
|
||||
######################################################
|
||||
|
|
|
@ -19,7 +19,7 @@ ifeq (yes, $(BUILD_DARWIN))
|
|||
SRC += osx_utils.mm retina_helper.mm
|
||||
endif
|
||||
|
||||
lpeg.o: CFLAGS += -Wno-unused-function
|
||||
lpeg.o: CXXFLAGS += -Wno-unused-function
|
||||
MatroskaParser.o: CFLAGS += -Wno-sometimes-uninitialized
|
||||
|
||||
###############
|
||||
|
@ -105,8 +105,7 @@ charset_detect.o: CXXFLAGS += -D_X86_
|
|||
font_file_lister_fontconfig.o: CXXFLAGS += $(CFLAGS_FONTCONFIG)
|
||||
text_file_reader.o: CXXFLAGS += -D_X86_
|
||||
video_provider_manager.o: CXXFLAGS += $(CFLAGS_FFMS2)
|
||||
auto4_lua.o auto4_lua_assfile.o auto4_lua_dialog.o auto4_lua_progresssink.o auto4_lua_regex.o auto4_lua_scriptreader.o auto4_regex.o: CXXFLAGS += $(CFLAGS_LUA)
|
||||
lpeg.o: CFLAGS += $(CFLAGS_LUA)
|
||||
auto4_lua.o auto4_lua_assfile.o auto4_lua_dialog.o auto4_lua_progresssink.o auto4_lua_regex.o auto4_lua_scriptreader.o auto4_regex.o lpeg.o: CXXFLAGS += $(CFLAGS_LUA)
|
||||
|
||||
SRC += \
|
||||
MatroskaParser.c \
|
||||
|
@ -197,7 +196,7 @@ SRC += \
|
|||
hotkey.cpp \
|
||||
hotkey_data_view_model.cpp \
|
||||
initial_line_state.cpp \
|
||||
lpeg.c \
|
||||
lpeg.cpp \
|
||||
main.cpp \
|
||||
menu.cpp \
|
||||
mkv_wrap.cpp \
|
||||
|
|
|
@ -295,7 +295,7 @@ namespace {
|
|||
}
|
||||
}
|
||||
|
||||
extern "C" int luaopen_lpeg (lua_State *L);
|
||||
int luaopen_lpeg (lua_State *L);
|
||||
|
||||
namespace Automation4 {
|
||||
int regex_init(lua_State *L);
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
#include <libaegisub/io.h>
|
||||
|
||||
#include <fstream>
|
||||
#include <lua.hpp>
|
||||
#include <lua.h>
|
||||
#include <memory>
|
||||
|
||||
namespace Automation4 {
|
||||
|
|
|
@ -16,10 +16,11 @@
|
|||
|
||||
#include <libaegisub/log.h>
|
||||
|
||||
#include <lua.hpp>
|
||||
|
||||
#include <libaegisub/fs.h>
|
||||
|
||||
#include <lua.h>
|
||||
#include <lualib.h>
|
||||
#include <lauxlib.h>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
#include <wx/string.h>
|
||||
|
|
1
vendor/lua
vendored
1
vendor/lua
vendored
|
@ -1 +0,0 @@
|
|||
Subproject commit 4997ebeaee85a1193d40820f5695d2555a30c39f
|
34
vendor/lua/COPYRIGHT
vendored
Normal file
34
vendor/lua/COPYRIGHT
vendored
Normal file
|
@ -0,0 +1,34 @@
|
|||
Lua License
|
||||
-----------
|
||||
|
||||
Lua is licensed under the terms of the MIT license reproduced below.
|
||||
This means that Lua is free software and can be used for both academic
|
||||
and commercial purposes at absolutely no cost.
|
||||
|
||||
For details and rationale, see http://www.lua.org/license.html .
|
||||
|
||||
===============================================================================
|
||||
|
||||
Copyright (C) 1994-2012 Lua.org, PUC-Rio.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
||||
===============================================================================
|
||||
|
||||
(end of COPYRIGHT)
|
183
vendor/lua/HISTORY
vendored
Normal file
183
vendor/lua/HISTORY
vendored
Normal file
|
@ -0,0 +1,183 @@
|
|||
HISTORY for Lua 5.1
|
||||
|
||||
* Changes from version 5.0 to 5.1
|
||||
-------------------------------
|
||||
Language:
|
||||
+ new module system.
|
||||
+ new semantics for control variables of fors.
|
||||
+ new semantics for setn/getn.
|
||||
+ new syntax/semantics for varargs.
|
||||
+ new long strings and comments.
|
||||
+ new `mod' operator (`%')
|
||||
+ new length operator #t
|
||||
+ metatables for all types
|
||||
API:
|
||||
+ new functions: lua_createtable, lua_get(set)field, lua_push(to)integer.
|
||||
+ user supplies memory allocator (lua_open becomes lua_newstate).
|
||||
+ luaopen_* functions must be called through Lua.
|
||||
Implementation:
|
||||
+ new configuration scheme via luaconf.h.
|
||||
+ incremental garbage collection.
|
||||
+ better handling of end-of-line in the lexer.
|
||||
+ fully reentrant parser (new Lua function `load')
|
||||
+ better support for 64-bit machines.
|
||||
+ native loadlib support for Mac OS X.
|
||||
+ standard distribution in only one library (lualib.a merged into lua.a)
|
||||
|
||||
* Changes from version 4.0 to 5.0
|
||||
-------------------------------
|
||||
Language:
|
||||
+ lexical scoping.
|
||||
+ Lua coroutines.
|
||||
+ standard libraries now packaged in tables.
|
||||
+ tags replaced by metatables and tag methods replaced by metamethods,
|
||||
stored in metatables.
|
||||
+ proper tail calls.
|
||||
+ each function can have its own global table, which can be shared.
|
||||
+ new __newindex metamethod, called when we insert a new key into a table.
|
||||
+ new block comments: --[[ ... ]].
|
||||
+ new generic for.
|
||||
+ new weak tables.
|
||||
+ new boolean type.
|
||||
+ new syntax "local function".
|
||||
+ (f()) returns the first value returned by f.
|
||||
+ {f()} fills a table with all values returned by f.
|
||||
+ \n ignored in [[\n .
|
||||
+ fixed and-or priorities.
|
||||
+ more general syntax for function definition (e.g. function a.x.y:f()...end).
|
||||
+ more general syntax for function calls (e.g. (print or write)(9)).
|
||||
+ new functions (time/date, tmpfile, unpack, require, load*, etc.).
|
||||
API:
|
||||
+ chunks are loaded by using lua_load; new luaL_loadfile and luaL_loadbuffer.
|
||||
+ introduced lightweight userdata, a simple "void*" without a metatable.
|
||||
+ new error handling protocol: the core no longer prints error messages;
|
||||
all errors are reported to the caller on the stack.
|
||||
+ new lua_atpanic for host cleanup.
|
||||
+ new, signal-safe, hook scheme.
|
||||
Implementation:
|
||||
+ new license: MIT.
|
||||
+ new, faster, register-based virtual machine.
|
||||
+ support for external multithreading and coroutines.
|
||||
+ new and consistent error message format.
|
||||
+ the core no longer needs "stdio.h" for anything (except for a single
|
||||
use of sprintf to convert numbers to strings).
|
||||
+ lua.c now runs the environment variable LUA_INIT, if present. It can
|
||||
be "@filename", to run a file, or the chunk itself.
|
||||
+ support for user extensions in lua.c.
|
||||
sample implementation given for command line editing.
|
||||
+ new dynamic loading library, active by default on several platforms.
|
||||
+ safe garbage-collector metamethods.
|
||||
+ precompiled bytecodes checked for integrity (secure binary dostring).
|
||||
+ strings are fully aligned.
|
||||
+ position capture in string.find.
|
||||
+ read('*l') can read lines with embedded zeros.
|
||||
|
||||
* Changes from version 3.2 to 4.0
|
||||
-------------------------------
|
||||
Language:
|
||||
+ new "break" and "for" statements (both numerical and for tables).
|
||||
+ uniform treatment of globals: globals are now stored in a Lua table.
|
||||
+ improved error messages.
|
||||
+ no more '$debug': full speed *and* full debug information.
|
||||
+ new read form: read(N) for next N bytes.
|
||||
+ general read patterns now deprecated.
|
||||
(still available with -DCOMPAT_READPATTERNS.)
|
||||
+ all return values are passed as arguments for the last function
|
||||
(old semantics still available with -DLUA_COMPAT_ARGRET)
|
||||
+ garbage collection tag methods for tables now deprecated.
|
||||
+ there is now only one tag method for order.
|
||||
API:
|
||||
+ New API: fully re-entrant, simpler, and more efficient.
|
||||
+ New debug API.
|
||||
Implementation:
|
||||
+ faster than ever: cleaner virtual machine and new hashing algorithm.
|
||||
+ non-recursive garbage-collector algorithm.
|
||||
+ reduced memory usage for programs with many strings.
|
||||
+ improved treatment for memory allocation errors.
|
||||
+ improved support for 16-bit machines (we hope).
|
||||
+ code now compiles unmodified as both ANSI C and C++.
|
||||
+ numbers in bases other than 10 are converted using strtoul.
|
||||
+ new -f option in Lua to support #! scripts.
|
||||
+ luac can now combine text and binaries.
|
||||
|
||||
* Changes from version 3.1 to 3.2
|
||||
-------------------------------
|
||||
+ redirected all output in Lua's core to _ERRORMESSAGE and _ALERT.
|
||||
+ increased limit on the number of constants and globals per function
|
||||
(from 2^16 to 2^24).
|
||||
+ debugging info (lua_debug and hooks) moved into lua_state and new API
|
||||
functions provided to get and set this info.
|
||||
+ new debug lib gives full debugging access within Lua.
|
||||
+ new table functions "foreachi", "sort", "tinsert", "tremove", "getn".
|
||||
+ new io functions "flush", "seek".
|
||||
|
||||
* Changes from version 3.0 to 3.1
|
||||
-------------------------------
|
||||
+ NEW FEATURE: anonymous functions with closures (via "upvalues").
|
||||
+ new syntax:
|
||||
- local variables in chunks.
|
||||
- better scope control with DO block END.
|
||||
- constructors can now be also written: { record-part; list-part }.
|
||||
- more general syntax for function calls and lvalues, e.g.:
|
||||
f(x).y=1
|
||||
o:f(x,y):g(z)
|
||||
f"string" is sugar for f("string")
|
||||
+ strings may now contain arbitrary binary data (e.g., embedded zeros).
|
||||
+ major code re-organization and clean-up; reduced module interdependecies.
|
||||
+ no arbitrary limits on the total number of constants and globals.
|
||||
+ support for multiple global contexts.
|
||||
+ better syntax error messages.
|
||||
+ new traversal functions "foreach" and "foreachvar".
|
||||
+ the default for numbers is now double.
|
||||
changing it to use floats or longs is easy.
|
||||
+ complete debug information stored in pre-compiled chunks.
|
||||
+ sample interpreter now prompts user when run interactively, and also
|
||||
handles control-C interruptions gracefully.
|
||||
|
||||
* Changes from version 2.5 to 3.0
|
||||
-------------------------------
|
||||
+ NEW CONCEPT: "tag methods".
|
||||
Tag methods replace fallbacks as the meta-mechanism for extending the
|
||||
semantics of Lua. Whereas fallbacks had a global nature, tag methods
|
||||
work on objects having the same tag (e.g., groups of tables).
|
||||
Existing code that uses fallbacks should work without change.
|
||||
+ new, general syntax for constructors {[exp] = exp, ... }.
|
||||
+ support for handling variable number of arguments in functions (varargs).
|
||||
+ support for conditional compilation ($if ... $else ... $end).
|
||||
+ cleaner semantics in API simplifies host code.
|
||||
+ better support for writing libraries (auxlib.h).
|
||||
+ better type checking and error messages in the standard library.
|
||||
+ luac can now also undump.
|
||||
|
||||
* Changes from version 2.4 to 2.5
|
||||
-------------------------------
|
||||
+ io and string libraries are now based on pattern matching;
|
||||
the old libraries are still available for compatibility
|
||||
+ dofile and dostring can now return values (via return statement)
|
||||
+ better support for 16- and 64-bit machines
|
||||
+ expanded documentation, with more examples
|
||||
|
||||
* Changes from version 2.2 to 2.4
|
||||
-------------------------------
|
||||
+ external compiler creates portable binary files that can be loaded faster
|
||||
+ interface for debugging and profiling
|
||||
+ new "getglobal" fallback
|
||||
+ new functions for handling references to Lua objects
|
||||
+ new functions in standard lib
|
||||
+ only one copy of each string is stored
|
||||
+ expanded documentation, with more examples
|
||||
|
||||
* Changes from version 2.1 to 2.2
|
||||
-------------------------------
|
||||
+ functions now may be declared with any "lvalue" as a name
|
||||
+ garbage collection of functions
|
||||
+ support for pipes
|
||||
|
||||
* Changes from version 1.1 to 2.1
|
||||
-------------------------------
|
||||
+ object-oriented support
|
||||
+ fallbacks
|
||||
+ simplified syntax for tables
|
||||
+ many internal improvements
|
||||
|
||||
(end of HISTORY)
|
99
vendor/lua/INSTALL
vendored
Normal file
99
vendor/lua/INSTALL
vendored
Normal file
|
@ -0,0 +1,99 @@
|
|||
INSTALL for Lua 5.1
|
||||
|
||||
* Building Lua
|
||||
------------
|
||||
Lua is built in the src directory, but the build process can be
|
||||
controlled from the top-level Makefile.
|
||||
|
||||
Building Lua on Unix systems should be very easy. First do "make" and
|
||||
see if your platform is listed. If so, just do "make xxx", where xxx
|
||||
is your platform name. The platforms currently supported are:
|
||||
aix ansi bsd freebsd generic linux macosx mingw posix solaris
|
||||
|
||||
If your platform is not listed, try the closest one or posix, generic,
|
||||
ansi, in this order.
|
||||
|
||||
See below for customization instructions and for instructions on how
|
||||
to build with other Windows compilers.
|
||||
|
||||
If you want to check that Lua has been built correctly, do "make test"
|
||||
after building Lua. Also, have a look at the example programs in test.
|
||||
|
||||
* Installing Lua
|
||||
--------------
|
||||
Once you have built Lua, you may want to install it in an official
|
||||
place in your system. In this case, do "make install". The official
|
||||
place and the way to install files are defined in Makefile. You must
|
||||
have the right permissions to install files.
|
||||
|
||||
If you want to build and install Lua in one step, do "make xxx install",
|
||||
where xxx is your platform name.
|
||||
|
||||
If you want to install Lua locally, then do "make local". This will
|
||||
create directories bin, include, lib, man, and install Lua there as
|
||||
follows:
|
||||
|
||||
bin: lua luac
|
||||
include: lua.h luaconf.h lualib.h lauxlib.h lua.hpp
|
||||
lib: liblua.a
|
||||
man/man1: lua.1 luac.1
|
||||
|
||||
These are the only directories you need for development.
|
||||
|
||||
There are man pages for lua and luac, in both nroff and html, and a
|
||||
reference manual in html in doc, some sample code in test, and some
|
||||
useful stuff in etc. You don't need these directories for development.
|
||||
|
||||
If you want to install Lua locally, but in some other directory, do
|
||||
"make install INSTALL_TOP=xxx", where xxx is your chosen directory.
|
||||
|
||||
See below for instructions for Windows and other systems.
|
||||
|
||||
* Customization
|
||||
-------------
|
||||
Three things can be customized by editing a file:
|
||||
- Where and how to install Lua -- edit Makefile.
|
||||
- How to build Lua -- edit src/Makefile.
|
||||
- Lua features -- edit src/luaconf.h.
|
||||
|
||||
You don't actually need to edit the Makefiles because you may set the
|
||||
relevant variables when invoking make.
|
||||
|
||||
On the other hand, if you need to select some Lua features, you'll need
|
||||
to edit src/luaconf.h. The edited file will be the one installed, and
|
||||
it will be used by any Lua clients that you build, to ensure consistency.
|
||||
|
||||
We strongly recommend that you enable dynamic loading. This is done
|
||||
automatically for all platforms listed above that have this feature
|
||||
(and also Windows). See src/luaconf.h and also src/Makefile.
|
||||
|
||||
* Building Lua on Windows and other systems
|
||||
-----------------------------------------
|
||||
If you're not using the usual Unix tools, then the instructions for
|
||||
building Lua depend on the compiler you use. You'll need to create
|
||||
projects (or whatever your compiler uses) for building the library,
|
||||
the interpreter, and the compiler, as follows:
|
||||
|
||||
library: lapi.c lcode.c ldebug.c ldo.c ldump.c lfunc.c lgc.c llex.c
|
||||
lmem.c lobject.c lopcodes.c lparser.c lstate.c lstring.c
|
||||
ltable.c ltm.c lundump.c lvm.c lzio.c
|
||||
lauxlib.c lbaselib.c ldblib.c liolib.c lmathlib.c loslib.c
|
||||
ltablib.c lstrlib.c loadlib.c linit.c
|
||||
|
||||
interpreter: library, lua.c
|
||||
|
||||
compiler: library, luac.c print.c
|
||||
|
||||
If you use Visual Studio .NET, you can use etc/luavs.bat in its
|
||||
"Command Prompt".
|
||||
|
||||
If all you want is to build the Lua interpreter, you may put all .c files
|
||||
in a single project, except for luac.c and print.c. Or just use etc/all.c.
|
||||
|
||||
To use Lua as a library in your own programs, you'll need to know how to
|
||||
create and use libraries with your compiler.
|
||||
|
||||
As mentioned above, you may edit luaconf.h to select some features before
|
||||
building Lua.
|
||||
|
||||
(end of INSTALL)
|
45
vendor/lua/Makefile
vendored
Normal file
45
vendor/lua/Makefile
vendored
Normal file
|
@ -0,0 +1,45 @@
|
|||
include ../../Makefile.inc
|
||||
|
||||
LIB = liblua-aegisub.a
|
||||
|
||||
CXXFLAGS += -Wno-empty-body -Wno-deprecated-declarations
|
||||
|
||||
SRC = \
|
||||
src/lapi.cpp \
|
||||
src/lauxlib.cpp \
|
||||
src/lbaselib.cpp \
|
||||
src/lcode.cpp \
|
||||
src/ldblib.cpp \
|
||||
src/ldebug.cpp \
|
||||
src/ldo.cpp \
|
||||
src/ldump.cpp \
|
||||
src/lfunc.cpp \
|
||||
src/lgc.cpp \
|
||||
src/linit.cpp \
|
||||
src/liolib.cpp \
|
||||
src/llex.cpp \
|
||||
src/lmathlib.cpp \
|
||||
src/lmem.cpp \
|
||||
src/loadlib.cpp \
|
||||
src/lobject.cpp \
|
||||
src/lopcodes.cpp \
|
||||
src/loslib.cpp \
|
||||
src/lparser.cpp \
|
||||
src/lstate.cpp \
|
||||
src/lstring.cpp \
|
||||
src/lstrlib.cpp \
|
||||
src/ltable.cpp \
|
||||
src/ltablib.cpp \
|
||||
src/ltm.cpp \
|
||||
src/lua.cpp \
|
||||
src/luac.cpp \
|
||||
src/lundump.cpp \
|
||||
src/lvm.cpp \
|
||||
src/lzio.cpp \
|
||||
src/print.cpp
|
||||
|
||||
HEADER = src/*.h
|
||||
|
||||
include ../../Makefile.target
|
||||
-include src/*.d
|
||||
|
37
vendor/lua/README
vendored
Normal file
37
vendor/lua/README
vendored
Normal file
|
@ -0,0 +1,37 @@
|
|||
README for Lua 5.1
|
||||
|
||||
See INSTALL for installation instructions.
|
||||
See HISTORY for a summary of changes since the last released version.
|
||||
|
||||
* What is Lua?
|
||||
------------
|
||||
Lua is a powerful, light-weight programming language designed for extending
|
||||
applications. Lua is also frequently used as a general-purpose, stand-alone
|
||||
language. Lua is free software.
|
||||
|
||||
For complete information, visit Lua's web site at http://www.lua.org/ .
|
||||
For an executive summary, see http://www.lua.org/about.html .
|
||||
|
||||
Lua has been used in many different projects around the world.
|
||||
For a short list, see http://www.lua.org/uses.html .
|
||||
|
||||
* Availability
|
||||
------------
|
||||
Lua is freely available for both academic and commercial purposes.
|
||||
See COPYRIGHT and http://www.lua.org/license.html for details.
|
||||
Lua can be downloaded at http://www.lua.org/download.html .
|
||||
|
||||
* Installation
|
||||
------------
|
||||
Lua is implemented in pure ANSI C, and compiles unmodified in all known
|
||||
platforms that have an ANSI C compiler. In most Unix-like platforms, simply
|
||||
do "make" with a suitable target. See INSTALL for detailed instructions.
|
||||
|
||||
* Origin
|
||||
------
|
||||
Lua is developed at Lua.org, a laboratory of the Department of Computer
|
||||
Science of PUC-Rio (the Pontifical Catholic University of Rio de Janeiro
|
||||
in Brazil).
|
||||
For more information about the authors, see http://www.lua.org/authors.html .
|
||||
|
||||
(end of README)
|
1087
vendor/lua/src/lapi.cpp
vendored
Normal file
1087
vendor/lua/src/lapi.cpp
vendored
Normal file
File diff suppressed because it is too large
Load diff
16
vendor/lua/src/lapi.h
vendored
Normal file
16
vendor/lua/src/lapi.h
vendored
Normal file
|
@ -0,0 +1,16 @@
|
|||
/*
|
||||
** $Id: lapi.h,v 2.2.1.1 2007/12/27 13:02:25 roberto Exp $
|
||||
** Auxiliary functions from Lua API
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
|
||||
#ifndef lapi_h
|
||||
#define lapi_h
|
||||
|
||||
|
||||
#include "lobject.h"
|
||||
|
||||
|
||||
LUAI_FUNC void luaA_pushobject (lua_State *L, const TValue *o);
|
||||
|
||||
#endif
|
652
vendor/lua/src/lauxlib.cpp
vendored
Normal file
652
vendor/lua/src/lauxlib.cpp
vendored
Normal file
|
@ -0,0 +1,652 @@
|
|||
/*
|
||||
** $Id: lauxlib.c,v 1.159.1.3 2008/01/21 13:20:51 roberto Exp $
|
||||
** Auxiliary functions for building Lua libraries
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
|
||||
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
/* This file uses only the official API of Lua.
|
||||
** Any function declared here could be written as an application function.
|
||||
*/
|
||||
|
||||
#define lauxlib_c
|
||||
#define LUA_LIB
|
||||
|
||||
#include "lua.h"
|
||||
|
||||
#include "lauxlib.h"
|
||||
|
||||
|
||||
#define FREELIST_REF 0 /* free list of references */
|
||||
|
||||
|
||||
/* convert a stack index to positive */
|
||||
#define abs_index(L, i) ((i) > 0 || (i) <= LUA_REGISTRYINDEX ? (i) : \
|
||||
lua_gettop(L) + (i) + 1)
|
||||
|
||||
|
||||
/*
|
||||
** {======================================================
|
||||
** Error-report functions
|
||||
** =======================================================
|
||||
*/
|
||||
|
||||
|
||||
LUALIB_API int luaL_argerror (lua_State *L, int narg, const char *extramsg) {
|
||||
lua_Debug ar;
|
||||
if (!lua_getstack(L, 0, &ar)) /* no stack frame? */
|
||||
return luaL_error(L, "bad argument #%d (%s)", narg, extramsg);
|
||||
lua_getinfo(L, "n", &ar);
|
||||
if (strcmp(ar.namewhat, "method") == 0) {
|
||||
narg--; /* do not count `self' */
|
||||
if (narg == 0) /* error is in the self argument itself? */
|
||||
return luaL_error(L, "calling " LUA_QS " on bad self (%s)",
|
||||
ar.name, extramsg);
|
||||
}
|
||||
if (ar.name == NULL)
|
||||
ar.name = "?";
|
||||
return luaL_error(L, "bad argument #%d to " LUA_QS " (%s)",
|
||||
narg, ar.name, extramsg);
|
||||
}
|
||||
|
||||
|
||||
LUALIB_API int luaL_typerror (lua_State *L, int narg, const char *tname) {
|
||||
const char *msg = lua_pushfstring(L, "%s expected, got %s",
|
||||
tname, luaL_typename(L, narg));
|
||||
return luaL_argerror(L, narg, msg);
|
||||
}
|
||||
|
||||
|
||||
static void tag_error (lua_State *L, int narg, int tag) {
|
||||
luaL_typerror(L, narg, lua_typename(L, tag));
|
||||
}
|
||||
|
||||
|
||||
LUALIB_API void luaL_where (lua_State *L, int level) {
|
||||
lua_Debug ar;
|
||||
if (lua_getstack(L, level, &ar)) { /* check function at level */
|
||||
lua_getinfo(L, "Sl", &ar); /* get info about it */
|
||||
if (ar.currentline > 0) { /* is there info? */
|
||||
lua_pushfstring(L, "%s:%d: ", ar.short_src, ar.currentline);
|
||||
return;
|
||||
}
|
||||
}
|
||||
lua_pushliteral(L, ""); /* else, no information available... */
|
||||
}
|
||||
|
||||
|
||||
LUALIB_API int luaL_error (lua_State *L, const char *fmt, ...) {
|
||||
va_list argp;
|
||||
va_start(argp, fmt);
|
||||
luaL_where(L, 1);
|
||||
lua_pushvfstring(L, fmt, argp);
|
||||
va_end(argp);
|
||||
lua_concat(L, 2);
|
||||
return lua_error(L);
|
||||
}
|
||||
|
||||
/* }====================================================== */
|
||||
|
||||
|
||||
LUALIB_API int luaL_checkoption (lua_State *L, int narg, const char *def,
|
||||
const char *const lst[]) {
|
||||
const char *name = (def) ? luaL_optstring(L, narg, def) :
|
||||
luaL_checkstring(L, narg);
|
||||
int i;
|
||||
for (i=0; lst[i]; i++)
|
||||
if (strcmp(lst[i], name) == 0)
|
||||
return i;
|
||||
return luaL_argerror(L, narg,
|
||||
lua_pushfstring(L, "invalid option " LUA_QS, name));
|
||||
}
|
||||
|
||||
|
||||
LUALIB_API int luaL_newmetatable (lua_State *L, const char *tname) {
|
||||
lua_getfield(L, LUA_REGISTRYINDEX, tname); /* get registry.name */
|
||||
if (!lua_isnil(L, -1)) /* name already in use? */
|
||||
return 0; /* leave previous value on top, but return 0 */
|
||||
lua_pop(L, 1);
|
||||
lua_newtable(L); /* create metatable */
|
||||
lua_pushvalue(L, -1);
|
||||
lua_setfield(L, LUA_REGISTRYINDEX, tname); /* registry.name = metatable */
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
LUALIB_API void *luaL_checkudata (lua_State *L, int ud, const char *tname) {
|
||||
void *p = lua_touserdata(L, ud);
|
||||
if (p != NULL) { /* value is a userdata? */
|
||||
if (lua_getmetatable(L, ud)) { /* does it have a metatable? */
|
||||
lua_getfield(L, LUA_REGISTRYINDEX, tname); /* get correct metatable */
|
||||
if (lua_rawequal(L, -1, -2)) { /* does it have the correct mt? */
|
||||
lua_pop(L, 2); /* remove both metatables */
|
||||
return p;
|
||||
}
|
||||
}
|
||||
}
|
||||
luaL_typerror(L, ud, tname); /* else error */
|
||||
return NULL; /* to avoid warnings */
|
||||
}
|
||||
|
||||
|
||||
LUALIB_API void luaL_checkstack (lua_State *L, int space, const char *mes) {
|
||||
if (!lua_checkstack(L, space))
|
||||
luaL_error(L, "stack overflow (%s)", mes);
|
||||
}
|
||||
|
||||
|
||||
LUALIB_API void luaL_checktype (lua_State *L, int narg, int t) {
|
||||
if (lua_type(L, narg) != t)
|
||||
tag_error(L, narg, t);
|
||||
}
|
||||
|
||||
|
||||
LUALIB_API void luaL_checkany (lua_State *L, int narg) {
|
||||
if (lua_type(L, narg) == LUA_TNONE)
|
||||
luaL_argerror(L, narg, "value expected");
|
||||
}
|
||||
|
||||
|
||||
LUALIB_API const char *luaL_checklstring (lua_State *L, int narg, size_t *len) {
|
||||
const char *s = lua_tolstring(L, narg, len);
|
||||
if (!s) tag_error(L, narg, LUA_TSTRING);
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
LUALIB_API const char *luaL_optlstring (lua_State *L, int narg,
|
||||
const char *def, size_t *len) {
|
||||
if (lua_isnoneornil(L, narg)) {
|
||||
if (len)
|
||||
*len = (def ? strlen(def) : 0);
|
||||
return def;
|
||||
}
|
||||
else return luaL_checklstring(L, narg, len);
|
||||
}
|
||||
|
||||
|
||||
LUALIB_API lua_Number luaL_checknumber (lua_State *L, int narg) {
|
||||
lua_Number d = lua_tonumber(L, narg);
|
||||
if (d == 0 && !lua_isnumber(L, narg)) /* avoid extra test when d is not 0 */
|
||||
tag_error(L, narg, LUA_TNUMBER);
|
||||
return d;
|
||||
}
|
||||
|
||||
|
||||
LUALIB_API lua_Number luaL_optnumber (lua_State *L, int narg, lua_Number def) {
|
||||
return luaL_opt(L, luaL_checknumber, narg, def);
|
||||
}
|
||||
|
||||
|
||||
LUALIB_API lua_Integer luaL_checkinteger (lua_State *L, int narg) {
|
||||
lua_Integer d = lua_tointeger(L, narg);
|
||||
if (d == 0 && !lua_isnumber(L, narg)) /* avoid extra test when d is not 0 */
|
||||
tag_error(L, narg, LUA_TNUMBER);
|
||||
return d;
|
||||
}
|
||||
|
||||
|
||||
LUALIB_API lua_Integer luaL_optinteger (lua_State *L, int narg,
|
||||
lua_Integer def) {
|
||||
return luaL_opt(L, luaL_checkinteger, narg, def);
|
||||
}
|
||||
|
||||
|
||||
LUALIB_API int luaL_getmetafield (lua_State *L, int obj, const char *event) {
|
||||
if (!lua_getmetatable(L, obj)) /* no metatable? */
|
||||
return 0;
|
||||
lua_pushstring(L, event);
|
||||
lua_rawget(L, -2);
|
||||
if (lua_isnil(L, -1)) {
|
||||
lua_pop(L, 2); /* remove metatable and metafield */
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
lua_remove(L, -2); /* remove only metatable */
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
LUALIB_API int luaL_callmeta (lua_State *L, int obj, const char *event) {
|
||||
obj = abs_index(L, obj);
|
||||
if (!luaL_getmetafield(L, obj, event)) /* no metafield? */
|
||||
return 0;
|
||||
lua_pushvalue(L, obj);
|
||||
lua_call(L, 1, 1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
LUALIB_API void (luaL_register) (lua_State *L, const char *libname,
|
||||
const luaL_Reg *l) {
|
||||
luaI_openlib(L, libname, l, 0);
|
||||
}
|
||||
|
||||
|
||||
static int libsize (const luaL_Reg *l) {
|
||||
int size = 0;
|
||||
for (; l->name; l++) size++;
|
||||
return size;
|
||||
}
|
||||
|
||||
|
||||
LUALIB_API void luaI_openlib (lua_State *L, const char *libname,
|
||||
const luaL_Reg *l, int nup) {
|
||||
if (libname) {
|
||||
int size = libsize(l);
|
||||
/* check whether lib already exists */
|
||||
luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED", 1);
|
||||
lua_getfield(L, -1, libname); /* get _LOADED[libname] */
|
||||
if (!lua_istable(L, -1)) { /* not found? */
|
||||
lua_pop(L, 1); /* remove previous result */
|
||||
/* try global variable (and create one if it does not exist) */
|
||||
if (luaL_findtable(L, LUA_GLOBALSINDEX, libname, size) != NULL)
|
||||
luaL_error(L, "name conflict for module " LUA_QS, libname);
|
||||
lua_pushvalue(L, -1);
|
||||
lua_setfield(L, -3, libname); /* _LOADED[libname] = new table */
|
||||
}
|
||||
lua_remove(L, -2); /* remove _LOADED table */
|
||||
lua_insert(L, -(nup+1)); /* move library table to below upvalues */
|
||||
}
|
||||
for (; l->name; l++) {
|
||||
int i;
|
||||
for (i=0; i<nup; i++) /* copy upvalues to the top */
|
||||
lua_pushvalue(L, -nup);
|
||||
lua_pushcclosure(L, l->func, nup);
|
||||
lua_setfield(L, -(nup+2), l->name);
|
||||
}
|
||||
lua_pop(L, nup); /* remove upvalues */
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
** {======================================================
|
||||
** getn-setn: size for arrays
|
||||
** =======================================================
|
||||
*/
|
||||
|
||||
#if defined(LUA_COMPAT_GETN)
|
||||
|
||||
static int checkint (lua_State *L, int topop) {
|
||||
int n = (lua_type(L, -1) == LUA_TNUMBER) ? lua_tointeger(L, -1) : -1;
|
||||
lua_pop(L, topop);
|
||||
return n;
|
||||
}
|
||||
|
||||
|
||||
static void getsizes (lua_State *L) {
|
||||
lua_getfield(L, LUA_REGISTRYINDEX, "LUA_SIZES");
|
||||
if (lua_isnil(L, -1)) { /* no `size' table? */
|
||||
lua_pop(L, 1); /* remove nil */
|
||||
lua_newtable(L); /* create it */
|
||||
lua_pushvalue(L, -1); /* `size' will be its own metatable */
|
||||
lua_setmetatable(L, -2);
|
||||
lua_pushliteral(L, "kv");
|
||||
lua_setfield(L, -2, "__mode"); /* metatable(N).__mode = "kv" */
|
||||
lua_pushvalue(L, -1);
|
||||
lua_setfield(L, LUA_REGISTRYINDEX, "LUA_SIZES"); /* store in register */
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
LUALIB_API void luaL_setn (lua_State *L, int t, int n) {
|
||||
t = abs_index(L, t);
|
||||
lua_pushliteral(L, "n");
|
||||
lua_rawget(L, t);
|
||||
if (checkint(L, 1) >= 0) { /* is there a numeric field `n'? */
|
||||
lua_pushliteral(L, "n"); /* use it */
|
||||
lua_pushinteger(L, n);
|
||||
lua_rawset(L, t);
|
||||
}
|
||||
else { /* use `sizes' */
|
||||
getsizes(L);
|
||||
lua_pushvalue(L, t);
|
||||
lua_pushinteger(L, n);
|
||||
lua_rawset(L, -3); /* sizes[t] = n */
|
||||
lua_pop(L, 1); /* remove `sizes' */
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
LUALIB_API int luaL_getn (lua_State *L, int t) {
|
||||
int n;
|
||||
t = abs_index(L, t);
|
||||
lua_pushliteral(L, "n"); /* try t.n */
|
||||
lua_rawget(L, t);
|
||||
if ((n = checkint(L, 1)) >= 0) return n;
|
||||
getsizes(L); /* else try sizes[t] */
|
||||
lua_pushvalue(L, t);
|
||||
lua_rawget(L, -2);
|
||||
if ((n = checkint(L, 2)) >= 0) return n;
|
||||
return (int)lua_objlen(L, t);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* }====================================================== */
|
||||
|
||||
|
||||
|
||||
LUALIB_API const char *luaL_gsub (lua_State *L, const char *s, const char *p,
|
||||
const char *r) {
|
||||
const char *wild;
|
||||
size_t l = strlen(p);
|
||||
luaL_Buffer b;
|
||||
luaL_buffinit(L, &b);
|
||||
while ((wild = strstr(s, p)) != NULL) {
|
||||
luaL_addlstring(&b, s, wild - s); /* push prefix */
|
||||
luaL_addstring(&b, r); /* push replacement in place of pattern */
|
||||
s = wild + l; /* continue after `p' */
|
||||
}
|
||||
luaL_addstring(&b, s); /* push last suffix */
|
||||
luaL_pushresult(&b);
|
||||
return lua_tostring(L, -1);
|
||||
}
|
||||
|
||||
|
||||
LUALIB_API const char *luaL_findtable (lua_State *L, int idx,
|
||||
const char *fname, int szhint) {
|
||||
const char *e;
|
||||
lua_pushvalue(L, idx);
|
||||
do {
|
||||
e = strchr(fname, '.');
|
||||
if (e == NULL) e = fname + strlen(fname);
|
||||
lua_pushlstring(L, fname, e - fname);
|
||||
lua_rawget(L, -2);
|
||||
if (lua_isnil(L, -1)) { /* no such field? */
|
||||
lua_pop(L, 1); /* remove this nil */
|
||||
lua_createtable(L, 0, (*e == '.' ? 1 : szhint)); /* new table for field */
|
||||
lua_pushlstring(L, fname, e - fname);
|
||||
lua_pushvalue(L, -2);
|
||||
lua_settable(L, -4); /* set new table into field */
|
||||
}
|
||||
else if (!lua_istable(L, -1)) { /* field has a non-table value? */
|
||||
lua_pop(L, 2); /* remove table and value */
|
||||
return fname; /* return problematic part of the name */
|
||||
}
|
||||
lua_remove(L, -2); /* remove previous table */
|
||||
fname = e + 1;
|
||||
} while (*e == '.');
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
** {======================================================
|
||||
** Generic Buffer manipulation
|
||||
** =======================================================
|
||||
*/
|
||||
|
||||
|
||||
#define bufflen(B) ((B)->p - (B)->buffer)
|
||||
#define bufffree(B) ((size_t)(LUAL_BUFFERSIZE - bufflen(B)))
|
||||
|
||||
#define LIMIT (LUA_MINSTACK/2)
|
||||
|
||||
|
||||
static int emptybuffer (luaL_Buffer *B) {
|
||||
size_t l = bufflen(B);
|
||||
if (l == 0) return 0; /* put nothing on stack */
|
||||
else {
|
||||
lua_pushlstring(B->L, B->buffer, l);
|
||||
B->p = B->buffer;
|
||||
B->lvl++;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void adjuststack (luaL_Buffer *B) {
|
||||
if (B->lvl > 1) {
|
||||
lua_State *L = B->L;
|
||||
int toget = 1; /* number of levels to concat */
|
||||
size_t toplen = lua_strlen(L, -1);
|
||||
do {
|
||||
size_t l = lua_strlen(L, -(toget+1));
|
||||
if (B->lvl - toget + 1 >= LIMIT || toplen > l) {
|
||||
toplen += l;
|
||||
toget++;
|
||||
}
|
||||
else break;
|
||||
} while (toget < B->lvl);
|
||||
lua_concat(L, toget);
|
||||
B->lvl = B->lvl - toget + 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
LUALIB_API char *luaL_prepbuffer (luaL_Buffer *B) {
|
||||
if (emptybuffer(B))
|
||||
adjuststack(B);
|
||||
return B->buffer;
|
||||
}
|
||||
|
||||
|
||||
LUALIB_API void luaL_addlstring (luaL_Buffer *B, const char *s, size_t l) {
|
||||
while (l--)
|
||||
luaL_addchar(B, *s++);
|
||||
}
|
||||
|
||||
|
||||
LUALIB_API void luaL_addstring (luaL_Buffer *B, const char *s) {
|
||||
luaL_addlstring(B, s, strlen(s));
|
||||
}
|
||||
|
||||
|
||||
LUALIB_API void luaL_pushresult (luaL_Buffer *B) {
|
||||
emptybuffer(B);
|
||||
lua_concat(B->L, B->lvl);
|
||||
B->lvl = 1;
|
||||
}
|
||||
|
||||
|
||||
LUALIB_API void luaL_addvalue (luaL_Buffer *B) {
|
||||
lua_State *L = B->L;
|
||||
size_t vl;
|
||||
const char *s = lua_tolstring(L, -1, &vl);
|
||||
if (vl <= bufffree(B)) { /* fit into buffer? */
|
||||
memcpy(B->p, s, vl); /* put it there */
|
||||
B->p += vl;
|
||||
lua_pop(L, 1); /* remove from stack */
|
||||
}
|
||||
else {
|
||||
if (emptybuffer(B))
|
||||
lua_insert(L, -2); /* put buffer before new value */
|
||||
B->lvl++; /* add new value into B stack */
|
||||
adjuststack(B);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
LUALIB_API void luaL_buffinit (lua_State *L, luaL_Buffer *B) {
|
||||
B->L = L;
|
||||
B->p = B->buffer;
|
||||
B->lvl = 0;
|
||||
}
|
||||
|
||||
/* }====================================================== */
|
||||
|
||||
|
||||
LUALIB_API int luaL_ref (lua_State *L, int t) {
|
||||
int ref;
|
||||
t = abs_index(L, t);
|
||||
if (lua_isnil(L, -1)) {
|
||||
lua_pop(L, 1); /* remove from stack */
|
||||
return LUA_REFNIL; /* `nil' has a unique fixed reference */
|
||||
}
|
||||
lua_rawgeti(L, t, FREELIST_REF); /* get first free element */
|
||||
ref = (int)lua_tointeger(L, -1); /* ref = t[FREELIST_REF] */
|
||||
lua_pop(L, 1); /* remove it from stack */
|
||||
if (ref != 0) { /* any free element? */
|
||||
lua_rawgeti(L, t, ref); /* remove it from list */
|
||||
lua_rawseti(L, t, FREELIST_REF); /* (t[FREELIST_REF] = t[ref]) */
|
||||
}
|
||||
else { /* no free elements */
|
||||
ref = (int)lua_objlen(L, t);
|
||||
ref++; /* create new reference */
|
||||
}
|
||||
lua_rawseti(L, t, ref);
|
||||
return ref;
|
||||
}
|
||||
|
||||
|
||||
LUALIB_API void luaL_unref (lua_State *L, int t, int ref) {
|
||||
if (ref >= 0) {
|
||||
t = abs_index(L, t);
|
||||
lua_rawgeti(L, t, FREELIST_REF);
|
||||
lua_rawseti(L, t, ref); /* t[ref] = t[FREELIST_REF] */
|
||||
lua_pushinteger(L, ref);
|
||||
lua_rawseti(L, t, FREELIST_REF); /* t[FREELIST_REF] = ref */
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
** {======================================================
|
||||
** Load functions
|
||||
** =======================================================
|
||||
*/
|
||||
|
||||
typedef struct LoadF {
|
||||
int extraline;
|
||||
FILE *f;
|
||||
char buff[LUAL_BUFFERSIZE];
|
||||
} LoadF;
|
||||
|
||||
|
||||
static const char *getF (lua_State *L, void *ud, size_t *size) {
|
||||
LoadF *lf = (LoadF *)ud;
|
||||
(void)L;
|
||||
if (lf->extraline) {
|
||||
lf->extraline = 0;
|
||||
*size = 1;
|
||||
return "\n";
|
||||
}
|
||||
if (feof(lf->f)) return NULL;
|
||||
*size = fread(lf->buff, 1, sizeof(lf->buff), lf->f);
|
||||
return (*size > 0) ? lf->buff : NULL;
|
||||
}
|
||||
|
||||
|
||||
static int errfile (lua_State *L, const char *what, int fnameindex) {
|
||||
const char *serr = strerror(errno);
|
||||
const char *filename = lua_tostring(L, fnameindex) + 1;
|
||||
lua_pushfstring(L, "cannot %s %s: %s", what, filename, serr);
|
||||
lua_remove(L, fnameindex);
|
||||
return LUA_ERRFILE;
|
||||
}
|
||||
|
||||
|
||||
LUALIB_API int luaL_loadfile (lua_State *L, const char *filename) {
|
||||
LoadF lf;
|
||||
int status, readstatus;
|
||||
int c;
|
||||
int fnameindex = lua_gettop(L) + 1; /* index of filename on the stack */
|
||||
lf.extraline = 0;
|
||||
if (filename == NULL) {
|
||||
lua_pushliteral(L, "=stdin");
|
||||
lf.f = stdin;
|
||||
}
|
||||
else {
|
||||
lua_pushfstring(L, "@%s", filename);
|
||||
lf.f = fopen(filename, "r");
|
||||
if (lf.f == NULL) return errfile(L, "open", fnameindex);
|
||||
}
|
||||
c = getc(lf.f);
|
||||
if (c == '#') { /* Unix exec. file? */
|
||||
lf.extraline = 1;
|
||||
while ((c = getc(lf.f)) != EOF && c != '\n') ; /* skip first line */
|
||||
if (c == '\n') c = getc(lf.f);
|
||||
}
|
||||
if (c == LUA_SIGNATURE[0] && filename) { /* binary file? */
|
||||
lf.f = freopen(filename, "rb", lf.f); /* reopen in binary mode */
|
||||
if (lf.f == NULL) return errfile(L, "reopen", fnameindex);
|
||||
/* skip eventual `#!...' */
|
||||
while ((c = getc(lf.f)) != EOF && c != LUA_SIGNATURE[0]) ;
|
||||
lf.extraline = 0;
|
||||
}
|
||||
ungetc(c, lf.f);
|
||||
status = lua_load(L, getF, &lf, lua_tostring(L, -1));
|
||||
readstatus = ferror(lf.f);
|
||||
if (filename) fclose(lf.f); /* close file (even in case of errors) */
|
||||
if (readstatus) {
|
||||
lua_settop(L, fnameindex); /* ignore results from `lua_load' */
|
||||
return errfile(L, "read", fnameindex);
|
||||
}
|
||||
lua_remove(L, fnameindex);
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
typedef struct LoadS {
|
||||
const char *s;
|
||||
size_t size;
|
||||
} LoadS;
|
||||
|
||||
|
||||
static const char *getS (lua_State *L, void *ud, size_t *size) {
|
||||