mirror of
https://github.com/holub/mame
synced 2025-06-05 20:33:45 +03:00
Merge remote-tracking branch 'refs/remotes/mamedev/master'
This commit is contained in:
commit
5b4df8299c
1
.drone.sec
Normal file
1
.drone.sec
Normal file
@ -0,0 +1 @@
|
||||
eyJhbGciOiJSU0EtT0FFUCIsImVuYyI6IkExMjhHQ00ifQ.doN0hM3F1JcAqSRhxCrxPkeVEUj0cLHZ74LchLsP7JFE4-9udW0VQRRVEeQ8rrqtOb7X2am-hI2s9aLp6nq9duMdToFP5bJaUC0yxtAPCZbMgEZVB1BBxl04pgafswVXHUVR_yC4ToZlzuiKvsz1tjB2wFmyxowqqfbJILJVScobwYvIt5Mxp60A9vqBb1Xg77pR9EqYRmUiff_3Vrs4CEm2l39MXVuG8kwy9NOmJ3EStiVCh8iP0JwD-ZLBi3IMGGcGX73RyrNPAyFgwoXDEvSBflURc7ge3336wjfi2e7edeVmHBP-BhrI6Tng1BqyaNplZMtxZZ9vN-NqWYsXMg.4fOuhgSIsHgPVx6P.l9pmIM652sG1JvnBGjj-Aqr9k1U243w4acruslIkWcAzD9rxQOBK18011eQ3QyuFW4T1EjPvQMKflfGJNaPA74B2Is7HmSzG1NWrBkS0hv7uyf_WNwA83kdcoD0lyahtMG_td8AN4L7dlh0rh8BmOaPYHQ.VX42VcsvXuj9zYiZ41rzGg
|
46
.drone.yml
Normal file
46
.drone.yml
Normal file
@ -0,0 +1,46 @@
|
||||
# Build configure for https://www.tea-ci.org (fork of Drone CI with Msys2 support)
|
||||
# 32-bit until release including https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;a=commitdiff;h=0aa738220bb9dea2ad479e484560767b36701947
|
||||
build:
|
||||
image: teaci/msys32
|
||||
shell: mingw32
|
||||
pull: true
|
||||
branches:
|
||||
-master
|
||||
environment:
|
||||
- SUBTARGET=tiny
|
||||
- MINGW32=/c/msys32/mingw32
|
||||
- MAME_EXE=mametiny.exe
|
||||
# - SOURCES=src/mame/drivers/pacman.cpp
|
||||
commands:
|
||||
# - pacman -S -q --noprogressbar --noconfirm winpty
|
||||
- make
|
||||
- ./$MAME_EXE -validate && echo "Validation successful"
|
||||
|
||||
notify:
|
||||
irc:
|
||||
prefix: build
|
||||
nick: $$IRC_USER
|
||||
channel: mame-dev
|
||||
server:
|
||||
host: $$IRC_HOST
|
||||
port: $$IRC_PORT
|
||||
password: $$IRC_PASS
|
||||
tls: true
|
||||
when:
|
||||
success: false
|
||||
failure: true
|
||||
change: true
|
||||
|
||||
# Need to regen secrets file (.drone.sec) from within tea-ci.org to enable
|
||||
#notify:
|
||||
# email:
|
||||
# from: git@mamedev.org
|
||||
# host: $$EMAIL_SERVER
|
||||
# username: $$EMAIL_USERNAME
|
||||
# password: $$EMAIL_PASSWORD
|
||||
# recipients:
|
||||
# - $$EMAIL_LISTADDR
|
||||
# when:
|
||||
# success: false
|
||||
# failure: false
|
||||
# change: true
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -27,6 +27,7 @@
|
||||
!/tests/
|
||||
!/doxygen/
|
||||
!/web/
|
||||
!/.drone.yml
|
||||
!/.gitattributes
|
||||
!/.gitignore
|
||||
!/.travis.yml
|
||||
|
14
.travis.yml
14
.travis.yml
@ -19,8 +19,7 @@ matrix:
|
||||
- os: linux
|
||||
compiler: clang
|
||||
env:
|
||||
- SUBTARGET=arcade MAME=mamearcade64 LDOPTS="-Wl,-no-keep-memory"
|
||||
- SUBTARGET=mess MAME=mess64
|
||||
- SUBTARGET=tiny MAME=mametiny64
|
||||
script:
|
||||
- if [ $TRAVIS_OS_NAME == 'linux' ]; then
|
||||
if [ $CC == 'clang' ]; then
|
||||
@ -28,19 +27,20 @@ script:
|
||||
else make -j4 OPTIMIZE=0 OVERRIDE_CC="gcc-5" OVERRIDE_CXX="g++-5" && ./$MAME -validate;
|
||||
fi
|
||||
elif [ $TRAVIS_OS_NAME == 'osx' ]; then
|
||||
unset LDOPTS && make -j2 OPTIMIZE=0 MACOSX_USE_LIBSDL=1 && ./$MAME -validate;
|
||||
unset LDOPTS && make -j2 OPTIMIZE=0 USE_LIBSDL=1 && ./$MAME -validate;
|
||||
fi
|
||||
sudo: required
|
||||
before_install:
|
||||
- "if [ ${TRAVIS_OS_NAME:-'linux'} = 'linux' ]; then sudo add-apt-repository ppa:zoogie/sdl2-snapshots -y; fi"
|
||||
- "if [ ${TRAVIS_OS_NAME:-'linux'} = 'linux' ]; then sudo add-apt-repository ppa:shahar-evron/qt-backports -y; fi"
|
||||
- "if [ ${TRAVIS_OS_NAME:-'linux'} = 'linux' ]; then sudo add-apt-repository ppa:beineri/opt-qt551 -y; fi"
|
||||
- "if [ ${TRAVIS_OS_NAME:-'linux'} = 'linux' ]; then sudo apt-get update -qq; fi"
|
||||
- "if [ ${TRAVIS_OS_NAME:-'linux'} = 'linux' ]; then sudo apt-get install -y --force-yes libsdl2-dev libsdl2-ttf-dev libasound2-dev libqt4-dev libqt4-dev-bin; fi"
|
||||
- "if [ ${TRAVIS_OS_NAME:-'linux'} = 'linux' ]; then sudo apt-get install -y --force-yes libsdl2-dev libsdl2-ttf-dev libasound2-dev qt55base qt55quickcontrols qt55declarative qt55tools qt55svg; fi"
|
||||
- "if [ ${TRAVIS_OS_NAME:-'linux'} = 'linux' ]; then source /opt/qt55/bin/qt55-env.sh; fi"
|
||||
- "if [ ${TRAVIS_OS_NAME:-'linux'} = 'osx' ]; then brew update; fi"
|
||||
- "if [ ${TRAVIS_OS_NAME:-'linux'} = 'osx' ]; then brew install sdl2 sdl2_ttf; fi"
|
||||
branches:
|
||||
only:
|
||||
- master
|
||||
notifications:
|
||||
email:
|
||||
- secure: "sK8JJcn1A0yLnbDJ/7vmJgESuXmP6D4QlvQvsYLp1xAx5eTVSJ5Z+GSXLBJ9CnoeJ5AlPVPX4rXdRV93UyxYlTh1O97x8VZZQtYBNPRjk/VCflsOOg7C+jcJKX/knMu/QG2MVEDE5G2b8mHSAgWljG/7Z2N0rYZlWppwklYafOkyW4uE0E7PU5XpmKim4ra6Y1eDSbap+XJiDwgUm9moDZrgAv7eom9NIWGNMRIozSRyR2IkYimlWE92FOy5PzLJtFGK02iumbYN+39mTux59v/h/m6HD6cD7Wf10Lco9+Fnmi9Bs+VvIReJIP9pDABRvJ3MkUV4I9BjUT9xk48lzxqjGtdfUwOMDOTABd4Pb/5cmNtyNUQIosy5oiplR6USBnqD7/gmJw+mfn3A+jdQHGne+akypwzUjSM6XrezjTiZLlDDG+QpA0kwAnxSXw8H2SpVyynMSn4nu0iZmOiOZMtFY0jKlt/W7OFC5wTuJFrky+bBGlVIv3KGOTJNJNgasXV4u0NXOjHyeBFpFYCIf0FZLfYyf7ITu94JxUzXGcVi5D0lBwvKY9HfJ4yJxciyfH6V7yU1+o23E/Meqe/tjt6dTW8DM5xIokrnusfzE5b0zw5GFyg54nbpazXpcPnrMdxhp+t2C7xKrxcZXhBECRYegj+Z86D9BJP/yum1YrQ="
|
||||
email: false
|
||||
|
6
3rdparty/README.md
vendored
6
3rdparty/README.md
vendored
@ -20,16 +20,12 @@ glm - [The MIT License (MIT)](http://opensource.org/licenses/MIT)
|
||||
|
||||
googletest - [The BSD 3-Clause License](http://opensource.org/licenses/BSD-3-Clause)
|
||||
|
||||
http-parser - [The MIT License (MIT)](http://opensource.org/licenses/MIT)
|
||||
|
||||
libflac - [The BSD 3-Clause License](http://opensource.org/licenses/BSD-3-Clause)
|
||||
|
||||
libjpeg - [Custom BSD-like](https://github.com/numenta/nupic/blob/master/external/licenses/LICENSE.libjpeg-6b.txt)
|
||||
|
||||
libuv - [Node License (BSD-like)](https://github.com/mamedev/mame/blob/master/3rdparty/libuv/LICENSE)
|
||||
|
||||
lsqlite3 - [The MIT License (MIT)](http://opensource.org/licenses/MIT)
|
||||
|
||||
lua - [The MIT License (MIT)](http://opensource.org/licenses/MIT)
|
||||
|
||||
lua-zlib - [The MIT License (MIT)](http://opensource.org/licenses/MIT)
|
||||
@ -52,8 +48,6 @@ sdl2 - [zlib license](http://opensource.org/licenses/Zlib)
|
||||
|
||||
softfloat - [U.C. Berkeley open-source license](https://github.com/mamedev/mame/blob/master/3rdparty/softfloat/README.txt) MIT compatible
|
||||
|
||||
sqlite3 - Public Domain
|
||||
|
||||
winpcap - [The BSD 3-Clause License](http://opensource.org/licenses/BSD-3-Clause)
|
||||
|
||||
zlib - [zlib license](http://opensource.org/licenses/Zlib)
|
||||
|
274
3rdparty/bgfx/3rdparty/ocornut-imgui/imgui.cpp
vendored
274
3rdparty/bgfx/3rdparty/ocornut-imgui/imgui.cpp
vendored
@ -457,7 +457,6 @@
|
||||
The list below consist mostly of notes of things to do before they are requested/discussed by users (at that point it usually happens on the github)
|
||||
|
||||
- doc: add a proper documentation+regression testing system (#435)
|
||||
- window: maximum window size settings (per-axis). for large popups in particular user may not want the popup to fill all space.
|
||||
- window: add a way for very transient windows (non-saved, temporary overlay over hundreds of objects) to "clean" up from the global window list. perhaps a lightweight explicit cleanup pass.
|
||||
- window: calling SetNextWindowSize() every frame with <= 0 doesn't do anything, may be useful to allow (particularly when used for a single axis).
|
||||
- window: auto-fit feedback loop when user relies on any dynamic layout (window width multiplier, column) appears weird to end-user. clarify.
|
||||
@ -611,6 +610,7 @@
|
||||
#include <math.h> // sqrtf, fabsf, fmodf, powf, cosf, sinf, floorf, ceilf
|
||||
#include <stdlib.h> // NULL, malloc, free, qsort, atoi
|
||||
#include <stdio.h> // vsnprintf, sscanf, printf
|
||||
#include <limits.h> // INT_MIN, INT_MAX
|
||||
#if defined(_MSC_VER) && _MSC_VER <= 1500 // MSVC 2008 or earlier
|
||||
#include <stddef.h> // intptr_t
|
||||
#else
|
||||
@ -867,9 +867,6 @@ void ImGuiIO::AddInputCharactersUTF8(const char* utf8_chars)
|
||||
|
||||
#define IM_F32_TO_INT8(_VAL) ((int)((_VAL) * 255.0f + 0.5f))
|
||||
|
||||
#define IM_INT_MIN (-2147483647-1)
|
||||
#define IM_INT_MAX (2147483647)
|
||||
|
||||
// Play it nice with Windows users. Notepad in 2015 still doesn't display text data with Unix-style \n.
|
||||
#ifdef _WIN32
|
||||
#define IM_NEWLINE "\r\n"
|
||||
@ -1611,6 +1608,86 @@ float ImGuiSimpleColumns::CalcExtraSpace(float avail_w)
|
||||
return ImMax(0.0f, avail_w - Width);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// ImGuiListClipper
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
static void SetCursorPosYAndSetupDummyPrevLine(float pos_y, float line_height)
|
||||
{
|
||||
// Setting those fields so that SetScrollHere() can properly function after the end of our clipper usage.
|
||||
// If we end up needing more accurate data (to e.g. use SameLine) we may as well make the clipper have a fourth step to let user process and display the last item in their list.
|
||||
ImGui::SetCursorPosY(pos_y);
|
||||
ImGuiWindow* window = ImGui::GetCurrentWindow();
|
||||
window->DC.CursorPosPrevLine.y = window->DC.CursorPos.y - line_height;
|
||||
window->DC.PrevLineHeight = (line_height - GImGui->Style.ItemSpacing.y);
|
||||
}
|
||||
|
||||
// Use case A: Begin() called from constructor with items_height<0, then called again from Sync() in StepNo 1
|
||||
// Use case B: Begin() called from constructor with items_height>0
|
||||
// FIXME-LEGACY: Ideally we should remove the Begin/End functions but they are part of the legacy API we still support. This is why some of the code in Step() calling Begin() and reassign some fields, spaghetti style.
|
||||
void ImGuiListClipper::Begin(int count, float items_height)
|
||||
{
|
||||
StartPosY = ImGui::GetCursorPosY();
|
||||
ItemsHeight = items_height;
|
||||
ItemsCount = count;
|
||||
StepNo = 0;
|
||||
DisplayEnd = DisplayStart = -1;
|
||||
if (ItemsHeight > 0.0f)
|
||||
{
|
||||
ImGui::CalcListClipping(ItemsCount, ItemsHeight, &DisplayStart, &DisplayEnd); // calculate how many to clip/display
|
||||
if (DisplayStart > 0)
|
||||
SetCursorPosYAndSetupDummyPrevLine(StartPosY + DisplayStart * ItemsHeight, ItemsHeight); // advance cursor
|
||||
StepNo = 2;
|
||||
}
|
||||
}
|
||||
|
||||
void ImGuiListClipper::End()
|
||||
{
|
||||
if (ItemsCount < 0)
|
||||
return;
|
||||
// In theory here we should assert that ImGui::GetCursorPosY() == StartPosY + DisplayEnd * ItemsHeight, but it feels saner to just seek at the end and not assert/crash the user.
|
||||
if (ItemsCount < INT_MAX)
|
||||
SetCursorPosYAndSetupDummyPrevLine(StartPosY + ItemsCount * ItemsHeight, ItemsHeight); // advance cursor
|
||||
ItemsCount = -1;
|
||||
StepNo = 3;
|
||||
}
|
||||
|
||||
bool ImGuiListClipper::Step()
|
||||
{
|
||||
if (ItemsCount == 0 || ImGui::GetCurrentWindowRead()->SkipItems)
|
||||
{
|
||||
ItemsCount = -1;
|
||||
return false;
|
||||
}
|
||||
if (StepNo == 0) // Step 0: the clipper let you process the first element, regardless of it being visible or not, so we can measure the element height.
|
||||
{
|
||||
DisplayStart = 0;
|
||||
DisplayEnd = 1;
|
||||
StartPosY = ImGui::GetCursorPosY();
|
||||
StepNo = 1;
|
||||
return true;
|
||||
}
|
||||
if (StepNo == 1) // Step 1: the clipper infer height from first element, calculate the actual range of elements to display, and position the cursor before the first element.
|
||||
{
|
||||
if (ItemsCount == 1) { ItemsCount = -1; return false; }
|
||||
float items_height = ImGui::GetCursorPosY() - StartPosY;
|
||||
IM_ASSERT(items_height > 0.0f); // If this triggers, it means Item 0 hasn't moved the cursor vertically
|
||||
ImGui::SetCursorPosY(StartPosY); // Rewind cursor so we can Begin() again, this time with a known height.
|
||||
Begin(ItemsCount, items_height);
|
||||
StepNo = 3;
|
||||
return true;
|
||||
}
|
||||
if (StepNo == 2) // Step 2: dummy step only required if an explicit items_height was passed to constructor or Begin() and user still call Step(). Does nothing and switch to Step 3.
|
||||
{
|
||||
IM_ASSERT(DisplayStart >= 0 && DisplayEnd >= 0);
|
||||
StepNo = 3;
|
||||
return true;
|
||||
}
|
||||
if (StepNo == 3) // Step 3: the clipper validate that we have reached the expected Y position (corresponding to element DisplayEnd), advance the cursor to the end of the list and then returns 'false' to end the loop.
|
||||
End();
|
||||
return false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// ImGuiWindow
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -1659,8 +1736,8 @@ ImGuiWindow::ImGuiWindow(const char* name)
|
||||
ParentWindow = NULL;
|
||||
|
||||
FocusIdxAllCounter = FocusIdxTabCounter = -1;
|
||||
FocusIdxAllRequestCurrent = FocusIdxTabRequestCurrent = IM_INT_MAX;
|
||||
FocusIdxAllRequestNext = FocusIdxTabRequestNext = IM_INT_MAX;
|
||||
FocusIdxAllRequestCurrent = FocusIdxTabRequestCurrent = INT_MAX;
|
||||
FocusIdxAllRequestNext = FocusIdxTabRequestNext = INT_MAX;
|
||||
}
|
||||
|
||||
ImGuiWindow::~ImGuiWindow()
|
||||
@ -1824,7 +1901,7 @@ bool ImGui::FocusableItemRegister(ImGuiWindow* window, bool is_active, bool tab_
|
||||
|
||||
// Process keyboard input at this point: TAB, Shift-TAB switch focus
|
||||
// We can always TAB out of a widget that doesn't allow tabbing in.
|
||||
if (tab_stop && window->FocusIdxAllRequestNext == IM_INT_MAX && window->FocusIdxTabRequestNext == IM_INT_MAX && is_active && IsKeyPressedMap(ImGuiKey_Tab))
|
||||
if (tab_stop && window->FocusIdxAllRequestNext == INT_MAX && window->FocusIdxTabRequestNext == INT_MAX && is_active && IsKeyPressedMap(ImGuiKey_Tab))
|
||||
{
|
||||
// Modulo on index will be applied at the end of frame once we've got the total counter of items.
|
||||
window->FocusIdxTabRequestNext = window->FocusIdxTabCounter + (g.IO.KeyShift ? (allow_keyboard_focus ? -1 : 0) : +1);
|
||||
@ -2882,18 +2959,8 @@ ImVec2 ImGui::CalcTextSize(const char* text, const char* text_end, bool hide_tex
|
||||
}
|
||||
|
||||
// Helper to calculate coarse clipping of large list of evenly sized items.
|
||||
// NB: Prefer using the ImGuiListClipper higher-level helper if you can!
|
||||
// NB: Prefer using the ImGuiListClipper higher-level helper if you can! Read comments and instructions there on how those use this sort of pattern.
|
||||
// NB: 'items_count' is only used to clamp the result, if you don't know your count you can use INT_MAX
|
||||
// If you are displaying thousands of items and you have a random access to the list, you can perform clipping yourself to save on CPU.
|
||||
// {
|
||||
// float item_height = ImGui::GetTextLineHeightWithSpacing();
|
||||
// int display_start, display_end;
|
||||
// ImGui::CalcListClipping(count, item_height, &display_start, &display_end); // calculate how many to clip/display
|
||||
// ImGui::SetCursorPosY(ImGui::GetCursorPosY() + (display_start) * item_height); // advance cursor
|
||||
// for (int i = display_start; i < display_end; i++) // display only visible items
|
||||
// // TODO: display visible item
|
||||
// ImGui::SetCursorPosY(ImGui::GetCursorPosY() + (count - display_end) * item_height); // advance cursor
|
||||
// }
|
||||
void ImGui::CalcListClipping(int items_count, float items_height, int* out_items_display_start, int* out_items_display_end)
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
@ -2905,6 +2972,11 @@ void ImGui::CalcListClipping(int items_count, float items_height, int* out_items
|
||||
*out_items_display_end = items_count;
|
||||
return;
|
||||
}
|
||||
if (window->SkipItems)
|
||||
{
|
||||
*out_items_display_start = *out_items_display_end = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
const ImVec2 pos = window->DC.CursorPos;
|
||||
int start = (int)((window->ClipRect.Min.y - pos.y) / items_height);
|
||||
@ -3347,7 +3419,7 @@ static inline void ClearSetNextWindowData()
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
g.SetNextWindowPosCond = g.SetNextWindowSizeCond = g.SetNextWindowContentSizeCond = g.SetNextWindowCollapsedCond = 0;
|
||||
g.SetNextWindowFocus = false;
|
||||
g.SetNextWindowSizeConstraint = g.SetNextWindowFocus = false;
|
||||
}
|
||||
|
||||
static bool BeginPopupEx(const char* str_id, ImGuiWindowFlags extra_flags)
|
||||
@ -3548,12 +3620,12 @@ static void CheckStacksSize(ImGuiWindow* window, bool write)
|
||||
// NOT checking: DC.ItemWidth, DC.AllowKeyboardFocus, DC.ButtonRepeat, DC.TextWrapPos (per window) to allow user to conveniently push once and not pop (they are cleared on Begin)
|
||||
ImGuiContext& g = *GImGui;
|
||||
int* p_backup = &window->DC.StackSizesBackup[0];
|
||||
{ int current = window->IDStack.Size; if (write) *p_backup = current; else IM_ASSERT(*p_backup == current); p_backup++; } // User forgot PopID()
|
||||
{ int current = window->DC.GroupStack.Size; if (write) *p_backup = current; else IM_ASSERT(*p_backup == current); p_backup++; } // User forgot EndGroup()
|
||||
{ int current = g.CurrentPopupStack.Size; if (write) *p_backup = current; else IM_ASSERT(*p_backup == current); p_backup++; } // User forgot EndPopup()/EndMenu()
|
||||
{ int current = g.ColorModifiers.Size; if (write) *p_backup = current; else IM_ASSERT(*p_backup == current); p_backup++; } // User forgot PopStyleColor()
|
||||
{ int current = g.StyleModifiers.Size; if (write) *p_backup = current; else IM_ASSERT(*p_backup == current); p_backup++; } // User forgot PopStyleVar()
|
||||
{ int current = g.FontStack.Size; if (write) *p_backup = current; else IM_ASSERT(*p_backup == current); p_backup++; } // User forgot PopFont()
|
||||
{ int current = window->IDStack.Size; if (write) *p_backup = current; else IM_ASSERT(*p_backup == current && "PushID/PopID Mismatch!"); p_backup++; } // User forgot PopID()
|
||||
{ int current = window->DC.GroupStack.Size; if (write) *p_backup = current; else IM_ASSERT(*p_backup == current && "BeginGroup/EndGroup Mismatch!"); p_backup++; } // User forgot EndGroup()
|
||||
{ int current = g.CurrentPopupStack.Size; if (write) *p_backup = current; else IM_ASSERT(*p_backup == current && "BeginMenu/EndMenu or BeginPopup/EndPopup Mismatch"); p_backup++; }// User forgot EndPopup()/EndMenu()
|
||||
{ int current = g.ColorModifiers.Size; if (write) *p_backup = current; else IM_ASSERT(*p_backup == current && "PushStyleColor/PopStyleColor Mismatch!"); p_backup++; } // User forgot PopStyleColor()
|
||||
{ int current = g.StyleModifiers.Size; if (write) *p_backup = current; else IM_ASSERT(*p_backup == current && "PushStyleVar/PopStyleVar Mismatch!"); p_backup++; } // User forgot PopStyleVar()
|
||||
{ int current = g.FontStack.Size; if (write) *p_backup = current; else IM_ASSERT(*p_backup == current && "PushFont/PopFont Mismatch!"); p_backup++; } // User forgot PopFont()
|
||||
IM_ASSERT(p_backup == window->DC.StackSizesBackup + IM_ARRAYSIZE(window->DC.StackSizesBackup));
|
||||
}
|
||||
|
||||
@ -3662,6 +3734,31 @@ static ImGuiWindow* CreateNewWindow(const char* name, ImVec2 size, ImGuiWindowFl
|
||||
return window;
|
||||
}
|
||||
|
||||
static void ApplySizeFullWithConstraint(ImGuiWindow* window, ImVec2 new_size)
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
if (g.SetNextWindowSizeConstraint)
|
||||
{
|
||||
// Using -1,-1 on either X/Y axis to preserve the current size.
|
||||
ImRect cr = g.SetNextWindowSizeConstraintRect;
|
||||
new_size.x = (cr.Min.x >= 0 && cr.Max.x >= 0) ? ImClamp(new_size.x, cr.Min.x, cr.Max.x) : window->SizeFull.x;
|
||||
new_size.y = (cr.Min.y >= 0 && cr.Max.y >= 0) ? ImClamp(new_size.y, cr.Min.y, cr.Max.y) : window->SizeFull.y;
|
||||
if (g.SetNextWindowSizeConstraintCallback)
|
||||
{
|
||||
ImGuiSizeConstraintCallbackData data;
|
||||
data.UserData = g.SetNextWindowSizeConstraintCallbackUserData;
|
||||
data.Pos = window->Pos;
|
||||
data.CurrentSize = window->SizeFull;
|
||||
data.DesiredSize = new_size;
|
||||
g.SetNextWindowSizeConstraintCallback(&data);
|
||||
new_size = data.DesiredSize;
|
||||
}
|
||||
}
|
||||
if (!(window->Flags & (ImGuiWindowFlags_ChildWindow | ImGuiWindowFlags_AlwaysAutoResize)))
|
||||
new_size = ImMax(new_size, g.Style.WindowMinSize);
|
||||
window->SizeFull = new_size;
|
||||
}
|
||||
|
||||
// Push a new ImGui window to add widgets to.
|
||||
// - A default window called "Debug" is automatically stacked at the beginning of every frame so you can use widgets without explicitly calling a Begin/End pair.
|
||||
// - Begin/End can be called multiple times during the frame with the same window name to append content.
|
||||
@ -3727,7 +3824,7 @@ bool ImGui::Begin(const char* name, bool* p_open, const ImVec2& size_on_first_us
|
||||
bool window_pos_set_by_api = false, window_size_set_by_api = false;
|
||||
if (g.SetNextWindowPosCond)
|
||||
{
|
||||
const ImVec2 backup_cursor_pos = window->DC.CursorPos; // FIXME: not sure of the exact reason of this anymore :( need to look into that.
|
||||
const ImVec2 backup_cursor_pos = window->DC.CursorPos; // FIXME: not sure of the exact reason of this saving/restore anymore :( need to look into that.
|
||||
if (!window_was_active || window_appearing_after_being_hidden) window->SetWindowPosAllowFlags |= ImGuiSetCond_Appearing;
|
||||
window_pos_set_by_api = (window->SetWindowPosAllowFlags & g.SetNextWindowPosCond) != 0;
|
||||
if (window_pos_set_by_api && ImLengthSqr(g.SetNextWindowPosVal - ImVec2(-FLT_MAX,-FLT_MAX)) < 0.001f)
|
||||
@ -3788,12 +3885,12 @@ bool ImGui::Begin(const char* name, bool* p_open, const ImVec2& size_on_first_us
|
||||
window->Active = true;
|
||||
window->IndexWithinParent = 0;
|
||||
window->BeginCount = 0;
|
||||
window->DrawList->Clear();
|
||||
window->ClipRect = ImVec4(-FLT_MAX,-FLT_MAX,+FLT_MAX,+FLT_MAX);
|
||||
window->LastFrameActive = current_frame;
|
||||
window->IDStack.resize(1);
|
||||
|
||||
// Setup texture, outer clipping rectangle
|
||||
// Clear draw list, setup texture, outer clipping rectangle
|
||||
window->DrawList->Clear();
|
||||
window->DrawList->PushTextureID(g.Font->ContainerAtlas->TexID);
|
||||
ImRect fullscreen_rect(GetVisibleRect());
|
||||
if ((flags & ImGuiWindowFlags_ChildWindow) && !(flags & (ImGuiWindowFlags_ComboBox|ImGuiWindowFlags_Popup)))
|
||||
@ -3884,7 +3981,6 @@ bool ImGui::Begin(const char* name, bool* p_open, const ImVec2& size_on_first_us
|
||||
window->SizeFull.x = window->AutoFitOnlyGrows ? ImMax(window->SizeFull.x, size_auto_fit.x) : size_auto_fit.x;
|
||||
if (window->AutoFitFramesY > 0)
|
||||
window->SizeFull.y = window->AutoFitOnlyGrows ? ImMax(window->SizeFull.y, size_auto_fit.y) : size_auto_fit.y;
|
||||
window->Size = window->TitleBarRect().GetSize();
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -3902,17 +3998,12 @@ bool ImGui::Begin(const char* name, bool* p_open, const ImVec2& size_on_first_us
|
||||
if (!(flags & ImGuiWindowFlags_NoSavedSettings))
|
||||
MarkSettingsDirty();
|
||||
}
|
||||
window->Size = window->SizeFull;
|
||||
}
|
||||
|
||||
// Minimum window size
|
||||
if (!(flags & (ImGuiWindowFlags_ChildWindow | ImGuiWindowFlags_AlwaysAutoResize)))
|
||||
{
|
||||
window->SizeFull = ImMax(window->SizeFull, style.WindowMinSize);
|
||||
if (!window->Collapsed)
|
||||
window->Size = window->SizeFull;
|
||||
}
|
||||
|
||||
// Apply minimum/maximum window size constraints and final size
|
||||
ApplySizeFullWithConstraint(window, window->SizeFull);
|
||||
window->Size = window->Collapsed ? window->TitleBarRect().GetSize() : window->SizeFull;
|
||||
|
||||
// POSITION
|
||||
|
||||
// Position child window
|
||||
@ -3924,7 +4015,7 @@ bool ImGui::Begin(const char* name, bool* p_open, const ImVec2& size_on_first_us
|
||||
if ((flags & ImGuiWindowFlags_ChildWindow) && !(flags & ImGuiWindowFlags_Popup))
|
||||
{
|
||||
window->Pos = window->PosFloat = parent_window->DC.CursorPos;
|
||||
window->Size = window->SizeFull = size_on_first_use; // NB: argument name 'size_on_first_use' misleading here, it's really just 'size' as provided by user.
|
||||
window->Size = window->SizeFull = size_on_first_use; // NB: argument name 'size_on_first_use' misleading here, it's really just 'size' as provided by user passed via BeginChild()->Begin().
|
||||
}
|
||||
|
||||
bool window_pos_center = false;
|
||||
@ -3979,10 +4070,10 @@ bool ImGui::Begin(const char* name, bool* p_open, const ImVec2& size_on_first_us
|
||||
window->ItemWidthDefault = (float)(int)(g.FontSize * 16.0f);
|
||||
|
||||
// Prepare for focus requests
|
||||
window->FocusIdxAllRequestCurrent = (window->FocusIdxAllRequestNext == IM_INT_MAX || window->FocusIdxAllCounter == -1) ? IM_INT_MAX : (window->FocusIdxAllRequestNext + (window->FocusIdxAllCounter+1)) % (window->FocusIdxAllCounter+1);
|
||||
window->FocusIdxTabRequestCurrent = (window->FocusIdxTabRequestNext == IM_INT_MAX || window->FocusIdxTabCounter == -1) ? IM_INT_MAX : (window->FocusIdxTabRequestNext + (window->FocusIdxTabCounter+1)) % (window->FocusIdxTabCounter+1);
|
||||
window->FocusIdxAllRequestCurrent = (window->FocusIdxAllRequestNext == INT_MAX || window->FocusIdxAllCounter == -1) ? INT_MAX : (window->FocusIdxAllRequestNext + (window->FocusIdxAllCounter+1)) % (window->FocusIdxAllCounter+1);
|
||||
window->FocusIdxTabRequestCurrent = (window->FocusIdxTabRequestNext == INT_MAX || window->FocusIdxTabCounter == -1) ? INT_MAX : (window->FocusIdxTabRequestNext + (window->FocusIdxTabCounter+1)) % (window->FocusIdxTabCounter+1);
|
||||
window->FocusIdxAllCounter = window->FocusIdxTabCounter = -1;
|
||||
window->FocusIdxAllRequestNext = window->FocusIdxTabRequestNext = IM_INT_MAX;
|
||||
window->FocusIdxAllRequestNext = window->FocusIdxTabRequestNext = INT_MAX;
|
||||
|
||||
// Apply scrolling
|
||||
if (window->ScrollTarget.x < FLT_MAX)
|
||||
@ -4032,14 +4123,15 @@ bool ImGui::Begin(const char* name, bool* p_open, const ImVec2& size_on_first_us
|
||||
if (g.HoveredWindow == window && held && g.IO.MouseDoubleClicked[0])
|
||||
{
|
||||
// Manual auto-fit when double-clicking
|
||||
window->SizeFull = size_auto_fit;
|
||||
ApplySizeFullWithConstraint(window, size_auto_fit);
|
||||
if (!(flags & ImGuiWindowFlags_NoSavedSettings))
|
||||
MarkSettingsDirty();
|
||||
SetActiveID(0);
|
||||
}
|
||||
else if (held)
|
||||
{
|
||||
window->SizeFull = ImMax(window->SizeFull + g.IO.MouseDelta, style.WindowMinSize);
|
||||
// We don't use an incremental MouseDelta but rather compute an absolute target size based on mouse position
|
||||
ApplySizeFullWithConstraint(window, (g.IO.MousePos - g.ActiveIdClickOffset + resize_rect.GetSize()) - window->Pos);
|
||||
if (!(flags & ImGuiWindowFlags_NoSavedSettings))
|
||||
MarkSettingsDirty();
|
||||
}
|
||||
@ -4203,6 +4295,7 @@ bool ImGui::Begin(const char* name, bool* p_open, const ImVec2& size_on_first_us
|
||||
if (first_begin_of_the_frame)
|
||||
window->Accessed = false;
|
||||
window->BeginCount++;
|
||||
g.SetNextWindowSizeConstraint = false;
|
||||
|
||||
// Child window can be out of sight and have "negative" clip windows.
|
||||
// Mark them as collapsed so commands are skipped earlier (we can't manually collapse because they have no title bar).
|
||||
@ -4369,7 +4462,7 @@ void ImGui::FocusWindow(ImGuiWindow* window)
|
||||
// Steal focus on active widgets
|
||||
if (window->Flags & ImGuiWindowFlags_Popup) // FIXME: This statement should be unnecessary. Need further testing before removing it..
|
||||
if (g.ActiveId != 0 && g.ActiveIdWindow && g.ActiveIdWindow->RootWindow != window)
|
||||
ImGui::SetActiveID(0);
|
||||
SetActiveID(0);
|
||||
|
||||
// Bring to front
|
||||
if ((window->Flags & ImGuiWindowFlags_NoBringToFrontOnFocus) || g.Windows.back() == window)
|
||||
@ -4842,6 +4935,15 @@ void ImGui::SetNextWindowSize(const ImVec2& size, ImGuiSetCond cond)
|
||||
g.SetNextWindowSizeCond = cond ? cond : ImGuiSetCond_Always;
|
||||
}
|
||||
|
||||
void ImGui::SetNextWindowSizeConstraint(const ImVec2& size_min, const ImVec2& size_max, ImGuiSizeConstraintCallback custom_callback, void* custom_callback_user_data)
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
g.SetNextWindowSizeConstraint = true;
|
||||
g.SetNextWindowSizeConstraintRect = ImRect(size_min, size_max);
|
||||
g.SetNextWindowSizeConstraintCallback = custom_callback;
|
||||
g.SetNextWindowSizeConstraintCallbackUserData = custom_callback_user_data;
|
||||
}
|
||||
|
||||
void ImGui::SetNextWindowContentSize(const ImVec2& size)
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
@ -5077,7 +5179,7 @@ void ImGui::SetKeyboardFocusHere(int offset)
|
||||
{
|
||||
ImGuiWindow* window = GetCurrentWindow();
|
||||
window->FocusIdxAllRequestNext = window->FocusIdxAllCounter + 1 + offset;
|
||||
window->FocusIdxTabRequestNext = IM_INT_MAX;
|
||||
window->FocusIdxTabRequestNext = INT_MAX;
|
||||
}
|
||||
|
||||
void ImGui::SetStateStorage(ImGuiStorage* tree)
|
||||
@ -5355,6 +5457,7 @@ bool ImGui::ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool
|
||||
{
|
||||
SetActiveID(id, window); // Hold on ID
|
||||
FocusWindow(window);
|
||||
g.ActiveIdClickOffset = g.IO.MousePos - bb.Min;
|
||||
}
|
||||
if (((flags & ImGuiButtonFlags_PressedOnClick) && g.IO.MouseClicked[0]) || ((flags & ImGuiButtonFlags_PressedOnDoubleClick) && g.IO.MouseDoubleClicked[0]))
|
||||
{
|
||||
@ -6866,10 +6969,10 @@ bool ImGui::DragIntRange2(const char* label, int* v_current_min, int* v_current_
|
||||
ImGui::BeginGroup();
|
||||
PushMultiItemsWidths(2);
|
||||
|
||||
bool value_changed = ImGui::DragInt("##min", v_current_min, v_speed, (v_min >= v_max) ? IM_INT_MIN : v_min, (v_min >= v_max) ? *v_current_max : ImMin(v_max, *v_current_max), display_format);
|
||||
bool value_changed = ImGui::DragInt("##min", v_current_min, v_speed, (v_min >= v_max) ? INT_MIN : v_min, (v_min >= v_max) ? *v_current_max : ImMin(v_max, *v_current_max), display_format);
|
||||
ImGui::PopItemWidth();
|
||||
ImGui::SameLine(0, g.Style.ItemInnerSpacing.x);
|
||||
value_changed |= ImGui::DragInt("##max", v_current_max, v_speed, (v_min >= v_max) ? *v_current_min : ImMax(v_min, *v_current_min), (v_min >= v_max) ? IM_INT_MAX : v_max, display_format_max ? display_format_max : display_format);
|
||||
value_changed |= ImGui::DragInt("##max", v_current_max, v_speed, (v_min >= v_max) ? *v_current_min : ImMax(v_min, *v_current_min), (v_min >= v_max) ? INT_MAX : v_max, display_format_max ? display_format_max : display_format);
|
||||
ImGui::PopItemWidth();
|
||||
ImGui::SameLine(0, g.Style.ItemInnerSpacing.x);
|
||||
|
||||
@ -7964,9 +8067,9 @@ bool ImGui::InputTextEx(const char* label, char* buf, int buf_size, const ImVec2
|
||||
// Draw blinking cursor
|
||||
bool cursor_is_visible = (g.InputTextState.CursorAnim <= 0.0f) || fmodf(g.InputTextState.CursorAnim, 1.20f) <= 0.80f;
|
||||
ImVec2 cursor_screen_pos = render_pos + cursor_offset - render_scroll;
|
||||
ImRect cursor_screen_rect(cursor_screen_pos.x, cursor_screen_pos.y-g.FontSize+0.5f, cursor_screen_pos.x, cursor_screen_pos.y-1.5f);
|
||||
ImRect cursor_screen_rect(cursor_screen_pos.x, cursor_screen_pos.y-g.FontSize+0.5f, cursor_screen_pos.x+1.0f, cursor_screen_pos.y-1.5f);
|
||||
if (cursor_is_visible && cursor_screen_rect.Overlaps(clip_rect))
|
||||
draw_window->DrawList->AddLine(cursor_screen_rect.Min, cursor_screen_rect.Max, GetColorU32(ImGuiCol_Text));
|
||||
draw_window->DrawList->AddLine(cursor_screen_rect.Min, cursor_screen_rect.GetBL(), GetColorU32(ImGuiCol_Text));
|
||||
|
||||
// Notify OS of text input position for advanced IME (-1 x offset so that Windows IME can cover our cursor. Bit of an extra nicety.)
|
||||
if (is_editable)
|
||||
@ -8497,22 +8600,22 @@ bool ImGui::ListBox(const char* label, int* current_item, bool (*items_getter)(v
|
||||
// Assume all items have even height (= 1 line of text). If you need items of different or variable sizes you can create a custom version of ListBox() in your code without using the clipper.
|
||||
bool value_changed = false;
|
||||
ImGuiListClipper clipper(items_count, ImGui::GetTextLineHeightWithSpacing());
|
||||
for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; i++)
|
||||
{
|
||||
const bool item_selected = (i == *current_item);
|
||||
const char* item_text;
|
||||
if (!items_getter(data, i, &item_text))
|
||||
item_text = "*Unknown item*";
|
||||
|
||||
ImGui::PushID(i);
|
||||
if (ImGui::Selectable(item_text, item_selected))
|
||||
while (clipper.Step())
|
||||
for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; i++)
|
||||
{
|
||||
*current_item = i;
|
||||
value_changed = true;
|
||||
const bool item_selected = (i == *current_item);
|
||||
const char* item_text;
|
||||
if (!items_getter(data, i, &item_text))
|
||||
item_text = "*Unknown item*";
|
||||
|
||||
ImGui::PushID(i);
|
||||
if (ImGui::Selectable(item_text, item_selected))
|
||||
{
|
||||
*current_item = i;
|
||||
value_changed = true;
|
||||
}
|
||||
ImGui::PopID();
|
||||
}
|
||||
ImGui::PopID();
|
||||
}
|
||||
clipper.End();
|
||||
ImGui::ListBoxFooter();
|
||||
return value_changed;
|
||||
}
|
||||
@ -9052,6 +9155,17 @@ void ImGui::SameLine(float pos_x, float spacing_w)
|
||||
window->DC.CurrentLineTextBaseOffset = window->DC.PrevLineTextBaseOffset;
|
||||
}
|
||||
|
||||
void ImGui::NewLine()
|
||||
{
|
||||
ImGuiWindow* window = GetCurrentWindow();
|
||||
if (window->SkipItems)
|
||||
return;
|
||||
if (window->DC.CurrentLineHeight > 0.0f) // In the event that we are on a line with items that is smaller that FontSize high, we will preserve its height.
|
||||
ItemSize(ImVec2(0,0));
|
||||
else
|
||||
ItemSize(ImVec2(0.0f, GImGui->FontSize));
|
||||
}
|
||||
|
||||
void ImGui::NextColumn()
|
||||
{
|
||||
ImGuiWindow* window = GetCurrentWindow();
|
||||
@ -9109,7 +9223,7 @@ static float GetDraggedColumnOffset(int column_index)
|
||||
IM_ASSERT(column_index > 0); // We cannot drag column 0. If you get this assert you may have a conflict between the ID of your columns and another widgets.
|
||||
IM_ASSERT(g.ActiveId == window->DC.ColumnsSetID + ImGuiID(column_index));
|
||||
|
||||
float x = g.IO.MousePos.x + g.ActiveClickDeltaToCenter.x - window->Pos.x;
|
||||
float x = g.IO.MousePos.x - g.ActiveIdClickOffset.x - window->Pos.x;
|
||||
x = ImClamp(x, ImGui::GetColumnOffset(column_index-1)+g.Style.ColumnsMinSpacing, ImGui::GetColumnOffset(column_index+1)-g.Style.ColumnsMinSpacing);
|
||||
|
||||
return (float)(int)x;
|
||||
@ -9214,7 +9328,7 @@ void ImGui::Columns(int columns_count, const char* id, bool border)
|
||||
if (held)
|
||||
{
|
||||
if (g.ActiveIdIsJustActivated)
|
||||
g.ActiveClickDeltaToCenter.x = x - g.IO.MousePos.x;
|
||||
g.ActiveIdClickOffset.x -= 4; // Store from center of column line
|
||||
x = GetDraggedColumnOffset(i);
|
||||
SetColumnOffset(i, x);
|
||||
}
|
||||
@ -9525,22 +9639,22 @@ void ImGui::ShowMetricsWindow(bool* p_open)
|
||||
}
|
||||
if (!pcmd_node_open)
|
||||
continue;
|
||||
ImGuiListClipper clipper(pcmd->ElemCount/3, ImGui::GetTextLineHeight()*3 + ImGui::GetStyle().ItemSpacing.y); // Manually coarse clip our print out of individual vertices to save CPU, only items that may be visible.
|
||||
for (int prim = clipper.DisplayStart, vtx_i = elem_offset + clipper.DisplayStart*3; prim < clipper.DisplayEnd; prim++)
|
||||
{
|
||||
char buf[300], *buf_p = buf;
|
||||
ImVec2 triangles_pos[3];
|
||||
for (int n = 0; n < 3; n++, vtx_i++)
|
||||
ImGuiListClipper clipper(pcmd->ElemCount/3); // Manually coarse clip our print out of individual vertices to save CPU, only items that may be visible.
|
||||
while (clipper.Step())
|
||||
for (int prim = clipper.DisplayStart, vtx_i = elem_offset + clipper.DisplayStart*3; prim < clipper.DisplayEnd; prim++)
|
||||
{
|
||||
ImDrawVert& v = draw_list->VtxBuffer[idx_buffer ? idx_buffer[vtx_i] : vtx_i];
|
||||
triangles_pos[n] = v.pos;
|
||||
buf_p += sprintf(buf_p, "%s %04d { pos = (%8.2f,%8.2f), uv = (%.6f,%.6f), col = %08X }\n", (n == 0) ? "vtx" : " ", vtx_i, v.pos.x, v.pos.y, v.uv.x, v.uv.y, v.col);
|
||||
char buf[300], *buf_p = buf;
|
||||
ImVec2 triangles_pos[3];
|
||||
for (int n = 0; n < 3; n++, vtx_i++)
|
||||
{
|
||||
ImDrawVert& v = draw_list->VtxBuffer[idx_buffer ? idx_buffer[vtx_i] : vtx_i];
|
||||
triangles_pos[n] = v.pos;
|
||||
buf_p += sprintf(buf_p, "%s %04d { pos = (%8.2f,%8.2f), uv = (%.6f,%.6f), col = %08X }\n", (n == 0) ? "vtx" : " ", vtx_i, v.pos.x, v.pos.y, v.uv.x, v.uv.y, v.col);
|
||||
}
|
||||
ImGui::Selectable(buf, false);
|
||||
if (ImGui::IsItemHovered())
|
||||
overlay_draw_list->AddPolyline(triangles_pos, 3, IM_COL32(255,255,0,255), true, 1.0f, false); // Add triangle without AA, more readable for large-thin triangle
|
||||
}
|
||||
ImGui::Selectable(buf, false);
|
||||
if (ImGui::IsItemHovered())
|
||||
overlay_draw_list->AddPolyline(triangles_pos, 3, IM_COL32(255,255,0,255), true, 1.0f, false); // Add triangle without AA, more readable for large-thin triangle
|
||||
}
|
||||
clipper.End();
|
||||
ImGui::TreePop();
|
||||
}
|
||||
overlay_draw_list->PopClipRect();
|
||||
|
74
3rdparty/bgfx/3rdparty/ocornut-imgui/imgui.h
vendored
74
3rdparty/bgfx/3rdparty/ocornut-imgui/imgui.h
vendored
@ -52,7 +52,8 @@ struct ImGuiStorage; // Simple custom key value storage
|
||||
struct ImGuiStyle; // Runtime data for styling/colors
|
||||
struct ImGuiTextFilter; // Parse and apply text filters. In format "aaaaa[,bbbb][,ccccc]"
|
||||
struct ImGuiTextBuffer; // Text buffer for logging/accumulating text
|
||||
struct ImGuiTextEditCallbackData; // Shared state of ImGui::InputText() when using custom callbacks (advanced)
|
||||
struct ImGuiTextEditCallbackData; // Shared state of ImGui::InputText() when using custom ImGuiTextEditCallback (rare/advanced use)
|
||||
struct ImGuiSizeConstraintCallbackData;// Structure used to constraint window size in custom ways when using custom ImGuiSizeConstraintCallback (rare/advanced use)
|
||||
struct ImGuiListClipper; // Helper to manually clip large list of items
|
||||
struct ImGuiContext; // ImGui context (opaque)
|
||||
|
||||
@ -73,6 +74,7 @@ typedef int ImGuiInputTextFlags; // flags for InputText*() // e
|
||||
typedef int ImGuiSelectableFlags; // flags for Selectable() // enum ImGuiSelectableFlags_
|
||||
typedef int ImGuiTreeNodeFlags; // flags for TreeNode*(), Collapsing*() // enum ImGuiTreeNodeFlags_
|
||||
typedef int (*ImGuiTextEditCallback)(ImGuiTextEditCallbackData *data);
|
||||
typedef void (*ImGuiSizeConstraintCallback)(ImGuiSizeConstraintCallbackData* data);
|
||||
|
||||
// Others helpers at bottom of the file:
|
||||
// class ImVector<> // Lightweight std::vector like class.
|
||||
@ -138,6 +140,7 @@ namespace ImGui
|
||||
IMGUI_API void SetNextWindowPos(const ImVec2& pos, ImGuiSetCond cond = 0); // set next window position. call before Begin()
|
||||
IMGUI_API void SetNextWindowPosCenter(ImGuiSetCond cond = 0); // set next window position to be centered on screen. call before Begin()
|
||||
IMGUI_API void SetNextWindowSize(const ImVec2& size, ImGuiSetCond cond = 0); // set next window size. set axis to 0.0f to force an auto-fit on this axis. call before Begin()
|
||||
IMGUI_API void SetNextWindowSizeConstraint(const ImVec2& size_min, const ImVec2& size_max, ImGuiSizeConstraintCallback custom_callback = NULL, void* custom_callback_data = NULL); // set next window size limits. use -1,-1 on either X/Y axis to preserve the current size. Use callback to apply non-trivial programmatic constraints.
|
||||
IMGUI_API void SetNextWindowContentSize(const ImVec2& size); // set next window content size (enforce the range of scrollbars). set axis to 0.0f to leave it automatic. call before Begin()
|
||||
IMGUI_API void SetNextWindowContentWidth(float width); // set next window content width (enforce the range of horizontal scrollbar). call before Begin()
|
||||
IMGUI_API void SetNextWindowCollapsed(bool collapsed, ImGuiSetCond cond = 0); // set next window collapsed state. call before Begin()
|
||||
@ -191,6 +194,7 @@ namespace ImGui
|
||||
// Cursor / Layout
|
||||
IMGUI_API void Separator(); // horizontal line
|
||||
IMGUI_API void SameLine(float pos_x = 0.0f, float spacing_w = -1.0f); // call between widgets or groups to layout them horizontally
|
||||
IMGUI_API void NewLine(); // undo a SameLine()
|
||||
IMGUI_API void Spacing(); // add spacing
|
||||
IMGUI_API void Dummy(const ImVec2& size); // add a dummy item of given size
|
||||
IMGUI_API void Indent(); // move content position toward the right by style.IndentSpacing pixels
|
||||
@ -249,7 +253,7 @@ namespace ImGui
|
||||
IMGUI_API void BulletText(const char* fmt, ...) IM_PRINTFARGS(1);
|
||||
IMGUI_API void BulletTextV(const char* fmt, va_list args);
|
||||
IMGUI_API bool Button(const char* label, const ImVec2& size = ImVec2(0,0));
|
||||
IMGUI_API bool SmallButton(const char* label);
|
||||
IMGUI_API bool SmallButton(const char* label); // button with FramePadding=(0,0)
|
||||
IMGUI_API bool InvisibleButton(const char* str_id, const ImVec2& size);
|
||||
IMGUI_API void Image(ImTextureID user_texture_id, const ImVec2& size, const ImVec2& uv0 = ImVec2(0,0), const ImVec2& uv1 = ImVec2(1,1), const ImVec4& tint_col = ImVec4(1,1,1,1), const ImVec4& border_col = ImVec4(0,0,0,0));
|
||||
IMGUI_API bool ImageButton(ImTextureID user_texture_id, const ImVec2& size, const ImVec2& uv0 = ImVec2(0,0), const ImVec2& uv1 = ImVec2(1,1), int frame_padding = -1, const ImVec4& bg_col = ImVec4(0,0,0,0), const ImVec4& tint_col = ImVec4(1,1,1,1)); // <0 frame_padding uses default frame padding settings. 0 for no padding
|
||||
@ -1030,7 +1034,18 @@ struct ImGuiTextEditCallbackData
|
||||
bool HasSelection() const { return SelectionStart != SelectionEnd; }
|
||||
};
|
||||
|
||||
// Resizing callback data to apply custom constraint. As enabled by SetNextWindowSizeConstraint(). Callback is called during the next Begin().
|
||||
// NB: For basic min/max size constraint on each axis you don't need to use the callback! The SetNextWindowSizeConstraint() parameters are enough.
|
||||
struct ImGuiSizeConstraintCallbackData
|
||||
{
|
||||
void* UserData; // Read-only. What user passed to SetNextWindowSizeConstraint()
|
||||
ImVec2 Pos; // Read-only. Window position, for reference.
|
||||
ImVec2 CurrentSize; // Read-only. Current window size.
|
||||
ImVec2 DesiredSize; // Read-write. Desired size, based on user's mouse position. Write to this field to restrain resizing.
|
||||
};
|
||||
|
||||
// ImColor() helper to implicity converts colors to either ImU32 (packed 4x1 byte) or ImVec4 (4x1 float)
|
||||
// Prefer using IM_COL32() macros if you want a guaranteed compile-time ImU32 for usage with ImDrawList API.
|
||||
// Avoid storing ImColor! Store either u32 of ImVec4. This is not a full-featured color class.
|
||||
// None of the ImGui API are using ImColor directly but you can use it as a convenience to pass colors in either ImU32 or ImVec4 formats.
|
||||
struct ImColor
|
||||
@ -1051,36 +1066,33 @@ struct ImColor
|
||||
};
|
||||
|
||||
// Helper: Manually clip large list of items.
|
||||
// If you are displaying thousands of even spaced items and you have a random access to the list, you can perform clipping yourself to save on CPU.
|
||||
// If you are submitting lots of evenly spaced items and you have a random access to the list, you can perform coarse clipping based on visibility to save yourself from processing those items at all.
|
||||
// The clipper calculates the range of visible items and advance the cursor to compensate for the non-visible items we have skipped.
|
||||
// ImGui already clip items based on their bounds but it needs to measure text size to do so. Coarse clipping before submission makes this cost and your own data fetching/submission cost null.
|
||||
// Usage:
|
||||
// ImGuiListClipper clipper(count, ImGui::GetTextLineHeightWithSpacing());
|
||||
// for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; i++) // display only visible items
|
||||
// ImGui::Text("line number %d", i);
|
||||
// clipper.End();
|
||||
// NB: 'count' is only used to clamp the result, if you don't know your count you can use INT_MAX
|
||||
// ImGuiListClipper clipper(1000); // we have 1000 elements, evenly spaced.
|
||||
// while (clipper.Step())
|
||||
// for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; i++)
|
||||
// ImGui::Text("line number %d", i);
|
||||
// - Step 0: the clipper let you process the first element, regardless of it being visible or not, so we can measure the element height (step skipped if we passed a known height as second arg to constructor).
|
||||
// - Step 1: the clipper infer height from first element, calculate the actual range of elements to display, and position the cursor before the first element.
|
||||
// - (Step 2: dummy step only required if an explicit items_height was passed to constructor or Begin() and user call Step(). Does nothing and switch to Step 3.)
|
||||
// - Step 3: the clipper validate that we have reached the expected Y position (corresponding to element DisplayEnd), advance the cursor to the end of the list and then returns 'false' to end the loop.
|
||||
struct ImGuiListClipper
|
||||
{
|
||||
float StartPosY;
|
||||
float ItemsHeight;
|
||||
int ItemsCount, DisplayStart, DisplayEnd;
|
||||
int ItemsCount, StepNo, DisplayStart, DisplayEnd;
|
||||
|
||||
ImGuiListClipper() { ItemsHeight = 0.0f; ItemsCount = DisplayStart = DisplayEnd = -1; }
|
||||
ImGuiListClipper(int count, float height) { ItemsCount = -1; Begin(count, height); }
|
||||
~ImGuiListClipper() { IM_ASSERT(ItemsCount == -1); } // user forgot to call End()
|
||||
// items_count: Use -1 to ignore (you can call Begin later). Use INT_MAX if you don't know how many items you have (in which case the cursor won't be advanced in the final step).
|
||||
// items_height: Use -1.0f to be calculated automatically on first step. Otherwise pass in the distance between your items, typically GetTextLineHeightWithSpacing() or GetItemsLineHeightWithSpacing().
|
||||
// If you don't specify an items_height, you NEED to call Step(). If you specify items_height you may call the old Begin()/End() api directly, but prefer calling Step().
|
||||
ImGuiListClipper(int items_count = -1, float items_height = -1.0f) { Begin(items_count, items_height); } // NB: Begin() initialize every fields (as we allow user to call Begin/End multiple times on a same instance if they want).
|
||||
~ImGuiListClipper() { IM_ASSERT(ItemsCount == -1); } // Assert if user forgot to call End() or Step() until false.
|
||||
|
||||
void Begin(int count, float height) // items_height: generally pass GetTextLineHeightWithSpacing() or GetItemsLineHeightWithSpacing()
|
||||
{
|
||||
IM_ASSERT(ItemsCount == -1);
|
||||
ItemsCount = count;
|
||||
ItemsHeight = height;
|
||||
ImGui::CalcListClipping(ItemsCount, ItemsHeight, &DisplayStart, &DisplayEnd); // calculate how many to clip/display
|
||||
ImGui::SetCursorPosY(ImGui::GetCursorPosY() + DisplayStart * ItemsHeight); // advance cursor
|
||||
}
|
||||
void End()
|
||||
{
|
||||
IM_ASSERT(ItemsCount >= 0);
|
||||
ImGui::SetCursorPosY(ImGui::GetCursorPosY() + (ItemsCount - DisplayEnd) * ItemsHeight); // advance cursor
|
||||
ItemsCount = -1;
|
||||
}
|
||||
IMGUI_API bool Step(); // Call until it returns false. The DisplayStart/DisplayEnd fields will be set and you can process/draw those items.
|
||||
IMGUI_API void Begin(int items_count, float items_height = -1.0f); // Automatically called by constructor if you passed 'items_count' or by Step() in Step 1.
|
||||
IMGUI_API void End(); // Automatically called on the last call of Step() that returns false.
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -1096,12 +1108,8 @@ struct ImGuiListClipper
|
||||
|
||||
// Draw callbacks for advanced uses.
|
||||
// NB- You most likely do NOT need to use draw callbacks just to create your own widget or customized UI rendering (you can poke into the draw list for that)
|
||||
// Draw callback may be useful for example, if you want to render a complex 3D scene inside a UI element, change your GPU render state, etc.
|
||||
// The expected behavior from your rendering loop is:
|
||||
// if (cmd.UserCallback != NULL)
|
||||
// cmd.UserCallback(parent_list, cmd);
|
||||
// else
|
||||
// RenderTriangles()
|
||||
// Draw callback may be useful for example, A) Change your GPU render state, B) render a complex 3D scene inside a UI element (without an intermediate texture/render target), etc.
|
||||
// The expected behavior from your rendering function is 'if (cmd.UserCallback != NULL) cmd.UserCallback(parent_list, cmd); else RenderTriangles()'
|
||||
typedef void (*ImDrawCallback)(const ImDrawList* parent_list, const ImDrawCmd* cmd);
|
||||
|
||||
// Typically, 1 command = 1 gpu draw call (unless command is a callback)
|
||||
@ -1117,7 +1125,7 @@ struct ImDrawCmd
|
||||
ImDrawCmd() { ElemCount = 0; ClipRect.x = ClipRect.y = -8192.0f; ClipRect.z = ClipRect.w = +8192.0f; TextureId = NULL; UserCallback = NULL; UserCallbackData = NULL; ViewId = 0; }
|
||||
};
|
||||
|
||||
// Vertex index (override with, e.g. '#define ImDrawIdx unsigned int' in ImConfig)
|
||||
// Vertex index (override with '#define ImDrawIdx unsigned int' inside in imconfig.h)
|
||||
#ifndef ImDrawIdx
|
||||
typedef unsigned short ImDrawIdx;
|
||||
#endif
|
||||
|
@ -46,6 +46,7 @@
|
||||
#endif
|
||||
|
||||
#define IM_ARRAYSIZE(_ARR) ((int)(sizeof(_ARR)/sizeof(*_ARR)))
|
||||
#define IM_MAX(_A,_B) (((_A) >= (_B)) ? (_A) : (_B))
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// DEMO CODE
|
||||
@ -59,6 +60,7 @@ static void ShowExampleAppLayout(bool* p_open);
|
||||
static void ShowExampleAppPropertyEditor(bool* p_open);
|
||||
static void ShowExampleAppLongText(bool* p_open);
|
||||
static void ShowExampleAppAutoResize(bool* p_open);
|
||||
static void ShowExampleAppConstrainedResize(bool* p_open);
|
||||
static void ShowExampleAppFixedOverlay(bool* p_open);
|
||||
static void ShowExampleAppManipulatingWindowTitle(bool* p_open);
|
||||
static void ShowExampleAppCustomRendering(bool* p_open);
|
||||
@ -105,6 +107,7 @@ void ImGui::ShowTestWindow(bool* p_open)
|
||||
static bool show_app_property_editor = false;
|
||||
static bool show_app_long_text = false;
|
||||
static bool show_app_auto_resize = false;
|
||||
static bool show_app_constrained_resize = false;
|
||||
static bool show_app_fixed_overlay = false;
|
||||
static bool show_app_manipulating_window_title = false;
|
||||
static bool show_app_custom_rendering = false;
|
||||
@ -120,6 +123,7 @@ void ImGui::ShowTestWindow(bool* p_open)
|
||||
if (show_app_property_editor) ShowExampleAppPropertyEditor(&show_app_property_editor);
|
||||
if (show_app_long_text) ShowExampleAppLongText(&show_app_long_text);
|
||||
if (show_app_auto_resize) ShowExampleAppAutoResize(&show_app_auto_resize);
|
||||
if (show_app_constrained_resize) ShowExampleAppConstrainedResize(&show_app_constrained_resize);
|
||||
if (show_app_fixed_overlay) ShowExampleAppFixedOverlay(&show_app_fixed_overlay);
|
||||
if (show_app_manipulating_window_title) ShowExampleAppManipulatingWindowTitle(&show_app_manipulating_window_title);
|
||||
if (show_app_custom_rendering) ShowExampleAppCustomRendering(&show_app_custom_rendering);
|
||||
@ -183,6 +187,7 @@ void ImGui::ShowTestWindow(bool* p_open)
|
||||
ImGui::MenuItem("Property editor", NULL, &show_app_property_editor);
|
||||
ImGui::MenuItem("Long text display", NULL, &show_app_long_text);
|
||||
ImGui::MenuItem("Auto-resizing window", NULL, &show_app_auto_resize);
|
||||
ImGui::MenuItem("Constrained-resizing window", NULL, &show_app_constrained_resize);
|
||||
ImGui::MenuItem("Simple overlay", NULL, &show_app_fixed_overlay);
|
||||
ImGui::MenuItem("Manipulating window title", NULL, &show_app_manipulating_window_title);
|
||||
ImGui::MenuItem("Custom rendering", NULL, &show_app_custom_rendering);
|
||||
@ -384,14 +389,14 @@ void ImGui::ShowTestWindow(bool* p_open)
|
||||
static int pressed_count = 0;
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
if (i > 0)
|
||||
ImGui::SameLine();
|
||||
ImGui::PushID(i);
|
||||
int frame_padding = -1 + i; // -1 = uses default padding
|
||||
if (ImGui::ImageButton(tex_id, ImVec2(32,32), ImVec2(0,0), ImVec2(32.0f/tex_w,32/tex_h), frame_padding, ImColor(0,0,0,255)))
|
||||
pressed_count += 1;
|
||||
ImGui::PopID();
|
||||
ImGui::SameLine();
|
||||
}
|
||||
ImGui::NewLine();
|
||||
ImGui::Text("Pressed %d times.", pressed_count);
|
||||
ImGui::TreePop();
|
||||
}
|
||||
@ -704,7 +709,7 @@ void ImGui::ShowTestWindow(bool* p_open)
|
||||
if (i > 0) ImGui::SameLine();
|
||||
ImGui::PushID(i);
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_GrabMinSize, 40);
|
||||
ImGui::VSliderFloat("##v", ImVec2(40,160), &values[i], 0.0f, 1.0f, "%.2f");
|
||||
ImGui::VSliderFloat("##v", ImVec2(40,160), &values[i], 0.0f, 1.0f, "%.2f\nsec");
|
||||
ImGui::PopStyleVar();
|
||||
ImGui::PopID();
|
||||
}
|
||||
@ -1793,6 +1798,43 @@ static void ShowExampleAppAutoResize(bool* p_open)
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
static void ShowExampleAppConstrainedResize(bool* p_open)
|
||||
{
|
||||
struct CustomConstraints // Helper functions to demonstrate programmatic constraints
|
||||
{
|
||||
static void Square(ImGuiSizeConstraintCallbackData* data) { data->DesiredSize = ImVec2(IM_MAX(data->DesiredSize.x, data->DesiredSize.y), IM_MAX(data->DesiredSize.x, data->DesiredSize.y)); }
|
||||
static void Step(ImGuiSizeConstraintCallbackData* data) { float step = (float)(int)(intptr_t)data->UserData; data->DesiredSize = ImVec2((int)(data->DesiredSize.x / step + 0.5f) * step, (int)(data->DesiredSize.y / step + 0.5f) * step); }
|
||||
};
|
||||
|
||||
static int type = 0;
|
||||
if (type == 0) ImGui::SetNextWindowSizeConstraint(ImVec2(-1, 0), ImVec2(-1, FLT_MAX)); // Vertical only
|
||||
if (type == 1) ImGui::SetNextWindowSizeConstraint(ImVec2(0, -1), ImVec2(FLT_MAX, -1)); // Horizontal only
|
||||
if (type == 2) ImGui::SetNextWindowSizeConstraint(ImVec2(100, 100), ImVec2(FLT_MAX, FLT_MAX)); // Width > 100, Height > 100
|
||||
if (type == 3) ImGui::SetNextWindowSizeConstraint(ImVec2(300, 0), ImVec2(400, FLT_MAX)); // Width 300-400
|
||||
if (type == 4) ImGui::SetNextWindowSizeConstraint(ImVec2(0, 0), ImVec2(FLT_MAX, FLT_MAX), CustomConstraints::Square); // Always Square
|
||||
if (type == 5) ImGui::SetNextWindowSizeConstraint(ImVec2(0, 0), ImVec2(FLT_MAX, FLT_MAX), CustomConstraints::Step, (void*)100);// Fixed Step
|
||||
|
||||
if (ImGui::Begin("Example: Constrained Resize", p_open))
|
||||
{
|
||||
const char* desc[] =
|
||||
{
|
||||
"Resize vertical only",
|
||||
"Resize horizontal only",
|
||||
"Width > 100, Height > 100",
|
||||
"Width 300-400",
|
||||
"Custom: Always Square",
|
||||
"Custom: Fixed Steps (100)",
|
||||
};
|
||||
ImGui::Combo("Constraint", &type, desc, IM_ARRAYSIZE(desc));
|
||||
if (ImGui::Button("200x200")) ImGui::SetWindowSize(ImVec2(200,200)); ImGui::SameLine();
|
||||
if (ImGui::Button("500x500")) ImGui::SetWindowSize(ImVec2(500,500)); ImGui::SameLine();
|
||||
if (ImGui::Button("800x200")) ImGui::SetWindowSize(ImVec2(800,200));
|
||||
for (int i = 0; i < 10; i++)
|
||||
ImGui::Text("Hello, sailor! Making this line long enough for the example.");
|
||||
}
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
static void ShowExampleAppFixedOverlay(bool* p_open)
|
||||
{
|
||||
ImGui::SetNextWindowPos(ImVec2(10,10));
|
||||
@ -1807,10 +1849,8 @@ static void ShowExampleAppFixedOverlay(bool* p_open)
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
static void ShowExampleAppManipulatingWindowTitle(bool* p_open)
|
||||
static void ShowExampleAppManipulatingWindowTitle(bool*)
|
||||
{
|
||||
(void)p_open;
|
||||
|
||||
// By default, Windows are uniquely identified by their title.
|
||||
// You can use the "##" and "###" markers to manipulate the display/ID. Read FAQ at the top of this file!
|
||||
|
||||
@ -2002,7 +2042,8 @@ struct ExampleAppConsole
|
||||
|
||||
if (ImGui::SmallButton("Add Dummy Text")) { AddLog("%d some text", Items.Size); AddLog("some more text"); AddLog("display very important message here!"); } ImGui::SameLine();
|
||||
if (ImGui::SmallButton("Add Dummy Error")) AddLog("[error] something went wrong"); ImGui::SameLine();
|
||||
if (ImGui::SmallButton("Clear")) ClearLog();
|
||||
if (ImGui::SmallButton("Clear")) ClearLog(); ImGui::SameLine();
|
||||
if (ImGui::SmallButton("Scroll to bottom")) ScrollToBottom = true;
|
||||
//static float t = 0.0f; if (ImGui::GetTime() - t > 0.02f) { t = ImGui::GetTime(); AddLog("Spam %f", t); }
|
||||
|
||||
ImGui::Separator();
|
||||
@ -2013,24 +2054,33 @@ struct ExampleAppConsole
|
||||
ImGui::PopStyleVar();
|
||||
ImGui::Separator();
|
||||
|
||||
// Display every line as a separate entry so we can change their color or add custom widgets. If you only want raw text you can use ImGui::TextUnformatted(log.begin(), log.end());
|
||||
// NB- if you have thousands of entries this approach may be too inefficient. You can seek and display only the lines that are visible - CalcListClipping() is a helper to compute this information.
|
||||
// If your items are of variable size you may want to implement code similar to what CalcListClipping() does. Or split your data into fixed height items to allow random-seeking into your list.
|
||||
ImGui::BeginChild("ScrollingRegion", ImVec2(0,-ImGui::GetItemsLineHeightWithSpacing()), false, ImGuiWindowFlags_HorizontalScrollbar);
|
||||
if (ImGui::BeginPopupContextWindow())
|
||||
{
|
||||
if (ImGui::Selectable("Clear")) ClearLog();
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
|
||||
// Display every line as a separate entry so we can change their color or add custom widgets. If you only want raw text you can use ImGui::TextUnformatted(log.begin(), log.end());
|
||||
// NB- if you have thousands of entries this approach may be too inefficient and may require user-side clipping to only process visible items.
|
||||
// You can seek and display only the lines that are visible using the ImGuiListClipper helper, if your elements are evenly spaced and you have cheap random access to the elements.
|
||||
// To use the clipper we could replace the 'for (int i = 0; i < Items.Size; i++)' loop with:
|
||||
// ImGuiListClipper clipper(Items.Size);
|
||||
// while (clipper.Step())
|
||||
// for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; i++)
|
||||
// However take note that you can not use this code as is if a filter is active because it breaks the 'cheap random-access' property. We would need random-access on the post-filtered list.
|
||||
// A typical application wanting coarse clipping and filtering may want to pre-compute an array of indices that passed the filtering test, recomputing this array when user changes the filter,
|
||||
// and appending newly elements as they are inserted. This is left as a task to the user until we can manage to improve this example code!
|
||||
// If your items are of variable size you may want to implement code similar to what ImGuiListClipper does. Or split your data into fixed height items to allow random-seeking into your list.
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(4,1)); // Tighten spacing
|
||||
for (int i = 0; i < Items.Size; i++)
|
||||
{
|
||||
const char* item = Items[i];
|
||||
if (!filter.PassFilter(item))
|
||||
continue;
|
||||
ImVec4 col = ImColor(255,255,255); // A better implementation may store a type per-item. For the sample let's just parse the text.
|
||||
if (strstr(item, "[error]")) col = ImColor(255,100,100);
|
||||
else if (strncmp(item, "# ", 2) == 0) col = ImColor(255,200,150);
|
||||
ImVec4 col = ImVec4(1.0f,1.0f,1.0f,1.0f); // A better implementation may store a type per-item. For the sample let's just parse the text.
|
||||
if (strstr(item, "[error]")) col = ImColor(1.0f,0.4f,0.4f,1.0f);
|
||||
else if (strncmp(item, "# ", 2) == 0) col = ImColor(1.0f,0.78f,0.58f,1.0f);
|
||||
ImGui::PushStyleColor(ImGuiCol_Text, col);
|
||||
ImGui::TextUnformatted(item);
|
||||
ImGui::PopStyleColor();
|
||||
@ -2440,10 +2490,10 @@ static void ShowExampleAppLongText(bool* p_open)
|
||||
{
|
||||
// Multiple calls to Text(), manually coarsely clipped - demonstrate how to use the ImGuiListClipper helper.
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0,0));
|
||||
ImGuiListClipper clipper(lines, ImGui::GetTextLineHeightWithSpacing()); // Here we changed spacing is zero anyway so we could use GetTextLineHeight(), but _WithSpacing() is typically more correct
|
||||
for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; i++)
|
||||
ImGui::Text("%i The quick brown fox jumps over the lazy dog\n", i);
|
||||
clipper.End();
|
||||
ImGuiListClipper clipper(lines);
|
||||
while (clipper.Step())
|
||||
for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; i++)
|
||||
ImGui::Text("%i The quick brown fox jumps over the lazy dog", i);
|
||||
ImGui::PopStyleVar();
|
||||
break;
|
||||
}
|
||||
@ -2451,7 +2501,7 @@ static void ShowExampleAppLongText(bool* p_open)
|
||||
// Multiple calls to Text(), not clipped (slow)
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0,0));
|
||||
for (int i = 0; i < lines; i++)
|
||||
ImGui::Text("%i The quick brown fox jumps over the lazy dog\n", i);
|
||||
ImGui::Text("%i The quick brown fox jumps over the lazy dog", i);
|
||||
ImGui::PopStyleVar();
|
||||
break;
|
||||
}
|
||||
|
@ -1143,7 +1143,8 @@ ImFont* ImFontAtlas::AddFont(const ImFontConfig* font_cfg)
|
||||
|
||||
ConfigData.push_back(*font_cfg);
|
||||
ImFontConfig& new_font_cfg = ConfigData.back();
|
||||
new_font_cfg.DstFont = Fonts.back();
|
||||
if (!new_font_cfg.DstFont)
|
||||
new_font_cfg.DstFont = Fonts.back();
|
||||
if (!new_font_cfg.FontDataOwnedByAtlas)
|
||||
{
|
||||
new_font_cfg.FontData = ImGui::MemAlloc(new_font_cfg.FontDataSize);
|
||||
@ -1153,7 +1154,7 @@ ImFont* ImFontAtlas::AddFont(const ImFontConfig* font_cfg)
|
||||
|
||||
// Invalidate texture
|
||||
ClearTexData();
|
||||
return Fonts.back();
|
||||
return new_font_cfg.DstFont;
|
||||
}
|
||||
|
||||
// Default font TTF is compressed with stb_compress then base85 encoded (see extra_fonts/binary_to_compressed_c.cpp for encoder)
|
||||
|
@ -373,6 +373,7 @@ struct ImGuiContext
|
||||
bool ActiveIdIsAlive;
|
||||
bool ActiveIdIsJustActivated; // Set at the time of activation for one frame
|
||||
bool ActiveIdAllowOverlap; // Set only by active widget
|
||||
ImVec2 ActiveIdClickOffset; // Clicked offset from upper-left corner, if applicable (currently only set by ButtonBehavior)
|
||||
ImGuiWindow* ActiveIdWindow;
|
||||
ImGuiWindow* MovedWindow; // Track the child window we clicked on to move a window.
|
||||
ImGuiID MovedWindowMoveId; // == MovedWindow->RootWindow->MoveId
|
||||
@ -393,6 +394,10 @@ struct ImGuiContext
|
||||
ImGuiSetCond SetNextWindowSizeCond;
|
||||
ImGuiSetCond SetNextWindowContentSizeCond;
|
||||
ImGuiSetCond SetNextWindowCollapsedCond;
|
||||
ImRect SetNextWindowSizeConstraintRect; // Valid if 'SetNextWindowSizeConstraint' is true
|
||||
ImGuiSizeConstraintCallback SetNextWindowSizeConstraintCallback;
|
||||
void* SetNextWindowSizeConstraintCallbackUserData;
|
||||
bool SetNextWindowSizeConstraint;
|
||||
bool SetNextWindowFocus;
|
||||
bool SetNextTreeNodeOpenVal;
|
||||
ImGuiSetCond SetNextTreeNodeOpenCond;
|
||||
@ -410,7 +415,6 @@ struct ImGuiContext
|
||||
ImFont InputTextPasswordFont;
|
||||
ImGuiID ScalarAsInputTextId; // Temporary text input when CTRL+clicking on a slider, etc.
|
||||
ImGuiStorage ColorEditModeStorage; // Store user selection of color edit mode
|
||||
ImVec2 ActiveClickDeltaToCenter;
|
||||
float DragCurrentValue; // Currently dragged value, always float, not rounded by end-user precision settings
|
||||
ImVec2 DragLastMouseDelta;
|
||||
float DragSpeedDefaultRatio; // If speed == 0.0f, uses (max-min) * DragSpeedDefaultRatio
|
||||
@ -458,6 +462,7 @@ struct ImGuiContext
|
||||
ActiveIdIsAlive = false;
|
||||
ActiveIdIsJustActivated = false;
|
||||
ActiveIdAllowOverlap = false;
|
||||
ActiveIdClickOffset = ImVec2(-1,-1);
|
||||
ActiveIdWindow = NULL;
|
||||
MovedWindow = NULL;
|
||||
MovedWindowMoveId = 0;
|
||||
@ -471,11 +476,12 @@ struct ImGuiContext
|
||||
SetNextWindowContentSizeCond = 0;
|
||||
SetNextWindowCollapsedCond = 0;
|
||||
SetNextWindowFocus = false;
|
||||
SetNextWindowSizeConstraintCallback = NULL;
|
||||
SetNextWindowSizeConstraintCallbackUserData = NULL;
|
||||
SetNextTreeNodeOpenVal = false;
|
||||
SetNextTreeNodeOpenCond = 0;
|
||||
|
||||
ScalarAsInputTextId = 0;
|
||||
ActiveClickDeltaToCenter = ImVec2(0.0f, 0.0f);
|
||||
DragCurrentValue = 0.0f;
|
||||
DragLastMouseDelta = ImVec2(0.0f, 0.0f);
|
||||
DragSpeedDefaultRatio = 0.01f;
|
||||
|
BIN
3rdparty/bgfx/examples/assets/textures/alphatest.png
vendored
Normal file
BIN
3rdparty/bgfx/examples/assets/textures/alphatest.png
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.0 KiB |
42
3rdparty/bgfx/examples/common/bounds.cpp
vendored
42
3rdparty/bgfx/examples/common/bounds.cpp
vendored
@ -279,32 +279,26 @@ void calcMinBoundingSphere(Sphere& _sphere, const void* _vertices, uint32_t _num
|
||||
|
||||
void calcPlaneUv(const Plane& _plane, float* _udir, float* _vdir)
|
||||
{
|
||||
const uint8_t axis =
|
||||
bx::fabsolute(_plane.m_normal[0]) > 0.6f ? 0
|
||||
: (bx::fabsolute(_plane.m_normal[1]) > 0.6f ? 1
|
||||
: 2
|
||||
);
|
||||
const uint8_t* index = (uint8_t*)&"\x1\x2\x0\x2\x0\x1"[axis*2];
|
||||
const uint8_t idx0 = *(index );
|
||||
const uint8_t idx1 = *(index+1);
|
||||
const float nx = _plane.m_normal[0];
|
||||
const float ny = _plane.m_normal[1];
|
||||
const float nz = _plane.m_normal[2];
|
||||
|
||||
_udir[0] = 0.0f;
|
||||
_udir[1] = 0.0f;
|
||||
_udir[2] = 0.0f;
|
||||
_udir[idx0] = 1.0f;
|
||||
if (bx::fabsolute(nx) > bx::fabsolute(nz) )
|
||||
{
|
||||
float invLen = 1.0f / bx::fsqrt(nx*nx + nz*nz);
|
||||
_udir[0] = -nz * invLen;
|
||||
_udir[1] = 0.0f;
|
||||
_udir[2] = nx * invLen;
|
||||
}
|
||||
else
|
||||
{
|
||||
float invLen = 1.0f / bx::fsqrt(ny*ny + nz*nz);
|
||||
_udir[0] = 0.0f;
|
||||
_udir[1] = nz * invLen;
|
||||
_udir[2] = -ny * invLen;
|
||||
}
|
||||
|
||||
_vdir[0] = 0.0f;
|
||||
_vdir[1] = 0.0f;
|
||||
_vdir[2] = 0.0f;
|
||||
_vdir[idx1] = 1.0f;
|
||||
|
||||
const float invPlaneAxis = 1.0f / _plane.m_normal[axis];
|
||||
|
||||
_udir[axis] -= bx::vec3Dot(_udir, _plane.m_normal) * invPlaneAxis;
|
||||
bx::vec3Norm(_udir, _udir);
|
||||
|
||||
_vdir[axis] -= bx::vec3Dot(_vdir, _plane.m_normal) * invPlaneAxis;
|
||||
bx::vec3Norm(_vdir, _vdir);
|
||||
bx::vec3Cross(_vdir, _plane.m_normal, _udir);
|
||||
}
|
||||
|
||||
void buildFrustumPlanes(Plane* _result, const float* _viewProj)
|
||||
|
@ -110,7 +110,7 @@ namespace entry
|
||||
const char* argv[1] = { "android.so" };
|
||||
m_mte.m_argc = 1;
|
||||
m_mte.m_argv = const_cast<char**>(argv);
|
||||
|
||||
|
||||
while (0 == m_app->destroyRequested)
|
||||
{
|
||||
int32_t num;
|
||||
@ -140,7 +140,7 @@ namespace entry
|
||||
// Command from main thread: a new ANativeWindow is ready for use. Upon
|
||||
// receiving this command, android_app->window will contain the new window
|
||||
// surface.
|
||||
if (m_window == NULL)
|
||||
if (m_window != m_app->window)
|
||||
{
|
||||
m_window = m_app->window;
|
||||
bgfx::androidSetWindow(m_window);
|
||||
@ -152,7 +152,10 @@ namespace entry
|
||||
WindowHandle defaultWindow = { 0 };
|
||||
m_eventQueue.postSizeEvent(defaultWindow, width, height);
|
||||
|
||||
m_thread.init(MainThreadEntry::threadFunc, &m_mte);
|
||||
if (!m_thread.isRunning() )
|
||||
{
|
||||
m_thread.init(MainThreadEntry::threadFunc, &m_mte);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
|
5
3rdparty/bgfx/src/bgfx.cpp
vendored
5
3rdparty/bgfx/src/bgfx.cpp
vendored
@ -285,6 +285,7 @@ namespace bgfx
|
||||
static bool s_renderFrameCalled = false;
|
||||
InternalData g_internalData;
|
||||
PlatformData g_platformData;
|
||||
bool g_platformDataChangedSinceReset = false;
|
||||
|
||||
void AllocatorStub::checkLeaks()
|
||||
{
|
||||
@ -305,13 +306,13 @@ namespace bgfx
|
||||
{
|
||||
BGFX_FATAL(true
|
||||
&& g_platformData.ndt == _data.ndt
|
||||
&& g_platformData.nwh == _data.nwh
|
||||
&& g_platformData.context == _data.context
|
||||
, Fatal::UnableToInitialize
|
||||
, "Only backbuffer pointer can be changed after initialization!"
|
||||
, "Only backbuffer pointer and native window handle can be changed after initialization!"
|
||||
);
|
||||
}
|
||||
memcpy(&g_platformData, &_data, sizeof(PlatformData) );
|
||||
g_platformDataChangedSinceReset = true;
|
||||
}
|
||||
|
||||
const InternalData* getInternalData()
|
||||
|
7
3rdparty/bgfx/src/bgfx_p.h
vendored
7
3rdparty/bgfx/src/bgfx_p.h
vendored
@ -264,6 +264,7 @@ namespace bgfx
|
||||
{
|
||||
extern InternalData g_internalData;
|
||||
extern PlatformData g_platformData;
|
||||
extern bool g_platformDataChangedSinceReset;
|
||||
|
||||
#if BGFX_CONFIG_MAX_DRAW_CALLS < (64<<10)
|
||||
typedef uint16_t RenderItemCount;
|
||||
@ -2134,7 +2135,11 @@ namespace bgfx
|
||||
BX_WARN(0 != _width && 0 != _height, "Frame buffer resolution width or height cannot be 0 (width %d, height %d).", _width, _height);
|
||||
m_resolution.m_width = bx::uint32_max(1, _width);
|
||||
m_resolution.m_height = bx::uint32_max(1, _height);
|
||||
m_resolution.m_flags = _flags;
|
||||
m_resolution.m_flags = 0
|
||||
| _flags
|
||||
| (g_platformDataChangedSinceReset ? BGFX_RESET_INTERNAL_FORCE : 0)
|
||||
;
|
||||
g_platformDataChangedSinceReset = false;
|
||||
|
||||
m_flipAfterRender = !!(_flags & BGFX_RESET_FLIP_AFTER_RENDER);
|
||||
|
||||
|
8
3rdparty/bgfx/src/glcontext_egl.cpp
vendored
8
3rdparty/bgfx/src/glcontext_egl.cpp
vendored
@ -343,6 +343,14 @@ EGL_IMPORT
|
||||
# if BX_PLATFORM_ANDROID
|
||||
if (NULL != m_display)
|
||||
{
|
||||
EGLNativeWindowType nwh = (EGLNativeWindowType )g_platformData.nwh;
|
||||
eglMakeCurrent(EGL_NO_DISPLAY, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
|
||||
eglDestroySurface(m_display, m_surface);
|
||||
m_surface = eglCreateWindowSurface(m_display, m_config, nwh, NULL);
|
||||
BGFX_FATAL(m_surface != EGL_NO_SURFACE, Fatal::UnableToInitialize, "Failed to create surface.");
|
||||
EGLBoolean success = eglMakeCurrent(m_display, m_surface, m_surface, m_context);
|
||||
BGFX_FATAL(success, Fatal::UnableToInitialize, "Failed to set context.");
|
||||
|
||||
EGLint format;
|
||||
eglGetConfigAttrib(m_display, m_config, EGL_NATIVE_VISUAL_ID, &format);
|
||||
ANativeWindow_setBuffersGeometry( (ANativeWindow*)g_platformData.nwh, _width, _height, format);
|
||||
|
9
3rdparty/bgfx/src/image.cpp
vendored
9
3rdparty/bgfx/src/image.cpp
vendored
@ -2112,7 +2112,7 @@ namespace bgfx
|
||||
|
||||
{ 8, 0, 8, 0 },
|
||||
{ 4, 4, 4, 4 },
|
||||
{ 4, 4, 0, 0 },
|
||||
{ 4, 4, 4, 4 },
|
||||
{ 0, 8, 0, 8 },
|
||||
};
|
||||
|
||||
@ -2247,7 +2247,7 @@ namespace bgfx
|
||||
*_r += bitRangeConvert( (_block >> 10) & 0x1f, 5, 8) * _factor;
|
||||
*_g += bitRangeConvert( (_block >> 5) & 0x1f, 5, 8) * _factor;
|
||||
*_b += bitRangeConvert( (_block >> 1) & 0x0f, 4, 8) * _factor;
|
||||
*_a += 255;
|
||||
*_a += 255 * _factor;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -2265,7 +2265,7 @@ namespace bgfx
|
||||
*_r += bitRangeConvert( (_block >> 26) & 0x1f, 5, 8) * _factor;
|
||||
*_g += bitRangeConvert( (_block >> 21) & 0x1f, 5, 8) * _factor;
|
||||
*_b += bitRangeConvert( (_block >> 16) & 0x1f, 5, 8) * _factor;
|
||||
*_a += 255;
|
||||
*_a += 255 * _factor;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -3191,7 +3191,7 @@ namespace bgfx
|
||||
_imageContainer.m_height = height;
|
||||
_imageContainer.m_depth = depth;
|
||||
_imageContainer.m_format = format;
|
||||
_imageContainer.m_numMips = uint8_t(numMips);
|
||||
_imageContainer.m_numMips = uint8_t(bx::uint32_max(numMips, 1) );
|
||||
_imageContainer.m_hasAlpha = hasAlpha;
|
||||
_imageContainer.m_cubeMap = numFaces > 1;
|
||||
_imageContainer.m_ktx = false;
|
||||
@ -3248,6 +3248,7 @@ namespace bgfx
|
||||
return true;
|
||||
}
|
||||
|
||||
BX_TRACE("Unrecognized image format (magic: 0x%08x)!", magic);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
10
3rdparty/bgfx/src/renderer_gl.cpp
vendored
10
3rdparty/bgfx/src/renderer_gl.cpp
vendored
@ -6198,7 +6198,15 @@ namespace bgfx { namespace gl
|
||||
}
|
||||
else
|
||||
{
|
||||
GL_CHECK(glDisable(GL_DEPTH_TEST) );
|
||||
if (BGFX_STATE_DEPTH_WRITE & newFlags)
|
||||
{
|
||||
GL_CHECK(glEnable(GL_DEPTH_TEST) );
|
||||
GL_CHECK(glDepthFunc(GL_ALWAYS) );
|
||||
}
|
||||
else
|
||||
{
|
||||
GL_CHECK(glDisable(GL_DEPTH_TEST) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
76
3rdparty/bgfx/tools/texturev/texturev.cpp
vendored
76
3rdparty/bgfx/tools/texturev/texturev.cpp
vendored
@ -80,6 +80,11 @@ static const InputBinding s_bindingView[] =
|
||||
{ entry::Key::PageUp, entry::Modifier::None, 1, NULL, "view file-pgup" },
|
||||
{ entry::Key::PageDown, entry::Modifier::None, 1, NULL, "view file-pgdown" },
|
||||
|
||||
{ entry::Key::KeyR, entry::Modifier::None, 1, NULL, "view rgb r" },
|
||||
{ entry::Key::KeyG, entry::Modifier::None, 1, NULL, "view rgb g" },
|
||||
{ entry::Key::KeyB, entry::Modifier::None, 1, NULL, "view rgb b" },
|
||||
{ entry::Key::KeyA, entry::Modifier::None, 1, NULL, "view rgb a" },
|
||||
|
||||
{ entry::Key::KeyH, entry::Modifier::None, 1, NULL, "view help" },
|
||||
|
||||
INPUT_BINDING_END
|
||||
@ -105,8 +110,10 @@ struct View
|
||||
: m_fileIndex(0)
|
||||
, m_scaleFn(0)
|
||||
, m_mip(0)
|
||||
, m_abgr(UINT32_MAX)
|
||||
, m_zoom(1.0f)
|
||||
, m_filter(true)
|
||||
, m_alpha(false)
|
||||
, m_help(false)
|
||||
{
|
||||
}
|
||||
@ -191,6 +198,33 @@ struct View
|
||||
++m_fileIndex;
|
||||
m_fileIndex = bx::uint32_min(m_fileIndex, numFiles);
|
||||
}
|
||||
else if (0 == strcmp(_argv[1], "rgb") )
|
||||
{
|
||||
if (_argc >= 3)
|
||||
{
|
||||
if (_argv[2][0] == 'r')
|
||||
{
|
||||
m_abgr ^= 0x000000ff;
|
||||
}
|
||||
else if (_argv[2][0] == 'g')
|
||||
{
|
||||
m_abgr ^= 0x0000ff00;
|
||||
}
|
||||
else if (_argv[2][0] == 'b')
|
||||
{
|
||||
m_abgr ^= 0x00ff0000;
|
||||
}
|
||||
else if (_argv[2][0] == 'a')
|
||||
{
|
||||
m_alpha ^= true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_abgr = UINT32_MAX;
|
||||
m_alpha = false;
|
||||
}
|
||||
}
|
||||
else if (0 == strcmp(_argv[1], "help") )
|
||||
{
|
||||
m_help ^= true;
|
||||
@ -260,8 +294,10 @@ struct View
|
||||
uint32_t m_fileIndex;
|
||||
uint32_t m_scaleFn;
|
||||
uint32_t m_mip;
|
||||
uint32_t m_abgr;
|
||||
float m_zoom;
|
||||
bool m_filter;
|
||||
bool m_alpha;
|
||||
bool m_help;
|
||||
};
|
||||
|
||||
@ -294,7 +330,7 @@ struct PosUvColorVertex
|
||||
|
||||
bgfx::VertexDecl PosUvColorVertex::ms_decl;
|
||||
|
||||
bool screenQuad(int32_t _x, int32_t _y, int32_t _width, uint32_t _height, bool _originBottomLeft = false)
|
||||
bool screenQuad(int32_t _x, int32_t _y, int32_t _width, uint32_t _height, uint32_t _abgr, bool _originBottomLeft = false)
|
||||
{
|
||||
if (bgfx::checkAvailTransientVertexBuffer(6, PosUvColorVertex::ms_decl) )
|
||||
{
|
||||
@ -349,12 +385,12 @@ bool screenQuad(int32_t _x, int32_t _y, int32_t _width, uint32_t _height, bool _
|
||||
vertex[5].m_u = minu;
|
||||
vertex[5].m_v = minv;
|
||||
|
||||
vertex[0].m_abgr = UINT32_MAX;
|
||||
vertex[1].m_abgr = UINT32_MAX;
|
||||
vertex[2].m_abgr = UINT32_MAX;
|
||||
vertex[3].m_abgr = UINT32_MAX;
|
||||
vertex[4].m_abgr = UINT32_MAX;
|
||||
vertex[5].m_abgr = UINT32_MAX;
|
||||
vertex[0].m_abgr = _abgr;
|
||||
vertex[1].m_abgr = _abgr;
|
||||
vertex[2].m_abgr = _abgr;
|
||||
vertex[3].m_abgr = _abgr;
|
||||
vertex[4].m_abgr = _abgr;
|
||||
vertex[5].m_abgr = _abgr;
|
||||
|
||||
bgfx::setVertexBuffer(&vb);
|
||||
|
||||
@ -697,22 +733,26 @@ int _main_(int _argc, char** _argv)
|
||||
|
||||
ImGui::Text("Key bindings:\n\n");
|
||||
|
||||
ImGui::TextColored(ImVec4(1.0f, 1.0f, 0.0f, 1.0f), "ESC"); ImGui::SameLine(64); ImGui::Text("Exit.");
|
||||
ImGui::TextColored(ImVec4(1.0f, 1.0f, 0.0f, 1.0f), "h"); ImGui::SameLine(64); ImGui::Text("Toggle help screen.");
|
||||
ImGui::TextColored(ImVec4(1.0f, 1.0f, 0.0f, 1.0f), "f"); ImGui::SameLine(64); ImGui::Text("Toggle full-screen.");
|
||||
ImGui::TextColored(ImVec4(1.0f, 1.0f, 0.0f, 1.0f), "ESC"); ImGui::SameLine(64); ImGui::Text("Exit.");
|
||||
ImGui::TextColored(ImVec4(1.0f, 1.0f, 0.0f, 1.0f), "h"); ImGui::SameLine(64); ImGui::Text("Toggle help screen.");
|
||||
ImGui::TextColored(ImVec4(1.0f, 1.0f, 0.0f, 1.0f), "f"); ImGui::SameLine(64); ImGui::Text("Toggle full-screen.");
|
||||
ImGui::NextLine();
|
||||
|
||||
ImGui::TextColored(ImVec4(1.0f, 1.0f, 0.0f, 1.0f), "-"); ImGui::SameLine(64); ImGui::Text("Zoom out.");
|
||||
ImGui::TextColored(ImVec4(1.0f, 1.0f, 0.0f, 1.0f), "="); ImGui::SameLine(64); ImGui::Text("Zoom in.");
|
||||
ImGui::TextColored(ImVec4(1.0f, 1.0f, 0.0f, 1.0f), "-"); ImGui::SameLine(64); ImGui::Text("Zoom out.");
|
||||
ImGui::TextColored(ImVec4(1.0f, 1.0f, 0.0f, 1.0f), "="); ImGui::SameLine(64); ImGui::Text("Zoom in.");
|
||||
ImGui::NextLine();
|
||||
|
||||
ImGui::TextColored(ImVec4(1.0f, 1.0f, 0.0f, 1.0f), ","); ImGui::SameLine(64); ImGui::Text("MIP level up.");
|
||||
ImGui::TextColored(ImVec4(1.0f, 1.0f, 0.0f, 1.0f), "."); ImGui::SameLine(64); ImGui::Text("MIP level down.");
|
||||
ImGui::TextColored(ImVec4(1.0f, 1.0f, 0.0f, 1.0f), "/"); ImGui::SameLine(64); ImGui::Text("Toggle linear/point texture sampling.");
|
||||
ImGui::TextColored(ImVec4(1.0f, 1.0f, 0.0f, 1.0f), ","); ImGui::SameLine(64); ImGui::Text("MIP level up.");
|
||||
ImGui::TextColored(ImVec4(1.0f, 1.0f, 0.0f, 1.0f), "."); ImGui::SameLine(64); ImGui::Text("MIP level down.");
|
||||
ImGui::TextColored(ImVec4(1.0f, 1.0f, 0.0f, 1.0f), "/"); ImGui::SameLine(64); ImGui::Text("Toggle linear/point texture sampling.");
|
||||
ImGui::NextLine();
|
||||
|
||||
ImGui::TextColored(ImVec4(1.0f, 1.0f, 0.0f, 1.0f), "up"); ImGui::SameLine(64); ImGui::Text("Previous texture.");
|
||||
ImGui::TextColored(ImVec4(1.0f, 1.0f, 0.0f, 1.0f), "down"); ImGui::SameLine(64); ImGui::Text("Next texture.");
|
||||
ImGui::TextColored(ImVec4(1.0f, 1.0f, 0.0f, 1.0f), "up"); ImGui::SameLine(64); ImGui::Text("Previous texture.");
|
||||
ImGui::TextColored(ImVec4(1.0f, 1.0f, 0.0f, 1.0f), "down"); ImGui::SameLine(64); ImGui::Text("Next texture.");
|
||||
ImGui::NextLine();
|
||||
|
||||
ImGui::TextColored(ImVec4(1.0f, 1.0f, 0.0f, 1.0f), "r/g/b"); ImGui::SameLine(64); ImGui::Text("Toggle R, G, or B color channel.");
|
||||
ImGui::TextColored(ImVec4(1.0f, 1.0f, 0.0f, 1.0f), "a"); ImGui::SameLine(64); ImGui::Text("Toggle alpha blending.");
|
||||
ImGui::NextLine();
|
||||
|
||||
ImGui::Dummy(ImVec2(0.0f, 0.0f) );
|
||||
@ -797,6 +837,7 @@ int _main_(int _argc, char** _argv)
|
||||
, int(height - view.m_info.height * ss)/2
|
||||
, int(view.m_info.width * ss)
|
||||
, int(view.m_info.height * ss)
|
||||
, view.m_abgr
|
||||
);
|
||||
|
||||
float mtx[16];
|
||||
@ -821,6 +862,7 @@ int _main_(int _argc, char** _argv)
|
||||
bgfx::setState(0
|
||||
| BGFX_STATE_RGB_WRITE
|
||||
| BGFX_STATE_ALPHA_WRITE
|
||||
| (view.m_alpha ? BGFX_STATE_BLEND_ALPHA : BGFX_STATE_NONE)
|
||||
);
|
||||
bgfx::submit(0, view.m_info.cubeMap ? textureCubeProgram : textureProgram);
|
||||
|
||||
|
6
3rdparty/bx/include/bx/readerwriter.h
vendored
6
3rdparty/bx/include/bx/readerwriter.h
vendored
@ -374,7 +374,7 @@ namespace bx
|
||||
switch (_whence)
|
||||
{
|
||||
case Whence::Begin:
|
||||
m_pos = _offset;
|
||||
m_pos = int64_clamp(_offset, 0, m_top);
|
||||
break;
|
||||
|
||||
case Whence::Current:
|
||||
@ -434,7 +434,7 @@ namespace bx
|
||||
switch (_whence)
|
||||
{
|
||||
case Whence::Begin:
|
||||
m_pos = _offset;
|
||||
m_pos = int64_clamp(_offset, 0, m_top);
|
||||
break;
|
||||
|
||||
case Whence::Current:
|
||||
@ -506,7 +506,7 @@ namespace bx
|
||||
switch (_whence)
|
||||
{
|
||||
case Whence::Begin:
|
||||
m_pos = _offset;
|
||||
m_pos = int64_clamp(_offset, 0, m_top);
|
||||
break;
|
||||
|
||||
case Whence::Current:
|
||||
|
5
3rdparty/bx/include/bx/thread.h
vendored
5
3rdparty/bx/include/bx/thread.h
vendored
@ -8,6 +8,9 @@
|
||||
|
||||
#if BX_PLATFORM_POSIX
|
||||
# include <pthread.h>
|
||||
# if BX_PLATFORM_BSD
|
||||
# include <pthread_np.h>
|
||||
# endif
|
||||
# if defined(__GLIBC__) && !( (__GLIBC__ > 2) || ( (__GLIBC__ == 2) && (__GLIBC_MINOR__ >= 12) ) )
|
||||
# include <sys/prctl.h>
|
||||
# endif // defined(__GLIBC__) ...
|
||||
@ -164,7 +167,7 @@ namespace bx
|
||||
#ifdef __NetBSD__
|
||||
pthread_setname_np(m_handle, "%s", (void *)_name);
|
||||
#else
|
||||
pthread_setname_np(m_handle, _name);
|
||||
pthread_set_name_np(m_handle, _name);
|
||||
#endif
|
||||
#elif BX_PLATFORM_WINDOWS && BX_COMPILER_MSVC
|
||||
# pragma pack(push, 8)
|
||||
|
BIN
3rdparty/bx/tools/bin/darwin/genie
vendored
BIN
3rdparty/bx/tools/bin/darwin/genie
vendored
Binary file not shown.
BIN
3rdparty/bx/tools/bin/linux/genie
vendored
BIN
3rdparty/bx/tools/bin/linux/genie
vendored
Binary file not shown.
BIN
3rdparty/bx/tools/bin/windows/genie.exe
vendored
BIN
3rdparty/bx/tools/bin/windows/genie.exe
vendored
Binary file not shown.
28
3rdparty/http-parser/.gitignore
vendored
28
3rdparty/http-parser/.gitignore
vendored
@ -1,28 +0,0 @@
|
||||
/out/
|
||||
core
|
||||
tags
|
||||
*.o
|
||||
test
|
||||
test_g
|
||||
test_fast
|
||||
bench
|
||||
url_parser
|
||||
parsertrace
|
||||
parsertrace_g
|
||||
*.mk
|
||||
*.Makefile
|
||||
*.so.*
|
||||
*.a
|
||||
|
||||
|
||||
# Visual Studio uglies
|
||||
*.suo
|
||||
*.sln
|
||||
*.vcxproj
|
||||
*.vcxproj.filters
|
||||
*.vcxproj.user
|
||||
*.opensdf
|
||||
*.ncrunchsolution*
|
||||
*.sdf
|
||||
*.vsp
|
||||
*.psess
|
8
3rdparty/http-parser/.mailmap
vendored
8
3rdparty/http-parser/.mailmap
vendored
@ -1,8 +0,0 @@
|
||||
# update AUTHORS with:
|
||||
# git log --all --reverse --format='%aN <%aE>' | perl -ne 'BEGIN{print "# Authors ordered by first contribution.\n"} print unless $h{$_}; $h{$_} = 1' > AUTHORS
|
||||
Ryan Dahl <ry@tinyclouds.org>
|
||||
Salman Haq <salman.haq@asti-usa.com>
|
||||
Simon Zimmermann <simonz05@gmail.com>
|
||||
Thomas LE ROUX <thomas@november-eleven.fr> LE ROUX Thomas <thomas@procheo.fr>
|
||||
Thomas LE ROUX <thomas@november-eleven.fr> Thomas LE ROUX <thomas@procheo.fr>
|
||||
Fedor Indutny <fedor@indutny.com>
|
13
3rdparty/http-parser/.travis.yml
vendored
13
3rdparty/http-parser/.travis.yml
vendored
@ -1,13 +0,0 @@
|
||||
language: c
|
||||
|
||||
compiler:
|
||||
- clang
|
||||
- gcc
|
||||
|
||||
script:
|
||||
- "make"
|
||||
|
||||
notifications:
|
||||
email: false
|
||||
irc:
|
||||
- "irc.freenode.net#node-ci"
|
67
3rdparty/http-parser/AUTHORS
vendored
67
3rdparty/http-parser/AUTHORS
vendored
@ -1,67 +0,0 @@
|
||||
# Authors ordered by first contribution.
|
||||
Ryan Dahl <ry@tinyclouds.org>
|
||||
Jeremy Hinegardner <jeremy@hinegardner.org>
|
||||
Sergey Shepelev <temotor@gmail.com>
|
||||
Joe Damato <ice799@gmail.com>
|
||||
tomika <tomika_nospam@freemail.hu>
|
||||
Phoenix Sol <phoenix@burninglabs.com>
|
||||
Cliff Frey <cliff@meraki.com>
|
||||
Ewen Cheslack-Postava <ewencp@cs.stanford.edu>
|
||||
Santiago Gala <sgala@apache.org>
|
||||
Tim Becker <tim.becker@syngenio.de>
|
||||
Jeff Terrace <jterrace@gmail.com>
|
||||
Ben Noordhuis <info@bnoordhuis.nl>
|
||||
Nathan Rajlich <nathan@tootallnate.net>
|
||||
Mark Nottingham <mnot@mnot.net>
|
||||
Aman Gupta <aman@tmm1.net>
|
||||
Tim Becker <tim.becker@kuriositaet.de>
|
||||
Sean Cunningham <sean.cunningham@mandiant.com>
|
||||
Peter Griess <pg@std.in>
|
||||
Salman Haq <salman.haq@asti-usa.com>
|
||||
Cliff Frey <clifffrey@gmail.com>
|
||||
Jon Kolb <jon@b0g.us>
|
||||
Fouad Mardini <f.mardini@gmail.com>
|
||||
Paul Querna <pquerna@apache.org>
|
||||
Felix Geisendörfer <felix@debuggable.com>
|
||||
koichik <koichik@improvement.jp>
|
||||
Andre Caron <andre.l.caron@gmail.com>
|
||||
Ivo Raisr <ivosh@ivosh.net>
|
||||
James McLaughlin <jamie@lacewing-project.org>
|
||||
David Gwynne <loki@animata.net>
|
||||
Thomas LE ROUX <thomas@november-eleven.fr>
|
||||
Randy Rizun <rrizun@ortivawireless.com>
|
||||
Andre Louis Caron <andre.louis.caron@usherbrooke.ca>
|
||||
Simon Zimmermann <simonz05@gmail.com>
|
||||
Erik Dubbelboer <erik@dubbelboer.com>
|
||||
Martell Malone <martellmalone@gmail.com>
|
||||
Bertrand Paquet <bpaquet@octo.com>
|
||||
BogDan Vatra <bogdan@kde.org>
|
||||
Peter Faiman <peter@thepicard.org>
|
||||
Corey Richardson <corey@octayn.net>
|
||||
Tóth Tamás <tomika_nospam@freemail.hu>
|
||||
Cam Swords <cam.swords@gmail.com>
|
||||
Chris Dickinson <christopher.s.dickinson@gmail.com>
|
||||
Uli Köhler <ukoehler@btronik.de>
|
||||
Charlie Somerville <charlie@charliesomerville.com>
|
||||
Patrik Stutz <patrik.stutz@gmail.com>
|
||||
Fedor Indutny <fedor.indutny@gmail.com>
|
||||
runner <runner.mei@gmail.com>
|
||||
Alexis Campailla <alexis@janeasystems.com>
|
||||
David Wragg <david@wragg.org>
|
||||
Vinnie Falco <vinnie.falco@gmail.com>
|
||||
Alex Butum <alexbutum@linux.com>
|
||||
Rex Feng <rexfeng@gmail.com>
|
||||
Alex Kocharin <alex@kocharin.ru>
|
||||
Mark Koopman <markmontymark@yahoo.com>
|
||||
Helge Heß <me@helgehess.eu>
|
||||
Alexis La Goutte <alexis.lagoutte@gmail.com>
|
||||
George Miroshnykov <george.miroshnykov@gmail.com>
|
||||
Maciej Małecki <me@mmalecki.com>
|
||||
Marc O'Morain <github.com@marcomorain.com>
|
||||
Jeff Pinner <jpinner@twitter.com>
|
||||
Timothy J Fontaine <tjfontaine@gmail.com>
|
||||
Akagi201 <akagi201@gmail.com>
|
||||
Romain Giraud <giraud.romain@gmail.com>
|
||||
Jay Satiro <raysatiro@yahoo.com>
|
||||
Arne Steen <Arne.Steen@gmx.de>
|
||||
Kjell Schubert <kjell.schubert@gmail.com>
|
23
3rdparty/http-parser/LICENSE-MIT
vendored
23
3rdparty/http-parser/LICENSE-MIT
vendored
@ -1,23 +0,0 @@
|
||||
http_parser.c is based on src/http/ngx_http_parse.c from NGINX copyright
|
||||
Igor Sysoev.
|
||||
|
||||
Additional changes are licensed under the same terms as NGINX and
|
||||
copyright Joyent, Inc. and other Node contributors. All rights reserved.
|
||||
|
||||
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.
|
136
3rdparty/http-parser/Makefile
vendored
136
3rdparty/http-parser/Makefile
vendored
@ -1,136 +0,0 @@
|
||||
# Copyright Joyent, Inc. and other Node contributors. All rights reserved.
|
||||
#
|
||||
# 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.
|
||||
|
||||
PLATFORM ?= $(shell sh -c 'uname -s | tr "[A-Z]" "[a-z]"')
|
||||
SONAME ?= libhttp_parser.so.2.5.0
|
||||
|
||||
CC?=gcc
|
||||
AR?=ar
|
||||
|
||||
CPPFLAGS ?=
|
||||
LDFLAGS ?=
|
||||
|
||||
CPPFLAGS += -I.
|
||||
CPPFLAGS_DEBUG = $(CPPFLAGS) -DHTTP_PARSER_STRICT=1
|
||||
CPPFLAGS_DEBUG += $(CPPFLAGS_DEBUG_EXTRA)
|
||||
CPPFLAGS_FAST = $(CPPFLAGS) -DHTTP_PARSER_STRICT=0
|
||||
CPPFLAGS_FAST += $(CPPFLAGS_FAST_EXTRA)
|
||||
CPPFLAGS_BENCH = $(CPPFLAGS_FAST)
|
||||
|
||||
CFLAGS += -Wall -Wextra -Werror
|
||||
CFLAGS_DEBUG = $(CFLAGS) -O0 -g $(CFLAGS_DEBUG_EXTRA)
|
||||
CFLAGS_FAST = $(CFLAGS) -O3 $(CFLAGS_FAST_EXTRA)
|
||||
CFLAGS_BENCH = $(CFLAGS_FAST) -Wno-unused-parameter
|
||||
CFLAGS_LIB = $(CFLAGS_FAST) -fPIC
|
||||
|
||||
LDFLAGS_LIB = $(LDFLAGS) -shared
|
||||
|
||||
INSTALL ?= install
|
||||
PREFIX ?= $(DESTDIR)/usr/local
|
||||
LIBDIR = $(PREFIX)/lib
|
||||
INCLUDEDIR = $(PREFIX)/include
|
||||
|
||||
ifneq (darwin,$(PLATFORM))
|
||||
# TODO(bnoordhuis) The native SunOS linker expects -h rather than -soname...
|
||||
LDFLAGS_LIB += -Wl,-soname=$(SONAME)
|
||||
endif
|
||||
|
||||
test: test_g test_fast
|
||||
./test_g
|
||||
./test_fast
|
||||
|
||||
test_g: http_parser_g.o test_g.o
|
||||
$(CC) $(CFLAGS_DEBUG) $(LDFLAGS) http_parser_g.o test_g.o -o $@
|
||||
|
||||
test_g.o: test.c http_parser.h Makefile
|
||||
$(CC) $(CPPFLAGS_DEBUG) $(CFLAGS_DEBUG) -c test.c -o $@
|
||||
|
||||
http_parser_g.o: http_parser.c http_parser.h Makefile
|
||||
$(CC) $(CPPFLAGS_DEBUG) $(CFLAGS_DEBUG) -c http_parser.c -o $@
|
||||
|
||||
test_fast: http_parser.o test.o http_parser.h
|
||||
$(CC) $(CFLAGS_FAST) $(LDFLAGS) http_parser.o test.o -o $@
|
||||
|
||||
test.o: test.c http_parser.h Makefile
|
||||
$(CC) $(CPPFLAGS_FAST) $(CFLAGS_FAST) -c test.c -o $@
|
||||
|
||||
bench: http_parser.o bench.o
|
||||
$(CC) $(CFLAGS_BENCH) $(LDFLAGS) http_parser.o bench.o -o $@
|
||||
|
||||
bench.o: bench.c http_parser.h Makefile
|
||||
$(CC) $(CPPFLAGS_BENCH) $(CFLAGS_BENCH) -c bench.c -o $@
|
||||
|
||||
http_parser.o: http_parser.c http_parser.h Makefile
|
||||
$(CC) $(CPPFLAGS_FAST) $(CFLAGS_FAST) -c http_parser.c
|
||||
|
||||
test-run-timed: test_fast
|
||||
while(true) do time ./test_fast > /dev/null; done
|
||||
|
||||
test-valgrind: test_g
|
||||
valgrind ./test_g
|
||||
|
||||
libhttp_parser.o: http_parser.c http_parser.h Makefile
|
||||
$(CC) $(CPPFLAGS_FAST) $(CFLAGS_LIB) -c http_parser.c -o libhttp_parser.o
|
||||
|
||||
library: libhttp_parser.o
|
||||
$(CC) $(LDFLAGS_LIB) -o $(SONAME) $<
|
||||
|
||||
package: http_parser.o
|
||||
$(AR) rcs libhttp_parser.a http_parser.o
|
||||
|
||||
url_parser: http_parser.o contrib/url_parser.c
|
||||
$(CC) $(CPPFLAGS_FAST) $(CFLAGS_FAST) $^ -o $@
|
||||
|
||||
url_parser_g: http_parser_g.o contrib/url_parser.c
|
||||
$(CC) $(CPPFLAGS_DEBUG) $(CFLAGS_DEBUG) $^ -o $@
|
||||
|
||||
parsertrace: http_parser.o contrib/parsertrace.c
|
||||
$(CC) $(CPPFLAGS_FAST) $(CFLAGS_FAST) $^ -o parsertrace
|
||||
|
||||
parsertrace_g: http_parser_g.o contrib/parsertrace.c
|
||||
$(CC) $(CPPFLAGS_DEBUG) $(CFLAGS_DEBUG) $^ -o parsertrace_g
|
||||
|
||||
tags: http_parser.c http_parser.h test.c
|
||||
ctags $^
|
||||
|
||||
install: library
|
||||
$(INSTALL) -D http_parser.h $(INCLUDEDIR)/http_parser.h
|
||||
$(INSTALL) -D $(SONAME) $(LIBDIR)/$(SONAME)
|
||||
ln -s $(LIBDIR)/$(SONAME) $(LIBDIR)/libhttp_parser.so
|
||||
|
||||
install-strip: library
|
||||
$(INSTALL) -D http_parser.h $(INCLUDEDIR)/http_parser.h
|
||||
$(INSTALL) -D -s $(SONAME) $(LIBDIR)/$(SONAME)
|
||||
ln -s $(LIBDIR)/$(SONAME) $(LIBDIR)/libhttp_parser.so
|
||||
|
||||
uninstall:
|
||||
rm $(INCLUDEDIR)/http_parser.h
|
||||
rm $(LIBDIR)/$(SONAME)
|
||||
rm $(LIBDIR)/libhttp_parser.so
|
||||
|
||||
clean:
|
||||
rm -f *.o *.a tags test test_fast test_g \
|
||||
http_parser.tar libhttp_parser.so.* \
|
||||
url_parser url_parser_g parsertrace parsertrace_g
|
||||
|
||||
contrib/url_parser.c: http_parser.h
|
||||
contrib/parsertrace.c: http_parser.h
|
||||
|
||||
.PHONY: clean package test-run test-run-timed test-valgrind install install-strip uninstall
|
183
3rdparty/http-parser/README.md
vendored
183
3rdparty/http-parser/README.md
vendored
@ -1,183 +0,0 @@
|
||||
HTTP Parser
|
||||
===========
|
||||
|
||||
[](https://travis-ci.org/joyent/http-parser)
|
||||
|
||||
This is a parser for HTTP messages written in C. It parses both requests and
|
||||
responses. The parser is designed to be used in performance HTTP
|
||||
applications. It does not make any syscalls nor allocations, it does not
|
||||
buffer data, it can be interrupted at anytime. Depending on your
|
||||
architecture, it only requires about 40 bytes of data per message
|
||||
stream (in a web server that is per connection).
|
||||
|
||||
Features:
|
||||
|
||||
* No dependencies
|
||||
* Handles persistent streams (keep-alive).
|
||||
* Decodes chunked encoding.
|
||||
* Upgrade support
|
||||
* Defends against buffer overflow attacks.
|
||||
|
||||
The parser extracts the following information from HTTP messages:
|
||||
|
||||
* Header fields and values
|
||||
* Content-Length
|
||||
* Request method
|
||||
* Response status code
|
||||
* Transfer-Encoding
|
||||
* HTTP version
|
||||
* Request URL
|
||||
* Message body
|
||||
|
||||
|
||||
Usage
|
||||
-----
|
||||
|
||||
One `http_parser` object is used per TCP connection. Initialize the struct
|
||||
using `http_parser_init()` and set the callbacks. That might look something
|
||||
like this for a request parser:
|
||||
```c
|
||||
http_parser_settings settings;
|
||||
settings.on_url = my_url_callback;
|
||||
settings.on_header_field = my_header_field_callback;
|
||||
/* ... */
|
||||
|
||||
http_parser *parser = malloc(sizeof(http_parser));
|
||||
http_parser_init(parser, HTTP_REQUEST);
|
||||
parser->data = my_socket;
|
||||
```
|
||||
|
||||
When data is received on the socket execute the parser and check for errors.
|
||||
|
||||
```c
|
||||
size_t len = 80*1024, nparsed;
|
||||
char buf[len];
|
||||
ssize_t recved;
|
||||
|
||||
recved = recv(fd, buf, len, 0);
|
||||
|
||||
if (recved < 0) {
|
||||
/* Handle error. */
|
||||
}
|
||||
|
||||
/* Start up / continue the parser.
|
||||
* Note we pass recved==0 to signal that EOF has been received.
|
||||
*/
|
||||
nparsed = http_parser_execute(parser, &settings, buf, recved);
|
||||
|
||||
if (parser->upgrade) {
|
||||
/* handle new protocol */
|
||||
} else if (nparsed != recved) {
|
||||
/* Handle error. Usually just close the connection. */
|
||||
}
|
||||
```
|
||||
|
||||
HTTP needs to know where the end of the stream is. For example, sometimes
|
||||
servers send responses without Content-Length and expect the client to
|
||||
consume input (for the body) until EOF. To tell http_parser about EOF, give
|
||||
`0` as the fourth parameter to `http_parser_execute()`. Callbacks and errors
|
||||
can still be encountered during an EOF, so one must still be prepared
|
||||
to receive them.
|
||||
|
||||
Scalar valued message information such as `status_code`, `method`, and the
|
||||
HTTP version are stored in the parser structure. This data is only
|
||||
temporally stored in `http_parser` and gets reset on each new message. If
|
||||
this information is needed later, copy it out of the structure during the
|
||||
`headers_complete` callback.
|
||||
|
||||
The parser decodes the transfer-encoding for both requests and responses
|
||||
transparently. That is, a chunked encoding is decoded before being sent to
|
||||
the on_body callback.
|
||||
|
||||
|
||||
The Special Problem of Upgrade
|
||||
------------------------------
|
||||
|
||||
HTTP supports upgrading the connection to a different protocol. An
|
||||
increasingly common example of this is the Web Socket protocol which sends
|
||||
a request like
|
||||
|
||||
GET /demo HTTP/1.1
|
||||
Upgrade: WebSocket
|
||||
Connection: Upgrade
|
||||
Host: example.com
|
||||
Origin: http://example.com
|
||||
WebSocket-Protocol: sample
|
||||
|
||||
followed by non-HTTP data.
|
||||
|
||||
(See http://tools.ietf.org/html/draft-hixie-thewebsocketprotocol-75 for more
|
||||
information the Web Socket protocol.)
|
||||
|
||||
To support this, the parser will treat this as a normal HTTP message without a
|
||||
body, issuing both on_headers_complete and on_message_complete callbacks. However
|
||||
http_parser_execute() will stop parsing at the end of the headers and return.
|
||||
|
||||
The user is expected to check if `parser->upgrade` has been set to 1 after
|
||||
`http_parser_execute()` returns. Non-HTTP data begins at the buffer supplied
|
||||
offset by the return value of `http_parser_execute()`.
|
||||
|
||||
|
||||
Callbacks
|
||||
---------
|
||||
|
||||
During the `http_parser_execute()` call, the callbacks set in
|
||||
`http_parser_settings` will be executed. The parser maintains state and
|
||||
never looks behind, so buffering the data is not necessary. If you need to
|
||||
save certain data for later usage, you can do that from the callbacks.
|
||||
|
||||
There are two types of callbacks:
|
||||
|
||||
* notification `typedef int (*http_cb) (http_parser*);`
|
||||
Callbacks: on_message_begin, on_headers_complete, on_message_complete.
|
||||
* data `typedef int (*http_data_cb) (http_parser*, const char *at, size_t length);`
|
||||
Callbacks: (requests only) on_url,
|
||||
(common) on_header_field, on_header_value, on_body;
|
||||
|
||||
Callbacks must return 0 on success. Returning a non-zero value indicates
|
||||
error to the parser, making it exit immediately.
|
||||
|
||||
In case you parse HTTP message in chunks (i.e. `read()` request line
|
||||
from socket, parse, read half headers, parse, etc) your data callbacks
|
||||
may be called more than once. Http-parser guarantees that data pointer is only
|
||||
valid for the lifetime of callback. You can also `read()` into a heap allocated
|
||||
buffer to avoid copying memory around if this fits your application.
|
||||
|
||||
Reading headers may be a tricky task if you read/parse headers partially.
|
||||
Basically, you need to remember whether last header callback was field or value
|
||||
and apply the following logic:
|
||||
|
||||
(on_header_field and on_header_value shortened to on_h_*)
|
||||
------------------------ ------------ --------------------------------------------
|
||||
| State (prev. callback) | Callback | Description/action |
|
||||
------------------------ ------------ --------------------------------------------
|
||||
| nothing (first call) | on_h_field | Allocate new buffer and copy callback data |
|
||||
| | | into it |
|
||||
------------------------ ------------ --------------------------------------------
|
||||
| value | on_h_field | New header started. |
|
||||
| | | Copy current name,value buffers to headers |
|
||||
| | | list and allocate new buffer for new name |
|
||||
------------------------ ------------ --------------------------------------------
|
||||
| field | on_h_field | Previous name continues. Reallocate name |
|
||||
| | | buffer and append callback data to it |
|
||||
------------------------ ------------ --------------------------------------------
|
||||
| field | on_h_value | Value for current header started. Allocate |
|
||||
| | | new buffer and copy callback data to it |
|
||||
------------------------ ------------ --------------------------------------------
|
||||
| value | on_h_value | Value continues. Reallocate value buffer |
|
||||
| | | and append callback data to it |
|
||||
------------------------ ------------ --------------------------------------------
|
||||
|
||||
|
||||
Parsing URLs
|
||||
------------
|
||||
|
||||
A simplistic zero-copy URL parser is provided as `http_parser_parse_url()`.
|
||||
Users of this library may wish to use it to parse URLs constructed from
|
||||
consecutive `on_url` callbacks.
|
||||
|
||||
See examples of reading in headers:
|
||||
|
||||
* [partial example](http://gist.github.com/155877) in C
|
||||
* [from http-parser tests](http://github.com/joyent/http-parser/blob/37a0ff8/test.c#L403) in C
|
||||
* [from Node library](http://github.com/joyent/node/blob/842eaf4/src/http.js#L284) in Javascript
|
111
3rdparty/http-parser/bench.c
vendored
111
3rdparty/http-parser/bench.c
vendored
@ -1,111 +0,0 @@
|
||||
/* Copyright Fedor Indutny. All rights reserved.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
#include "http_parser.h"
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
static const char data[] =
|
||||
"POST /joyent/http-parser HTTP/1.1\r\n"
|
||||
"Host: github.com\r\n"
|
||||
"DNT: 1\r\n"
|
||||
"Accept-Encoding: gzip, deflate, sdch\r\n"
|
||||
"Accept-Language: ru-RU,ru;q=0.8,en-US;q=0.6,en;q=0.4\r\n"
|
||||
"User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) "
|
||||
"AppleWebKit/537.36 (KHTML, like Gecko) "
|
||||
"Chrome/39.0.2171.65 Safari/537.36\r\n"
|
||||
"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,"
|
||||
"image/webp,*/*;q=0.8\r\n"
|
||||
"Referer: https://github.com/joyent/http-parser\r\n"
|
||||
"Connection: keep-alive\r\n"
|
||||
"Transfer-Encoding: chunked\r\n"
|
||||
"Cache-Control: max-age=0\r\n\r\nb\r\nhello world\r\n0\r\n\r\n";
|
||||
static const size_t data_len = sizeof(data) - 1;
|
||||
|
||||
static int on_info(http_parser* p) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int on_data(http_parser* p, const char *at, size_t length) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static http_parser_settings settings = {
|
||||
.on_message_begin = on_info,
|
||||
.on_headers_complete = on_info,
|
||||
.on_message_complete = on_info,
|
||||
.on_header_field = on_data,
|
||||
.on_header_value = on_data,
|
||||
.on_url = on_data,
|
||||
.on_status = on_data,
|
||||
.on_body = on_data
|
||||
};
|
||||
|
||||
int bench(int iter_count, int silent) {
|
||||
struct http_parser parser;
|
||||
int i;
|
||||
int err;
|
||||
struct timeval start;
|
||||
struct timeval end;
|
||||
float rps;
|
||||
|
||||
if (!silent) {
|
||||
err = gettimeofday(&start, NULL);
|
||||
assert(err == 0);
|
||||
}
|
||||
|
||||
for (i = 0; i < iter_count; i++) {
|
||||
size_t parsed;
|
||||
http_parser_init(&parser, HTTP_REQUEST);
|
||||
|
||||
parsed = http_parser_execute(&parser, &settings, data, data_len);
|
||||
assert(parsed == data_len);
|
||||
}
|
||||
|
||||
if (!silent) {
|
||||
err = gettimeofday(&end, NULL);
|
||||
assert(err == 0);
|
||||
|
||||
fprintf(stdout, "Benchmark result:\n");
|
||||
|
||||
rps = (float) (end.tv_sec - start.tv_sec) +
|
||||
(end.tv_usec - start.tv_usec) * 1e-6f;
|
||||
fprintf(stdout, "Took %f seconds to run\n", rps);
|
||||
|
||||
rps = (float) iter_count / rps;
|
||||
fprintf(stdout, "%f req/sec\n", rps);
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
if (argc == 2 && strcmp(argv[1], "infinite") == 0) {
|
||||
for (;;)
|
||||
bench(5000000, 1);
|
||||
return 0;
|
||||
} else {
|
||||
return bench(5000000, 0);
|
||||
}
|
||||
}
|
160
3rdparty/http-parser/contrib/parsertrace.c
vendored
160
3rdparty/http-parser/contrib/parsertrace.c
vendored
@ -1,160 +0,0 @@
|
||||
/* Based on src/http/ngx_http_parse.c from NGINX copyright Igor Sysoev
|
||||
*
|
||||
* Additional changes are licensed under the same terms as NGINX and
|
||||
* copyright Joyent, Inc. and other Node contributors. All rights reserved.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/* Dump what the parser finds to stdout as it happen */
|
||||
|
||||
#include "http_parser.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
int on_message_begin(http_parser* _) {
|
||||
(void)_;
|
||||
printf("\n***MESSAGE BEGIN***\n\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int on_headers_complete(http_parser* _) {
|
||||
(void)_;
|
||||
printf("\n***HEADERS COMPLETE***\n\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int on_message_complete(http_parser* _) {
|
||||
(void)_;
|
||||
printf("\n***MESSAGE COMPLETE***\n\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int on_url(http_parser* _, const char* at, size_t length) {
|
||||
(void)_;
|
||||
printf("Url: %.*s\n", (int)length, at);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int on_header_field(http_parser* _, const char* at, size_t length) {
|
||||
(void)_;
|
||||
printf("Header field: %.*s\n", (int)length, at);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int on_header_value(http_parser* _, const char* at, size_t length) {
|
||||
(void)_;
|
||||
printf("Header value: %.*s\n", (int)length, at);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int on_body(http_parser* _, const char* at, size_t length) {
|
||||
(void)_;
|
||||
printf("Body: %.*s\n", (int)length, at);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void usage(const char* name) {
|
||||
fprintf(stderr,
|
||||
"Usage: %s $type $filename\n"
|
||||
" type: -x, where x is one of {r,b,q}\n"
|
||||
" parses file as a Response, reQuest, or Both\n",
|
||||
name);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
enum http_parser_type file_type;
|
||||
|
||||
if (argc != 3) {
|
||||
usage(argv[0]);
|
||||
}
|
||||
|
||||
char* type = argv[1];
|
||||
if (type[0] != '-') {
|
||||
usage(argv[0]);
|
||||
}
|
||||
|
||||
switch (type[1]) {
|
||||
/* in the case of "-", type[1] will be NUL */
|
||||
case 'r':
|
||||
file_type = HTTP_RESPONSE;
|
||||
break;
|
||||
case 'q':
|
||||
file_type = HTTP_REQUEST;
|
||||
break;
|
||||
case 'b':
|
||||
file_type = HTTP_BOTH;
|
||||
break;
|
||||
default:
|
||||
usage(argv[0]);
|
||||
}
|
||||
|
||||
char* filename = argv[2];
|
||||
FILE* file = fopen(filename, "r");
|
||||
if (file == NULL) {
|
||||
perror("fopen");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
fseek(file, 0, SEEK_END);
|
||||
long file_length = ftell(file);
|
||||
if (file_length == -1) {
|
||||
perror("ftell");
|
||||
goto fail;
|
||||
}
|
||||
fseek(file, 0, SEEK_SET);
|
||||
|
||||
char* data = malloc(file_length);
|
||||
if (fread(data, 1, file_length, file) != (size_t)file_length) {
|
||||
fprintf(stderr, "couldn't read entire file\n");
|
||||
free(data);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
http_parser_settings settings;
|
||||
memset(&settings, 0, sizeof(settings));
|
||||
settings.on_message_begin = on_message_begin;
|
||||
settings.on_url = on_url;
|
||||
settings.on_header_field = on_header_field;
|
||||
settings.on_header_value = on_header_value;
|
||||
settings.on_headers_complete = on_headers_complete;
|
||||
settings.on_body = on_body;
|
||||
settings.on_message_complete = on_message_complete;
|
||||
|
||||
http_parser parser;
|
||||
http_parser_init(&parser, file_type);
|
||||
size_t nparsed = http_parser_execute(&parser, &settings, data, file_length);
|
||||
free(data);
|
||||
|
||||
if (nparsed != (size_t)file_length) {
|
||||
fprintf(stderr,
|
||||
"Error: %s (%s)\n",
|
||||
http_errno_description(HTTP_PARSER_ERRNO(&parser)),
|
||||
http_errno_name(HTTP_PARSER_ERRNO(&parser)));
|
||||
goto fail;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
|
||||
fail:
|
||||
fclose(file);
|
||||
return EXIT_FAILURE;
|
||||
}
|
46
3rdparty/http-parser/contrib/url_parser.c
vendored
46
3rdparty/http-parser/contrib/url_parser.c
vendored
@ -1,46 +0,0 @@
|
||||
#include "http_parser.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
void
|
||||
dump_url (const char *url, const struct http_parser_url *u)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
printf("\tfield_set: 0x%x, port: %u\n", u->field_set, u->port);
|
||||
for (i = 0; i < UF_MAX; i++) {
|
||||
if ((u->field_set & (1 << i)) == 0) {
|
||||
printf("\tfield_data[%u]: unset\n", i);
|
||||
continue;
|
||||
}
|
||||
|
||||
printf("\tfield_data[%u]: off: %u, len: %u, part: %.*s\n",
|
||||
i,
|
||||
u->field_data[i].off,
|
||||
u->field_data[i].len,
|
||||
u->field_data[i].len,
|
||||
url + u->field_data[i].off);
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char ** argv) {
|
||||
struct http_parser_url u;
|
||||
int len, connect, result;
|
||||
|
||||
if (argc != 3) {
|
||||
printf("Syntax : %s connect|get url\n", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
len = strlen(argv[2]);
|
||||
connect = strcmp("connect", argv[1]) == 0 ? 1 : 0;
|
||||
printf("Parsing %s, connect %d\n", argv[2], connect);
|
||||
|
||||
result = http_parser_parse_url(argv[2], len, connect, &u);
|
||||
if (result != 0) {
|
||||
printf("Parse error : %d\n", result);
|
||||
return result;
|
||||
}
|
||||
printf("Parse ok, result : \n");
|
||||
dump_url(argv[2], &u);
|
||||
return 0;
|
||||
}
|
2429
3rdparty/http-parser/http_parser.c
vendored
2429
3rdparty/http-parser/http_parser.c
vendored
File diff suppressed because it is too large
Load Diff
111
3rdparty/http-parser/http_parser.gyp
vendored
111
3rdparty/http-parser/http_parser.gyp
vendored
@ -1,111 +0,0 @@
|
||||
# This file is used with the GYP meta build system.
|
||||
# http://code.google.com/p/gyp/
|
||||
# To build try this:
|
||||
# svn co http://gyp.googlecode.com/svn/trunk gyp
|
||||
# ./gyp/gyp -f make --depth=`pwd` http_parser.gyp
|
||||
# ./out/Debug/test
|
||||
{
|
||||
'target_defaults': {
|
||||
'default_configuration': 'Debug',
|
||||
'configurations': {
|
||||
# TODO: hoist these out and put them somewhere common, because
|
||||
# RuntimeLibrary MUST MATCH across the entire project
|
||||
'Debug': {
|
||||
'defines': [ 'DEBUG', '_DEBUG' ],
|
||||
'cflags': [ '-Wall', '-Wextra', '-O0', '-g', '-ftrapv' ],
|
||||
'msvs_settings': {
|
||||
'VCCLCompilerTool': {
|
||||
'RuntimeLibrary': 1, # static debug
|
||||
},
|
||||
},
|
||||
},
|
||||
'Release': {
|
||||
'defines': [ 'NDEBUG' ],
|
||||
'cflags': [ '-Wall', '-Wextra', '-O3' ],
|
||||
'msvs_settings': {
|
||||
'VCCLCompilerTool': {
|
||||
'RuntimeLibrary': 0, # static release
|
||||
},
|
||||
},
|
||||
}
|
||||
},
|
||||
'msvs_settings': {
|
||||
'VCCLCompilerTool': {
|
||||
},
|
||||
'VCLibrarianTool': {
|
||||
},
|
||||
'VCLinkerTool': {
|
||||
'GenerateDebugInformation': 'true',
|
||||
},
|
||||
},
|
||||
'conditions': [
|
||||
['OS == "win"', {
|
||||
'defines': [
|
||||
'WIN32'
|
||||
],
|
||||
}]
|
||||
],
|
||||
},
|
||||
|
||||
'targets': [
|
||||
{
|
||||
'target_name': 'http_parser',
|
||||
'type': 'static_library',
|
||||
'include_dirs': [ '.' ],
|
||||
'direct_dependent_settings': {
|
||||
'defines': [ 'HTTP_PARSER_STRICT=0' ],
|
||||
'include_dirs': [ '.' ],
|
||||
},
|
||||
'defines': [ 'HTTP_PARSER_STRICT=0' ],
|
||||
'sources': [ './http_parser.c', ],
|
||||
'conditions': [
|
||||
['OS=="win"', {
|
||||
'msvs_settings': {
|
||||
'VCCLCompilerTool': {
|
||||
# Compile as C++. http_parser.c is actually C99, but C++ is
|
||||
# close enough in this case.
|
||||
'CompileAs': 2,
|
||||
},
|
||||
},
|
||||
}]
|
||||
],
|
||||
},
|
||||
|
||||
{
|
||||
'target_name': 'http_parser_strict',
|
||||
'type': 'static_library',
|
||||
'include_dirs': [ '.' ],
|
||||
'direct_dependent_settings': {
|
||||
'defines': [ 'HTTP_PARSER_STRICT=1' ],
|
||||
'include_dirs': [ '.' ],
|
||||
},
|
||||
'defines': [ 'HTTP_PARSER_STRICT=1' ],
|
||||
'sources': [ './http_parser.c', ],
|
||||
'conditions': [
|
||||
['OS=="win"', {
|
||||
'msvs_settings': {
|
||||
'VCCLCompilerTool': {
|
||||
# Compile as C++. http_parser.c is actually C99, but C++ is
|
||||
# close enough in this case.
|
||||
'CompileAs': 2,
|
||||
},
|
||||
},
|
||||
}]
|
||||
],
|
||||
},
|
||||
|
||||
{
|
||||
'target_name': 'test-nonstrict',
|
||||
'type': 'executable',
|
||||
'dependencies': [ 'http_parser' ],
|
||||
'sources': [ 'test.c' ]
|
||||
},
|
||||
|
||||
{
|
||||
'target_name': 'test-strict',
|
||||
'type': 'executable',
|
||||
'dependencies': [ 'http_parser_strict' ],
|
||||
'sources': [ 'test.c' ]
|
||||
}
|
||||
]
|
||||
}
|
342
3rdparty/http-parser/http_parser.h
vendored
342
3rdparty/http-parser/http_parser.h
vendored
@ -1,342 +0,0 @@
|
||||
/* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
#ifndef http_parser_h
|
||||
#define http_parser_h
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Also update SONAME in the Makefile whenever you change these. */
|
||||
#define HTTP_PARSER_VERSION_MAJOR 2
|
||||
#define HTTP_PARSER_VERSION_MINOR 5
|
||||
#define HTTP_PARSER_VERSION_PATCH 0
|
||||
|
||||
#include <sys/types.h>
|
||||
#if defined(_WIN32) && !defined(__MINGW32__) && (!defined(_MSC_VER) || _MSC_VER<1600)
|
||||
#include <BaseTsd.h>
|
||||
#include <stddef.h>
|
||||
typedef __int8 int8_t;
|
||||
typedef unsigned __int8 uint8_t;
|
||||
typedef __int16 int16_t;
|
||||
typedef unsigned __int16 uint16_t;
|
||||
typedef __int32 int32_t;
|
||||
typedef unsigned __int32 uint32_t;
|
||||
typedef __int64 int64_t;
|
||||
typedef unsigned __int64 uint64_t;
|
||||
#else
|
||||
#include <stdint.h>
|
||||
#endif
|
||||
|
||||
/* Compile with -DHTTP_PARSER_STRICT=0 to make less checks, but run
|
||||
* faster
|
||||
*/
|
||||
#ifndef HTTP_PARSER_STRICT
|
||||
# define HTTP_PARSER_STRICT 1
|
||||
#endif
|
||||
|
||||
/* Maximium header size allowed. If the macro is not defined
|
||||
* before including this header then the default is used. To
|
||||
* change the maximum header size, define the macro in the build
|
||||
* environment (e.g. -DHTTP_MAX_HEADER_SIZE=<value>). To remove
|
||||
* the effective limit on the size of the header, define the macro
|
||||
* to a very large number (e.g. -DHTTP_MAX_HEADER_SIZE=0x7fffffff)
|
||||
*/
|
||||
#ifndef HTTP_MAX_HEADER_SIZE
|
||||
# define HTTP_MAX_HEADER_SIZE (80*1024)
|
||||
#endif
|
||||
|
||||
typedef struct http_parser http_parser;
|
||||
typedef struct http_parser_settings http_parser_settings;
|
||||
|
||||
|
||||
/* Callbacks should return non-zero to indicate an error. The parser will
|
||||
* then halt execution.
|
||||
*
|
||||
* The one exception is on_headers_complete. In a HTTP_RESPONSE parser
|
||||
* returning '1' from on_headers_complete will tell the parser that it
|
||||
* should not expect a body. This is used when receiving a response to a
|
||||
* HEAD request which may contain 'Content-Length' or 'Transfer-Encoding:
|
||||
* chunked' headers that indicate the presence of a body.
|
||||
*
|
||||
* http_data_cb does not return data chunks. It will be called arbitrarily
|
||||
* many times for each string. E.G. you might get 10 callbacks for "on_url"
|
||||
* each providing just a few characters more data.
|
||||
*/
|
||||
typedef int (*http_data_cb) (http_parser*, const char *at, size_t length);
|
||||
typedef int (*http_cb) (http_parser*);
|
||||
|
||||
|
||||
/* Request Methods */
|
||||
#define HTTP_METHOD_MAP(XX) \
|
||||
XX(0, DELETE, DELETE) \
|
||||
XX(1, GET, GET) \
|
||||
XX(2, HEAD, HEAD) \
|
||||
XX(3, POST, POST) \
|
||||
XX(4, PUT, PUT) \
|
||||
/* pathological */ \
|
||||
XX(5, CONNECT, CONNECT) \
|
||||
XX(6, OPTIONS, OPTIONS) \
|
||||
XX(7, TRACE, TRACE) \
|
||||
/* webdav */ \
|
||||
XX(8, COPY, COPY) \
|
||||
XX(9, LOCK, LOCK) \
|
||||
XX(10, MKCOL, MKCOL) \
|
||||
XX(11, MOVE, MOVE) \
|
||||
XX(12, PROPFIND, PROPFIND) \
|
||||
XX(13, PROPPATCH, PROPPATCH) \
|
||||
XX(14, SEARCH, SEARCH) \
|
||||
XX(15, UNLOCK, UNLOCK) \
|
||||
/* subversion */ \
|
||||
XX(16, REPORT, REPORT) \
|
||||
XX(17, MKACTIVITY, MKACTIVITY) \
|
||||
XX(18, CHECKOUT, CHECKOUT) \
|
||||
XX(19, MERGE, MERGE) \
|
||||
/* upnp */ \
|
||||
XX(20, MSEARCH, M-SEARCH) \
|
||||
XX(21, NOTIFY, NOTIFY) \
|
||||
XX(22, SUBSCRIBE, SUBSCRIBE) \
|
||||
XX(23, UNSUBSCRIBE, UNSUBSCRIBE) \
|
||||
/* RFC-5789 */ \
|
||||
XX(24, PATCH, PATCH) \
|
||||
XX(25, PURGE, PURGE) \
|
||||
/* CalDAV */ \
|
||||
XX(26, MKCALENDAR, MKCALENDAR) \
|
||||
|
||||
enum http_method
|
||||
{
|
||||
#define XX(num, name, string) HTTP_##name = num,
|
||||
HTTP_METHOD_MAP(XX)
|
||||
#undef XX
|
||||
};
|
||||
|
||||
|
||||
enum http_parser_type { HTTP_REQUEST, HTTP_RESPONSE, HTTP_BOTH };
|
||||
|
||||
|
||||
/* Flag values for http_parser.flags field */
|
||||
enum flags
|
||||
{ F_CHUNKED = 1 << 0
|
||||
, F_CONNECTION_KEEP_ALIVE = 1 << 1
|
||||
, F_CONNECTION_CLOSE = 1 << 2
|
||||
, F_CONNECTION_UPGRADE = 1 << 3
|
||||
, F_TRAILING = 1 << 4
|
||||
, F_UPGRADE = 1 << 5
|
||||
, F_SKIPBODY = 1 << 6
|
||||
};
|
||||
|
||||
|
||||
/* Map for errno-related constants
|
||||
*
|
||||
* The provided argument should be a macro that takes 2 arguments.
|
||||
*/
|
||||
#define HTTP_ERRNO_MAP(XX) \
|
||||
/* No error */ \
|
||||
XX(OK, "success") \
|
||||
\
|
||||
/* Callback-related errors */ \
|
||||
XX(CB_message_begin, "the on_message_begin callback failed") \
|
||||
XX(CB_url, "the on_url callback failed") \
|
||||
XX(CB_header_field, "the on_header_field callback failed") \
|
||||
XX(CB_header_value, "the on_header_value callback failed") \
|
||||
XX(CB_headers_complete, "the on_headers_complete callback failed") \
|
||||
XX(CB_body, "the on_body callback failed") \
|
||||
XX(CB_message_complete, "the on_message_complete callback failed") \
|
||||
XX(CB_status, "the on_status callback failed") \
|
||||
XX(CB_chunk_header, "the on_chunk_header callback failed") \
|
||||
XX(CB_chunk_complete, "the on_chunk_complete callback failed") \
|
||||
\
|
||||
/* Parsing-related errors */ \
|
||||
XX(INVALID_EOF_STATE, "stream ended at an unexpected time") \
|
||||
XX(HEADER_OVERFLOW, \
|
||||
"too many header bytes seen; overflow detected") \
|
||||
XX(CLOSED_CONNECTION, \
|
||||
"data received after completed connection: close message") \
|
||||
XX(INVALID_VERSION, "invalid HTTP version") \
|
||||
XX(INVALID_STATUS, "invalid HTTP status code") \
|
||||
XX(INVALID_METHOD, "invalid HTTP method") \
|
||||
XX(INVALID_URL, "invalid URL") \
|
||||
XX(INVALID_HOST, "invalid host") \
|
||||
XX(INVALID_PORT, "invalid port") \
|
||||
XX(INVALID_PATH, "invalid path") \
|
||||
XX(INVALID_QUERY_STRING, "invalid query string") \
|
||||
XX(INVALID_FRAGMENT, "invalid fragment") \
|
||||
XX(LF_EXPECTED, "LF character expected") \
|
||||
XX(INVALID_HEADER_TOKEN, "invalid character in header") \
|
||||
XX(INVALID_CONTENT_LENGTH, \
|
||||
"invalid character in content-length header") \
|
||||
XX(INVALID_CHUNK_SIZE, \
|
||||
"invalid character in chunk size header") \
|
||||
XX(INVALID_CONSTANT, "invalid constant string") \
|
||||
XX(INVALID_INTERNAL_STATE, "encountered unexpected internal state")\
|
||||
XX(STRICT, "strict mode assertion failed") \
|
||||
XX(PAUSED, "parser is paused") \
|
||||
XX(UNKNOWN, "an unknown error occurred")
|
||||
|
||||
|
||||
/* Define HPE_* values for each errno value above */
|
||||
#define HTTP_ERRNO_GEN(n, s) HPE_##n,
|
||||
enum http_errno {
|
||||
HTTP_ERRNO_MAP(HTTP_ERRNO_GEN)
|
||||
};
|
||||
#undef HTTP_ERRNO_GEN
|
||||
|
||||
|
||||
/* Get an http_errno value from an http_parser */
|
||||
#define HTTP_PARSER_ERRNO(p) ((enum http_errno) (p)->http_errno)
|
||||
|
||||
|
||||
struct http_parser {
|
||||
/** PRIVATE **/
|
||||
unsigned int type : 2; /* enum http_parser_type */
|
||||
unsigned int flags : 7; /* F_* values from 'flags' enum; semi-public */
|
||||
unsigned int state : 7; /* enum state from http_parser.c */
|
||||
unsigned int header_state : 8; /* enum header_state from http_parser.c */
|
||||
unsigned int index : 8; /* index into current matcher */
|
||||
|
||||
uint32_t nread; /* # bytes read in various scenarios */
|
||||
uint64_t content_length; /* # bytes in body (0 if no Content-Length header) */
|
||||
|
||||
/** READ-ONLY **/
|
||||
unsigned short http_major;
|
||||
unsigned short http_minor;
|
||||
unsigned int status_code : 16; /* responses only */
|
||||
unsigned int method : 8; /* requests only */
|
||||
unsigned int http_errno : 7;
|
||||
|
||||
/* 1 = Upgrade header was present and the parser has exited because of that.
|
||||
* 0 = No upgrade header present.
|
||||
* Should be checked when http_parser_execute() returns in addition to
|
||||
* error checking.
|
||||
*/
|
||||
unsigned int upgrade : 1;
|
||||
|
||||
/** PUBLIC **/
|
||||
void *data; /* A pointer to get hook to the "connection" or "socket" object */
|
||||
};
|
||||
|
||||
|
||||
struct http_parser_settings {
|
||||
http_cb on_message_begin;
|
||||
http_data_cb on_url;
|
||||
http_data_cb on_status;
|
||||
http_data_cb on_header_field;
|
||||
http_data_cb on_header_value;
|
||||
http_cb on_headers_complete;
|
||||
http_data_cb on_body;
|
||||
http_cb on_message_complete;
|
||||
/* When on_chunk_header is called, the current chunk length is stored
|
||||
* in parser->content_length.
|
||||
*/
|
||||
http_cb on_chunk_header;
|
||||
http_cb on_chunk_complete;
|
||||
};
|
||||
|
||||
|
||||
enum http_parser_url_fields
|
||||
{ UF_SCHEMA = 0
|
||||
, UF_HOST = 1
|
||||
, UF_PORT = 2
|
||||
, UF_PATH = 3
|
||||
, UF_QUERY = 4
|
||||
, UF_FRAGMENT = 5
|
||||
, UF_USERINFO = 6
|
||||
, UF_MAX = 7
|
||||
};
|
||||
|
||||
|
||||
/* Result structure for http_parser_parse_url().
|
||||
*
|
||||
* Callers should index into field_data[] with UF_* values iff field_set
|
||||
* has the relevant (1 << UF_*) bit set. As a courtesy to clients (and
|
||||
* because we probably have padding left over), we convert any port to
|
||||
* a uint16_t.
|
||||
*/
|
||||
struct http_parser_url {
|
||||
uint16_t field_set; /* Bitmask of (1 << UF_*) values */
|
||||
uint16_t port; /* Converted UF_PORT string */
|
||||
|
||||
struct {
|
||||
uint16_t off; /* Offset into buffer in which field starts */
|
||||
uint16_t len; /* Length of run in buffer */
|
||||
} field_data[UF_MAX];
|
||||
};
|
||||
|
||||
|
||||
/* Returns the library version. Bits 16-23 contain the major version number,
|
||||
* bits 8-15 the minor version number and bits 0-7 the patch level.
|
||||
* Usage example:
|
||||
*
|
||||
* unsigned long version = http_parser_version();
|
||||
* unsigned major = (version >> 16) & 255;
|
||||
* unsigned minor = (version >> 8) & 255;
|
||||
* unsigned patch = version & 255;
|
||||
* printf("http_parser v%u.%u.%u\n", major, minor, patch);
|
||||
*/
|
||||
unsigned long http_parser_version(void);
|
||||
|
||||
void http_parser_init(http_parser *parser, enum http_parser_type type);
|
||||
|
||||
|
||||
/* Initialize http_parser_settings members to 0
|
||||
*/
|
||||
void http_parser_settings_init(http_parser_settings *settings);
|
||||
|
||||
|
||||
/* Executes the parser. Returns number of parsed bytes. Sets
|
||||
* `parser->http_errno` on error. */
|
||||
size_t http_parser_execute(http_parser *parser,
|
||||
const http_parser_settings *settings,
|
||||
const char *data,
|
||||
size_t len);
|
||||
|
||||
|
||||
/* If http_should_keep_alive() in the on_headers_complete or
|
||||
* on_message_complete callback returns 0, then this should be
|
||||
* the last message on the connection.
|
||||
* If you are the server, respond with the "Connection: close" header.
|
||||
* If you are the client, close the connection.
|
||||
*/
|
||||
int http_should_keep_alive(const http_parser *parser);
|
||||
|
||||
/* Returns a string version of the HTTP method. */
|
||||
const char *http_method_str(enum http_method m);
|
||||
|
||||
/* Return a string name of the given error */
|
||||
const char *http_errno_name(enum http_errno err);
|
||||
|
||||
/* Return a string description of the given error */
|
||||
const char *http_errno_description(enum http_errno err);
|
||||
|
||||
/* Parse a URL; return nonzero on failure */
|
||||
int http_parser_parse_url(const char *buf, size_t buflen,
|
||||
int is_connect,
|
||||
struct http_parser_url *u);
|
||||
|
||||
/* Pause or un-pause the parser; a nonzero value pauses */
|
||||
void http_parser_pause(http_parser *parser, int paused);
|
||||
|
||||
/* Checks if this is the final chunk of the body. */
|
||||
int http_body_is_final(const http_parser *parser);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
3852
3rdparty/http-parser/test.c
vendored
3852
3rdparty/http-parser/test.c
vendored
File diff suppressed because it is too large
Load Diff
2
3rdparty/libuv/src/win/pipe.c
vendored
2
3rdparty/libuv/src/win/pipe.c
vendored
@ -85,7 +85,7 @@ static void eof_timer_close_cb(uv_handle_t* handle);
|
||||
|
||||
|
||||
static void uv_unique_pipe_name(char* ptr, char* name, size_t size) {
|
||||
snprintf(name, size, "\\\\?\\pipe\\uv\\%p-%u", ptr, GetCurrentProcessId());
|
||||
snprintf(name, size, "\\\\?\\pipe\\uv\\%p-%lu", ptr, GetCurrentProcessId());
|
||||
}
|
||||
|
||||
|
||||
|
51
3rdparty/lsqlite3/.travis.yml
vendored
51
3rdparty/lsqlite3/.travis.yml
vendored
@ -1,51 +0,0 @@
|
||||
#
|
||||
# LuaDist Travis-CI Hook
|
||||
#
|
||||
|
||||
# We assume C build environments
|
||||
language: C
|
||||
|
||||
# Try using multiple Lua Implementations
|
||||
env:
|
||||
- TOOL="gcc" # Use native compiler (GCC usually)
|
||||
- TOOL="clang" # Use clang
|
||||
- TOOL="i686-w64-mingw32" # 32bit MinGW
|
||||
- TOOL="x86_64-w64-mingw32" # 64bit MinGW
|
||||
- TOOL="arm-linux-gnueabihf" # ARM hard-float (hf), linux
|
||||
|
||||
# Crosscompile builds may fail
|
||||
matrix:
|
||||
allow_failures:
|
||||
- env: TOOL="i686-w64-mingw32"
|
||||
- env: TOOL="x86_64-w64-mingw32"
|
||||
- env: TOOL="arm-linux-gnueabihf"
|
||||
|
||||
# Install dependencies
|
||||
install:
|
||||
- git clone git://github.com/LuaDist/Tools.git ~/_tools
|
||||
- ~/_tools/travis/travis install
|
||||
|
||||
# Bootstap
|
||||
before_script:
|
||||
- ~/_tools/travis/travis bootstrap
|
||||
|
||||
# Build the module
|
||||
script:
|
||||
- ~/_tools/travis/travis build
|
||||
|
||||
# Execute additional tests or commands
|
||||
after_script:
|
||||
- ~/_tools/travis/travis test
|
||||
|
||||
# Only watch the master branch
|
||||
branches:
|
||||
only:
|
||||
- master
|
||||
|
||||
# Notify the LuaDist Dev group if needed
|
||||
notifications:
|
||||
recipients:
|
||||
- luadist-dev@googlegroups.com
|
||||
email:
|
||||
on_success: change
|
||||
on_failure: always
|
21
3rdparty/lsqlite3/CMakeLists.txt
vendored
21
3rdparty/lsqlite3/CMakeLists.txt
vendored
@ -1,21 +0,0 @@
|
||||
# Copyright (C) 2007-2012 LuaDist.
|
||||
# Created by Peter Kapec
|
||||
# Redistribution and use of this file is allowed according to the terms of the MIT license.
|
||||
# For details see the COPYRIGHT file distributed with LuaDist.
|
||||
# Please note that the package source code is licensed under its own license.
|
||||
|
||||
project ( lsqlite3 C )
|
||||
cmake_minimum_required ( VERSION 2.8 )
|
||||
include ( cmake/dist.cmake )
|
||||
include ( lua )
|
||||
|
||||
# Find SQLite3
|
||||
find_package ( SQLite3 REQUIRED )
|
||||
include_directories ( ${SQLITE3_INCLUDE_DIRS} )
|
||||
|
||||
# Create lsqlite module
|
||||
install_lua_module ( lsqlite3 lsqlite3.c lsqlite3.def LINK ${SQLITE3_LIBRARIES} )
|
||||
install_data ( HISTORY README )
|
||||
install_doc( doc/ )
|
||||
install_test ( lunit.lua test.lua tests-sqlite3.lua )
|
||||
install_example ( examples/ )
|
133
3rdparty/lsqlite3/HISTORY
vendored
133
3rdparty/lsqlite3/HISTORY
vendored
@ -1,133 +0,0 @@
|
||||
2007-August-15 e
|
||||
|
||||
Version "0.6-devel"
|
||||
|
||||
Since the "0.5-devel" release of this Lua library...
|
||||
|
||||
Tested with SQLite 3.4.2
|
||||
|
||||
Added some documentation.
|
||||
|
||||
Thanks to Thomas Lauer...
|
||||
|
||||
Moved line 525 ("luaL_checktype(L, 2, LUA_TTABLE);")
|
||||
below the declarations to eliminate non-gcc compiler errors.
|
||||
|
||||
Added create-collation, and associated test case.
|
||||
|
||||
-=-
|
||||
|
||||
2006-October-02 e
|
||||
|
||||
Since the "0.1-devel" release of this Lua library...
|
||||
- updated for Lua 5.1
|
||||
- provide automatic re-preparation of queries after schema changes
|
||||
- made prepared statements with bindings work with for-loops
|
||||
- added some compatibility names
|
||||
- added many test cases, and ported Mike Roth's tests and examples
|
||||
|
||||
-=-
|
||||
|
||||
Below is a header comment from the 2004 "0.1" version of the library...
|
||||
|
||||
/************************************************************************
|
||||
$Id: lsqlite3.c,v 1.3 2004/09/05 17:50:32 tngd Exp $
|
||||
|
||||
To consider:
|
||||
------------
|
||||
|
||||
EXPERIMENTAL APIs
|
||||
|
||||
* sqlite3_progress_handler (implemented)
|
||||
* sqlite3_commit_hook
|
||||
|
||||
TODO?
|
||||
|
||||
* sqlite3_create_collation
|
||||
|
||||
Changes:
|
||||
04-09-2004
|
||||
----------
|
||||
* changed second return value of db:compile to be the rest of the
|
||||
sql statement that was not processed instead of the number of
|
||||
characters of sql not processed (situation in case of success).
|
||||
* progress callback register function parameter order changed.
|
||||
number of opcodes is given before the callback now.
|
||||
|
||||
29-08-2004 e
|
||||
------------
|
||||
* added version() (now supported in sqlite 3.0.5)
|
||||
* added db:errmsg db:errcode db:total_changes
|
||||
* rename vm:get_column to vm:get_value
|
||||
* merge in Tiago's v1.11 change in dbvm_tostring
|
||||
|
||||
23-06-2004 e
|
||||
------------
|
||||
* heavily revised for SQLite3 C API
|
||||
* row values now returned as native type (not always text)
|
||||
* added db:nrows (named rows)
|
||||
* added vm:bind_blob
|
||||
* added vm:get_column
|
||||
* removed encode_binary decode_binary (no longer needed or supported)
|
||||
* removed version encoding error_string (unsupported in v 3.0.1 -- soon?)
|
||||
|
||||
09-04-2004
|
||||
----------
|
||||
* renamed db:rows to db:urows
|
||||
* renamed db:prows to db:rows
|
||||
|
||||
* added vm:get_unames()
|
||||
* added vm:get_utypes()
|
||||
* added vm:get_uvalues()
|
||||
|
||||
08-04-2004
|
||||
----------
|
||||
* changed db:encoding() and db:version() to use sqlite_libencoding() and
|
||||
sqlite_libversion()
|
||||
|
||||
* added vm:columns()
|
||||
* added vm:get_named_types()
|
||||
* added vm:get_named_values()
|
||||
|
||||
* added db:prows - like db:rows but returns a table with the column values
|
||||
instead of returning multiple columns seperatly on each iteration
|
||||
|
||||
* added compatibility functions idata,iname,itype,data,type
|
||||
|
||||
* added luaopen_sqlite_module. allow the library to be loaded without
|
||||
setting a global variable. does the same as luaopen_sqlite, but does not
|
||||
set the global name "sqlite".
|
||||
|
||||
* vm:bind now also returns an error string in case of error
|
||||
|
||||
31-03-2004 - 01-04-2004
|
||||
-----------------------
|
||||
* changed most of the internals. now using references (luaL_ref) in
|
||||
most of the places
|
||||
|
||||
* make the virtual machine interface seperate from the database
|
||||
handle. db:compile now returns a vm handle
|
||||
|
||||
* added db:rows [for ... in db:rows(...) do ... end]
|
||||
|
||||
* added db:close_vm
|
||||
|
||||
* added sqlite.encode_binary and sqlite.decode_binary
|
||||
|
||||
* attempt to do a strict checking on the return type of the user
|
||||
defined functions returned values
|
||||
|
||||
18-01-2004
|
||||
----------
|
||||
* add check on sql function callback to ensure there is enough stack
|
||||
space to pass column values as parameters
|
||||
|
||||
03-12-2003
|
||||
----------
|
||||
* callback functions now have to return boolean values to abort or
|
||||
continue operation instead of a zero or non-zero value
|
||||
|
||||
06-12-2003
|
||||
----------
|
||||
* make version member of sqlite table a function instead of a string
|
||||
************************************************************************/
|
106
3rdparty/lsqlite3/Makefile
vendored
106
3rdparty/lsqlite3/Makefile
vendored
@ -1,106 +0,0 @@
|
||||
# makefile for lsqlite3 library for Lua
|
||||
|
||||
ifneq "$(shell pkg-config --version)" ""
|
||||
# automagic setup (OS X fink, Linux apt-get, ..)
|
||||
#
|
||||
LUAINC= $(shell pkg-config --cflags lua)
|
||||
LUALIB= $(shell pkg-config --libs lua)
|
||||
LUAEXE= lua
|
||||
# Now, we actually want to _not_ push in stuff to the distro Lua CMOD directory,
|
||||
# way better to play within /usr/local/lib/lua/5.1/
|
||||
#LUACMOD= $(shell pkg-config --variable=INSTALL_CMOD lua)
|
||||
LUACMOD= /usr/local/lib/lua/5.1/
|
||||
#
|
||||
SQLITE3INC= $(shell pkg-config --cflags sqlite3)
|
||||
SQLITE3LIB= $(shell pkg-config --libs sqlite3)
|
||||
else
|
||||
# manual setup (change these to reflect your Lua installation)
|
||||
#
|
||||
BASE= /usr/local
|
||||
LUAINC= -I$(BASE)/include
|
||||
LUAEXE= $(BASE)/bin/lua.exe
|
||||
# LUALIB= -L$(BASE)/lib -llua51
|
||||
# LUACMOD= $(BASE)/lib/lua/5.1/
|
||||
# Windows' LUA_CDIR and LUALIB are both the same as the Lua executable's directory...
|
||||
LUALIB= -L$(BASE)/bin -llua51
|
||||
LUACMOD= $(BASE)/bin
|
||||
#
|
||||
SQLITE3INC= -I$(BASE)/include
|
||||
SQLITE3LIB= -L$(BASE)/bin -lsqlite3
|
||||
#
|
||||
POD2HTML= perl -x -S doc/pod2html.pl
|
||||
endif
|
||||
|
||||
TMP=./tmp
|
||||
DISTDIR=./archive
|
||||
|
||||
# OS detection
|
||||
#
|
||||
SHFLAGS=-shared
|
||||
UNAME= $(shell uname)
|
||||
ifeq "$(UNAME)" "Linux"
|
||||
_SO=so
|
||||
SHFLAGS= -fPIC
|
||||
endif
|
||||
ifneq "" "$(findstring BSD,$(UNAME))"
|
||||
_SO=so
|
||||
endif
|
||||
ifeq "$(UNAME)" "Darwin"
|
||||
_SO=bundle
|
||||
SHFLAGS= -bundle
|
||||
endif
|
||||
ifneq "" "$(findstring msys,$(OSTYPE))" # 'msys'
|
||||
_SO=dll
|
||||
endif
|
||||
|
||||
ifndef _SO
|
||||
$(error $(UNAME))
|
||||
$(error Unknown OS)
|
||||
endif
|
||||
|
||||
# no need to change anything below here - HAH!
|
||||
CFLAGS= $(INCS) $(DEFS) $(WARN) -O2 $(SHFLAGS)
|
||||
WARN= -Wall #-ansi -pedantic -Wall
|
||||
INCS= $(LUAINC) $(SQLITE3INC)
|
||||
LIBS= $(LUALIB) $(SQLITE3LIB)
|
||||
|
||||
MYNAME= sqlite3
|
||||
MYLIB= l$(MYNAME)
|
||||
|
||||
VER=$(shell svnversion -c . | sed 's/.*://')
|
||||
TARFILE = $(DISTDIR)/$(MYLIB)-$(VER).tar.gz
|
||||
|
||||
OBJS= $(MYLIB).o
|
||||
T= $(MYLIB).$(_SO)
|
||||
|
||||
all: $T
|
||||
|
||||
test: $T
|
||||
$(LUAEXE) test.lua
|
||||
$(LUAEXE) tests-sqlite3.lua
|
||||
|
||||
$T: $(OBJS)
|
||||
$(CC) $(SHFLAGS) -o $@ $(OBJS) $(LIBS)
|
||||
|
||||
install:
|
||||
cp $T $(LUACMOD)
|
||||
|
||||
clean:
|
||||
rm -f $(OBJS) $T core core.* a.out test.db
|
||||
|
||||
html:
|
||||
$(POD2HTML) --title="LuaSQLite 3" --infile=doc/lsqlite3.pod --outfile=doc/lsqlite3.html
|
||||
|
||||
dist: html
|
||||
echo 'Exporting...'
|
||||
mkdir -p $(TMP)
|
||||
mkdir -p $(DISTDIR)
|
||||
svn export -r HEAD . $(TMP)/$(MYLIB)-$(VER)
|
||||
mkdir -p $(TMP)/$(MYLIB)-$(VER)/doc
|
||||
cp -p doc/lsqlite3.html $(TMP)/$(MYLIB)-$(VER)/doc
|
||||
echo 'Compressing...'
|
||||
tar -zcf $(TARFILE) -C $(TMP) $(MYLIB)-$(VER)
|
||||
rm -fr $(TMP)/$(MYLIB)-$(VER)
|
||||
echo 'Done.'
|
||||
|
||||
.PHONY: all test clean dist install
|
8
3rdparty/lsqlite3/README
vendored
8
3rdparty/lsqlite3/README
vendored
@ -1,8 +0,0 @@
|
||||
|
||||
LuaSQLite 3 provides a means to manipulate SQLite3
|
||||
databases directly from lua using Lua 5.
|
||||
|
||||
To use this library you need SQLite3 library.
|
||||
You can get it from http://www.sqlite.org/
|
||||
|
||||
Lua 5 is available from http://www.lua.org/
|
118
3rdparty/lsqlite3/cmake/FindLua.cmake
vendored
118
3rdparty/lsqlite3/cmake/FindLua.cmake
vendored
@ -1,118 +0,0 @@
|
||||
# Locate Lua library
|
||||
# This module defines
|
||||
# LUA_EXECUTABLE, if found
|
||||
# LUA_FOUND, if false, do not try to link to Lua
|
||||
# LUA_LIBRARIES
|
||||
# LUA_INCLUDE_DIR, where to find lua.h
|
||||
# LUA_VERSION_STRING, the version of Lua found (since CMake 2.8.8)
|
||||
#
|
||||
# Note that the expected include convention is
|
||||
# #include "lua.h"
|
||||
# and not
|
||||
# #include <lua/lua.h>
|
||||
# This is because, the lua location is not standardized and may exist
|
||||
# in locations other than lua/
|
||||
|
||||
#=============================================================================
|
||||
# Copyright 2007-2009 Kitware, Inc.
|
||||
# Modified to support Lua 5.2 by LuaDist 2012
|
||||
#
|
||||
# Distributed under the OSI-approved BSD License (the "License");
|
||||
# see accompanying file Copyright.txt for details.
|
||||
#
|
||||
# This software is distributed WITHOUT ANY WARRANTY; without even the
|
||||
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
# See the License for more information.
|
||||
#=============================================================================
|
||||
# (To distribute this file outside of CMake, substitute the full
|
||||
# License text for the above reference.)
|
||||
#
|
||||
# The required version of Lua can be specified using the
|
||||
# standard syntax, e.g. FIND_PACKAGE(Lua 5.1)
|
||||
# Otherwise the module will search for any available Lua implementation
|
||||
|
||||
# Always search for non-versioned lua first (recommended)
|
||||
SET(_POSSIBLE_LUA_INCLUDE include include/lua)
|
||||
SET(_POSSIBLE_LUA_EXECUTABLE lua)
|
||||
SET(_POSSIBLE_LUA_LIBRARY lua)
|
||||
|
||||
# Determine possible naming suffixes (there is no standard for this)
|
||||
IF(Lua_FIND_VERSION_MAJOR AND Lua_FIND_VERSION_MINOR)
|
||||
SET(_POSSIBLE_SUFFIXES "${Lua_FIND_VERSION_MAJOR}${Lua_FIND_VERSION_MINOR}" "${Lua_FIND_VERSION_MAJOR}.${Lua_FIND_VERSION_MINOR}" "-${Lua_FIND_VERSION_MAJOR}.${Lua_FIND_VERSION_MINOR}")
|
||||
ELSE(Lua_FIND_VERSION_MAJOR AND Lua_FIND_VERSION_MINOR)
|
||||
SET(_POSSIBLE_SUFFIXES "52" "5.2" "-5.2" "51" "5.1" "-5.1")
|
||||
ENDIF(Lua_FIND_VERSION_MAJOR AND Lua_FIND_VERSION_MINOR)
|
||||
|
||||
# Set up possible search names and locations
|
||||
FOREACH(_SUFFIX ${_POSSIBLE_SUFFIXES})
|
||||
LIST(APPEND _POSSIBLE_LUA_INCLUDE "include/lua${_SUFFIX}")
|
||||
LIST(APPEND _POSSIBLE_LUA_EXECUTABLE "lua${_SUFFIX}")
|
||||
LIST(APPEND _POSSIBLE_LUA_LIBRARY "lua${_SUFFIX}")
|
||||
ENDFOREACH(_SUFFIX)
|
||||
|
||||
# Find the lua executable
|
||||
FIND_PROGRAM(LUA_EXECUTABLE
|
||||
NAMES ${_POSSIBLE_LUA_EXECUTABLE}
|
||||
)
|
||||
|
||||
# Find the lua header
|
||||
FIND_PATH(LUA_INCLUDE_DIR lua.h
|
||||
HINTS
|
||||
$ENV{LUA_DIR}
|
||||
PATH_SUFFIXES ${_POSSIBLE_LUA_INCLUDE}
|
||||
PATHS
|
||||
~/Library/Frameworks
|
||||
/Library/Frameworks
|
||||
/usr/local
|
||||
/usr
|
||||
/sw # Fink
|
||||
/opt/local # DarwinPorts
|
||||
/opt/csw # Blastwave
|
||||
/opt
|
||||
)
|
||||
|
||||
# Find the lua library
|
||||
FIND_LIBRARY(LUA_LIBRARY
|
||||
NAMES ${_POSSIBLE_LUA_LIBRARY}
|
||||
HINTS
|
||||
$ENV{LUA_DIR}
|
||||
PATH_SUFFIXES lib64 lib
|
||||
PATHS
|
||||
~/Library/Frameworks
|
||||
/Library/Frameworks
|
||||
/usr/local
|
||||
/usr
|
||||
/sw
|
||||
/opt/local
|
||||
/opt/csw
|
||||
/opt
|
||||
)
|
||||
|
||||
IF(LUA_LIBRARY)
|
||||
# include the math library for Unix
|
||||
IF(UNIX AND NOT APPLE)
|
||||
FIND_LIBRARY(LUA_MATH_LIBRARY m)
|
||||
SET( LUA_LIBRARIES "${LUA_LIBRARY};${LUA_MATH_LIBRARY}" CACHE STRING "Lua Libraries")
|
||||
# For Windows and Mac, don't need to explicitly include the math library
|
||||
ELSE(UNIX AND NOT APPLE)
|
||||
SET( LUA_LIBRARIES "${LUA_LIBRARY}" CACHE STRING "Lua Libraries")
|
||||
ENDIF(UNIX AND NOT APPLE)
|
||||
ENDIF(LUA_LIBRARY)
|
||||
|
||||
# Determine Lua version
|
||||
IF(LUA_INCLUDE_DIR AND EXISTS "${LUA_INCLUDE_DIR}/lua.h")
|
||||
FILE(STRINGS "${LUA_INCLUDE_DIR}/lua.h" lua_version_str REGEX "^#define[ \t]+LUA_RELEASE[ \t]+\"Lua .+\"")
|
||||
|
||||
STRING(REGEX REPLACE "^#define[ \t]+LUA_RELEASE[ \t]+\"Lua ([^\"]+)\".*" "\\1" LUA_VERSION_STRING "${lua_version_str}")
|
||||
UNSET(lua_version_str)
|
||||
ENDIF()
|
||||
|
||||
INCLUDE(FindPackageHandleStandardArgs)
|
||||
# handle the QUIETLY and REQUIRED arguments and set LUA_FOUND to TRUE if
|
||||
# all listed variables are TRUE
|
||||
FIND_PACKAGE_HANDLE_STANDARD_ARGS(Lua
|
||||
REQUIRED_VARS LUA_LIBRARIES LUA_INCLUDE_DIR
|
||||
VERSION_VAR LUA_VERSION_STRING)
|
||||
|
||||
MARK_AS_ADVANCED(LUA_INCLUDE_DIR LUA_LIBRARIES LUA_LIBRARY LUA_MATH_LIBRARY LUA_EXECUTABLE)
|
||||
|
37
3rdparty/lsqlite3/cmake/FindSQLite3.cmake
vendored
37
3rdparty/lsqlite3/cmake/FindSQLite3.cmake
vendored
@ -1,37 +0,0 @@
|
||||
# Copyright (C) 2007-2009 LuaDist.
|
||||
# Created by Peter Kapec <kapecp@gmail.com>
|
||||
# Redistribution and use of this file is allowed according to the terms of the MIT license.
|
||||
# For details see the COPYRIGHT file distributed with LuaDist.
|
||||
# Note:
|
||||
# Searching headers and libraries is very simple and is NOT as powerful as scripts
|
||||
# distributed with CMake, because LuaDist defines directories to search for.
|
||||
# Everyone is encouraged to contact the author with improvements. Maybe this file
|
||||
# becomes part of CMake distribution sometimes.
|
||||
|
||||
# - Find sqlite3
|
||||
# Find the native SQLITE3 headers and libraries.
|
||||
#
|
||||
# SQLITE3_INCLUDE_DIRS - where to find sqlite3.h, etc.
|
||||
# SQLITE3_LIBRARIES - List of libraries when using sqlite.
|
||||
# SQLITE3_FOUND - True if sqlite found.
|
||||
|
||||
# Look for the header file.
|
||||
FIND_PATH(SQLITE3_INCLUDE_DIR NAMES sqlite3.h)
|
||||
|
||||
# Look for the library.
|
||||
FIND_LIBRARY(SQLITE3_LIBRARY NAMES sqlite3 libsqlite3 sqlite libsqlite)
|
||||
|
||||
# Handle the QUIETLY and REQUIRED arguments and set SQLITE3_FOUND to TRUE if all listed variables are TRUE.
|
||||
INCLUDE(FindPackageHandleStandardArgs)
|
||||
FIND_PACKAGE_HANDLE_STANDARD_ARGS(SQLITE3 DEFAULT_MSG SQLITE3_LIBRARY SQLITE3_INCLUDE_DIR)
|
||||
|
||||
# Copy the results to the output variables.
|
||||
IF(SQLITE3_FOUND)
|
||||
SET(SQLITE3_LIBRARIES ${SQLITE3_LIBRARY})
|
||||
SET(SQLITE3_INCLUDE_DIRS ${SQLITE3_INCLUDE_DIR})
|
||||
ELSE(SQLITE3_FOUND)
|
||||
SET(SQLITE3_LIBRARIES)
|
||||
SET(SQLITE3_INCLUDE_DIRS)
|
||||
ENDIF(SQLITE3_FOUND)
|
||||
|
||||
MARK_AS_ADVANCED(SQLITE3_INCLUDE_DIRS SQLITE3_LIBRARIES)
|
321
3rdparty/lsqlite3/cmake/dist.cmake
vendored
321
3rdparty/lsqlite3/cmake/dist.cmake
vendored
@ -1,321 +0,0 @@
|
||||
# LuaDist CMake utility library.
|
||||
# Provides sane project defaults and macros common to LuaDist CMake builds.
|
||||
#
|
||||
# Copyright (C) 2007-2012 LuaDist.
|
||||
# by David Manura, Peter Drahoš
|
||||
# Redistribution and use of this file is allowed according to the terms of the MIT license.
|
||||
# For details see the COPYRIGHT file distributed with LuaDist.
|
||||
# Please note that the package source code is licensed under its own license.
|
||||
|
||||
## Extract information from dist.info
|
||||
if ( NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/dist.info )
|
||||
message ( FATAL_ERROR
|
||||
"Missing dist.info file (${CMAKE_CURRENT_SOURCE_DIR}/dist.info)." )
|
||||
endif ()
|
||||
file ( READ ${CMAKE_CURRENT_SOURCE_DIR}/dist.info DIST_INFO )
|
||||
if ( "${DIST_INFO}" STREQUAL "" )
|
||||
message ( FATAL_ERROR "Failed to load dist.info." )
|
||||
endif ()
|
||||
# Reads field `name` from dist.info string `DIST_INFO` into variable `var`.
|
||||
macro ( _parse_dist_field name var )
|
||||
string ( REGEX REPLACE ".*${name}[ \t]?=[ \t]?[\"']([^\"']+)[\"'].*" "\\1"
|
||||
${var} "${DIST_INFO}" )
|
||||
if ( ${var} STREQUAL DIST_INFO )
|
||||
message ( FATAL_ERROR "Failed to extract \"${var}\" from dist.info" )
|
||||
endif ()
|
||||
endmacro ()
|
||||
#
|
||||
_parse_dist_field ( name DIST_NAME )
|
||||
_parse_dist_field ( version DIST_VERSION )
|
||||
_parse_dist_field ( license DIST_LICENSE )
|
||||
_parse_dist_field ( author DIST_AUTHOR )
|
||||
_parse_dist_field ( maintainer DIST_MAINTAINER )
|
||||
_parse_dist_field ( url DIST_URL )
|
||||
_parse_dist_field ( desc DIST_DESC )
|
||||
message ( "DIST_NAME: ${DIST_NAME}")
|
||||
message ( "DIST_VERSION: ${DIST_VERSION}")
|
||||
message ( "DIST_LICENSE: ${DIST_LICENSE}")
|
||||
message ( "DIST_AUTHOR: ${DIST_AUTHOR}")
|
||||
message ( "DIST_MAINTAINER: ${DIST_MAINTAINER}")
|
||||
message ( "DIST_URL: ${DIST_URL}")
|
||||
message ( "DIST_DESC: ${DIST_DESC}")
|
||||
string ( REGEX REPLACE ".*depends[ \t]?=[ \t]?[\"']([^\"']+)[\"'].*" "\\1"
|
||||
DIST_DEPENDS ${DIST_INFO} )
|
||||
if ( DIST_DEPENDS STREQUAL DIST_INFO )
|
||||
set ( DIST_DEPENDS "" )
|
||||
endif ()
|
||||
message ( "DIST_DEPENDS: ${DIST_DEPENDS}")
|
||||
## 2DO: Parse DIST_DEPENDS and try to install Dependencies with automatically using externalproject_add
|
||||
|
||||
|
||||
## INSTALL DEFAULTS (Relative to CMAKE_INSTALL_PREFIX)
|
||||
# Primary paths
|
||||
set ( INSTALL_BIN bin CACHE PATH "Where to install binaries to." )
|
||||
set ( INSTALL_LIB lib CACHE PATH "Where to install libraries to." )
|
||||
set ( INSTALL_INC include CACHE PATH "Where to install headers to." )
|
||||
set ( INSTALL_ETC etc CACHE PATH "Where to store configuration files" )
|
||||
set ( INSTALL_SHARE share CACHE PATH "Directory for shared data." )
|
||||
|
||||
# Secondary paths
|
||||
option ( INSTALL_VERSION
|
||||
"Install runtime libraries and executables with version information." OFF)
|
||||
set ( INSTALL_DATA ${INSTALL_SHARE}/${DIST_NAME} CACHE PATH
|
||||
"Directory the package can store documentation, tests or other data in.")
|
||||
set ( INSTALL_DOC ${INSTALL_DATA}/doc CACHE PATH
|
||||
"Recommended directory to install documentation into.")
|
||||
set ( INSTALL_EXAMPLE ${INSTALL_DATA}/example CACHE PATH
|
||||
"Recommended directory to install examples into.")
|
||||
set ( INSTALL_TEST ${INSTALL_DATA}/test CACHE PATH
|
||||
"Recommended directory to install tests into.")
|
||||
set ( INSTALL_FOO ${INSTALL_DATA}/etc CACHE PATH
|
||||
"Where to install additional files")
|
||||
|
||||
# Tweaks and other defaults
|
||||
# Setting CMAKE to use loose block and search for find modules in source directory
|
||||
set ( CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true )
|
||||
set ( CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH} )
|
||||
option ( BUILD_SHARED_LIBS "Build shared libraries" ON )
|
||||
|
||||
# In MSVC, prevent warnings that can occur when using standard libraries.
|
||||
if ( MSVC )
|
||||
add_definitions ( -D_CRT_SECURE_NO_WARNINGS )
|
||||
endif ()
|
||||
|
||||
# RPath and relative linking
|
||||
option ( USE_RPATH "Use relative linking." ON)
|
||||
if ( USE_RPATH )
|
||||
string ( REGEX REPLACE "[^!/]+" ".." UP_DIR ${INSTALL_BIN} )
|
||||
set ( CMAKE_SKIP_BUILD_RPATH FALSE CACHE STRING "" FORCE )
|
||||
set ( CMAKE_BUILD_WITH_INSTALL_RPATH FALSE CACHE STRING "" FORCE )
|
||||
set ( CMAKE_INSTALL_RPATH $ORIGIN/${UP_DIR}/${INSTALL_LIB}
|
||||
CACHE STRING "" FORCE )
|
||||
set ( CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE CACHE STRING "" FORCE )
|
||||
set ( CMAKE_INSTALL_NAME_DIR @executable_path/${UP_DIR}/${INSTALL_LIB}
|
||||
CACHE STRING "" FORCE )
|
||||
endif ()
|
||||
|
||||
## MACROS
|
||||
# Parser macro
|
||||
macro ( parse_arguments prefix arg_names option_names)
|
||||
set ( DEFAULT_ARGS )
|
||||
foreach ( arg_name ${arg_names} )
|
||||
set ( ${prefix}_${arg_name} )
|
||||
endforeach ()
|
||||
foreach ( option ${option_names} )
|
||||
set ( ${prefix}_${option} FALSE )
|
||||
endforeach ()
|
||||
|
||||
set ( current_arg_name DEFAULT_ARGS )
|
||||
set ( current_arg_list )
|
||||
foreach ( arg ${ARGN} )
|
||||
set ( larg_names ${arg_names} )
|
||||
list ( FIND larg_names "${arg}" is_arg_name )
|
||||
if ( is_arg_name GREATER -1 )
|
||||
set ( ${prefix}_${current_arg_name} ${current_arg_list} )
|
||||
set ( current_arg_name ${arg} )
|
||||
set ( current_arg_list )
|
||||
else ()
|
||||
set ( loption_names ${option_names} )
|
||||
list ( FIND loption_names "${arg}" is_option )
|
||||
if ( is_option GREATER -1 )
|
||||
set ( ${prefix}_${arg} TRUE )
|
||||
else ()
|
||||
set ( current_arg_list ${current_arg_list} ${arg} )
|
||||
endif ()
|
||||
endif ()
|
||||
endforeach ()
|
||||
set ( ${prefix}_${current_arg_name} ${current_arg_list} )
|
||||
endmacro ()
|
||||
|
||||
|
||||
# install_executable ( executable_targets )
|
||||
# Installs any executables generated using "add_executable".
|
||||
# USE: install_executable ( lua )
|
||||
# NOTE: subdirectories are NOT supported
|
||||
set ( CPACK_COMPONENT_RUNTIME_DISPLAY_NAME "${DIST_NAME} Runtime" )
|
||||
set ( CPACK_COMPONENT_RUNTIME_DESCRIPTION
|
||||
"Executables and runtime libraries. Installed into ${INSTALL_BIN}." )
|
||||
macro ( install_executable )
|
||||
foreach ( _file ${ARGN} )
|
||||
if ( INSTALL_VERSION )
|
||||
set_target_properties ( ${_file} PROPERTIES VERSION ${DIST_VERSION}
|
||||
SOVERSION ${DIST_VERSION} )
|
||||
endif ()
|
||||
install ( TARGETS ${_file} RUNTIME DESTINATION ${INSTALL_BIN}
|
||||
COMPONENT Runtime )
|
||||
endforeach()
|
||||
endmacro ()
|
||||
|
||||
# install_library ( library_targets )
|
||||
# Installs any libraries generated using "add_library" into apropriate places.
|
||||
# USE: install_library ( libexpat )
|
||||
# NOTE: subdirectories are NOT supported
|
||||
set ( CPACK_COMPONENT_LIBRARY_DISPLAY_NAME "${DIST_NAME} Development Libraries" )
|
||||
set ( CPACK_COMPONENT_LIBRARY_DESCRIPTION
|
||||
"Static and import libraries needed for development. Installed into ${INSTALL_LIB} or ${INSTALL_BIN}." )
|
||||
macro ( install_library )
|
||||
foreach ( _file ${ARGN} )
|
||||
if ( INSTALL_VERSION )
|
||||
set_target_properties ( ${_file} PROPERTIES VERSION ${DIST_VERSION}
|
||||
SOVERSION ${DIST_VERSION} )
|
||||
endif ()
|
||||
install ( TARGETS ${_file}
|
||||
RUNTIME DESTINATION ${INSTALL_BIN} COMPONENT Runtime
|
||||
LIBRARY DESTINATION ${INSTALL_LIB} COMPONENT Runtime
|
||||
ARCHIVE DESTINATION ${INSTALL_LIB} COMPONENT Library )
|
||||
endforeach()
|
||||
endmacro ()
|
||||
|
||||
# helper function for various install_* functions, for PATTERN/REGEX args.
|
||||
macro ( _complete_install_args )
|
||||
if ( NOT("${_ARG_PATTERN}" STREQUAL "") )
|
||||
set ( _ARG_PATTERN PATTERN ${_ARG_PATTERN} )
|
||||
endif ()
|
||||
if ( NOT("${_ARG_REGEX}" STREQUAL "") )
|
||||
set ( _ARG_REGEX REGEX ${_ARG_REGEX} )
|
||||
endif ()
|
||||
endmacro ()
|
||||
|
||||
# install_header ( files/directories [INTO destination] )
|
||||
# Install a directories or files into header destination.
|
||||
# USE: install_header ( lua.h luaconf.h ) or install_header ( GL )
|
||||
# USE: install_header ( mylib.h INTO mylib )
|
||||
# For directories, supports optional PATTERN/REGEX arguments like install().
|
||||
set ( CPACK_COMPONENT_HEADER_DISPLAY_NAME "${DIST_NAME} Development Headers" )
|
||||
set ( CPACK_COMPONENT_HEADER_DESCRIPTION
|
||||
"Headers needed for development. Installed into ${INSTALL_INC}." )
|
||||
macro ( install_header )
|
||||
parse_arguments ( _ARG "INTO;PATTERN;REGEX" "" ${ARGN} )
|
||||
_complete_install_args()
|
||||
foreach ( _file ${_ARG_DEFAULT_ARGS} )
|
||||
if ( IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${_file}" )
|
||||
install ( DIRECTORY ${_file} DESTINATION ${INSTALL_INC}/${_ARG_INTO}
|
||||
COMPONENT Header ${_ARG_PATTERN} ${_ARG_REGEX} )
|
||||
else ()
|
||||
install ( FILES ${_file} DESTINATION ${INSTALL_INC}/${_ARG_INTO}
|
||||
COMPONENT Header )
|
||||
endif ()
|
||||
endforeach()
|
||||
endmacro ()
|
||||
|
||||
# install_data ( files/directories [INTO destination] )
|
||||
# This installs additional data files or directories.
|
||||
# USE: install_data ( extra data.dat )
|
||||
# USE: install_data ( image1.png image2.png INTO images )
|
||||
# For directories, supports optional PATTERN/REGEX arguments like install().
|
||||
set ( CPACK_COMPONENT_DATA_DISPLAY_NAME "${DIST_NAME} Data" )
|
||||
set ( CPACK_COMPONENT_DATA_DESCRIPTION
|
||||
"Application data. Installed into ${INSTALL_DATA}." )
|
||||
macro ( install_data )
|
||||
parse_arguments ( _ARG "INTO;PATTERN;REGEX" "" ${ARGN} )
|
||||
_complete_install_args()
|
||||
foreach ( _file ${_ARG_DEFAULT_ARGS} )
|
||||
if ( IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${_file}" )
|
||||
install ( DIRECTORY ${_file}
|
||||
DESTINATION ${INSTALL_DATA}/${_ARG_INTO}
|
||||
COMPONENT Data ${_ARG_PATTERN} ${_ARG_REGEX} )
|
||||
else ()
|
||||
install ( FILES ${_file} DESTINATION ${INSTALL_DATA}/${_ARG_INTO}
|
||||
COMPONENT Data )
|
||||
endif ()
|
||||
endforeach()
|
||||
endmacro ()
|
||||
|
||||
# INSTALL_DOC ( files/directories [INTO destination] )
|
||||
# This installs documentation content
|
||||
# USE: install_doc ( doc/ doc.pdf )
|
||||
# USE: install_doc ( index.html INTO html )
|
||||
# For directories, supports optional PATTERN/REGEX arguments like install().
|
||||
set ( CPACK_COMPONENT_DOCUMENTATION_DISPLAY_NAME "${DIST_NAME} Documentation" )
|
||||
set ( CPACK_COMPONENT_DOCUMENTATION_DESCRIPTION
|
||||
"Application documentation. Installed into ${INSTALL_DOC}." )
|
||||
macro ( install_doc )
|
||||
parse_arguments ( _ARG "INTO;PATTERN;REGEX" "" ${ARGN} )
|
||||
_complete_install_args()
|
||||
foreach ( _file ${_ARG_DEFAULT_ARGS} )
|
||||
if ( IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${_file}" )
|
||||
install ( DIRECTORY ${_file} DESTINATION ${INSTALL_DOC}/${_ARG_INTO}
|
||||
COMPONENT Documentation ${_ARG_PATTERN} ${_ARG_REGEX} )
|
||||
else ()
|
||||
install ( FILES ${_file} DESTINATION ${INSTALL_DOC}/${_ARG_INTO}
|
||||
COMPONENT Documentation )
|
||||
endif ()
|
||||
endforeach()
|
||||
endmacro ()
|
||||
|
||||
# install_example ( files/directories [INTO destination] )
|
||||
# This installs additional examples
|
||||
# USE: install_example ( examples/ exampleA )
|
||||
# USE: install_example ( super_example super_data INTO super)
|
||||
# For directories, supports optional PATTERN/REGEX argument like install().
|
||||
set ( CPACK_COMPONENT_EXAMPLE_DISPLAY_NAME "${DIST_NAME} Examples" )
|
||||
set ( CPACK_COMPONENT_EXAMPLE_DESCRIPTION
|
||||
"Examples and their associated data. Installed into ${INSTALL_EXAMPLE}." )
|
||||
macro ( install_example )
|
||||
parse_arguments ( _ARG "INTO;PATTERN;REGEX" "" ${ARGN} )
|
||||
_complete_install_args()
|
||||
foreach ( _file ${_ARG_DEFAULT_ARGS} )
|
||||
if ( IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${_file}" )
|
||||
install ( DIRECTORY ${_file} DESTINATION ${INSTALL_EXAMPLE}/${_ARG_INTO}
|
||||
COMPONENT Example ${_ARG_PATTERN} ${_ARG_REGEX} )
|
||||
else ()
|
||||
install ( FILES ${_file} DESTINATION ${INSTALL_EXAMPLE}/${_ARG_INTO}
|
||||
COMPONENT Example )
|
||||
endif ()
|
||||
endforeach()
|
||||
endmacro ()
|
||||
|
||||
# install_test ( files/directories [INTO destination] )
|
||||
# This installs tests and test files, DOES NOT EXECUTE TESTS
|
||||
# USE: install_test ( my_test data.sql )
|
||||
# USE: install_test ( feature_x_test INTO x )
|
||||
# For directories, supports optional PATTERN/REGEX argument like install().
|
||||
set ( CPACK_COMPONENT_TEST_DISPLAY_NAME "${DIST_NAME} Tests" )
|
||||
set ( CPACK_COMPONENT_TEST_DESCRIPTION
|
||||
"Tests and associated data. Installed into ${INSTALL_TEST}." )
|
||||
macro ( install_test )
|
||||
parse_arguments ( _ARG "INTO;PATTERN;REGEX" "" ${ARGN} )
|
||||
_complete_install_args()
|
||||
foreach ( _file ${_ARG_DEFAULT_ARGS} )
|
||||
if ( IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${_file}" )
|
||||
install ( DIRECTORY ${_file} DESTINATION ${INSTALL_TEST}/${_ARG_INTO}
|
||||
COMPONENT Test ${_ARG_PATTERN} ${_ARG_REGEX} )
|
||||
else ()
|
||||
install ( FILES ${_file} DESTINATION ${INSTALL_TEST}/${_ARG_INTO}
|
||||
COMPONENT Test )
|
||||
endif ()
|
||||
endforeach()
|
||||
endmacro ()
|
||||
|
||||
# install_foo ( files/directories [INTO destination] )
|
||||
# This installs optional or otherwise unneeded content
|
||||
# USE: install_foo ( etc/ example.doc )
|
||||
# USE: install_foo ( icon.png logo.png INTO icons)
|
||||
# For directories, supports optional PATTERN/REGEX argument like install().
|
||||
set ( CPACK_COMPONENT_OTHER_DISPLAY_NAME "${DIST_NAME} Unspecified Content" )
|
||||
set ( CPACK_COMPONENT_OTHER_DESCRIPTION
|
||||
"Other unspecified content. Installed into ${INSTALL_FOO}." )
|
||||
macro ( install_foo )
|
||||
parse_arguments ( _ARG "INTO;PATTERN;REGEX" "" ${ARGN} )
|
||||
_complete_install_args()
|
||||
foreach ( _file ${_ARG_DEFAULT_ARGS} )
|
||||
if ( IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${_file}" )
|
||||
install ( DIRECTORY ${_file} DESTINATION ${INSTALL_FOO}/${_ARG_INTO}
|
||||
COMPONENT Other ${_ARG_PATTERN} ${_ARG_REGEX} )
|
||||
else ()
|
||||
install ( FILES ${_file} DESTINATION ${INSTALL_FOO}/${_ARG_INTO}
|
||||
COMPONENT Other )
|
||||
endif ()
|
||||
endforeach()
|
||||
endmacro ()
|
||||
|
||||
## CTest defaults
|
||||
|
||||
## CPack defaults
|
||||
set ( CPACK_GENERATOR "ZIP" )
|
||||
set ( CPACK_STRIP_FILES TRUE )
|
||||
set ( CPACK_PACKAGE_NAME "${DIST_NAME}" )
|
||||
set ( CPACK_PACKAGE_VERSION "${DIST_VERSION}")
|
||||
set ( CPACK_PACKAGE_VENDOR "LuaDist" )
|
||||
set ( CPACK_COMPONENTS_ALL Runtime Library Header Data Documentation Example Other )
|
||||
include ( CPack )
|
293
3rdparty/lsqlite3/cmake/lua.cmake
vendored
293
3rdparty/lsqlite3/cmake/lua.cmake
vendored
@ -1,293 +0,0 @@
|
||||
# LuaDist CMake utility library for Lua.
|
||||
#
|
||||
# Copyright (C) 2007-2012 LuaDist.
|
||||
# by David Manura, Peter Drahos
|
||||
# Redistribution and use of this file is allowed according to the terms of the MIT license.
|
||||
# For details see the COPYRIGHT file distributed with LuaDist.
|
||||
# Please note that the package source code is licensed under its own license.
|
||||
|
||||
set ( INSTALL_LMOD ${INSTALL_LIB}/lua
|
||||
CACHE PATH "Directory to install Lua modules." )
|
||||
set ( INSTALL_CMOD ${INSTALL_LIB}/lua
|
||||
CACHE PATH "Directory to install Lua binary modules." )
|
||||
|
||||
option ( SKIP_LUA_WRAPPER
|
||||
"Do not build and install Lua executable wrappers." OFF)
|
||||
|
||||
# List of (Lua module name, file path) pairs.
|
||||
# Used internally by add_lua_test. Built by add_lua_module.
|
||||
set ( _lua_modules )
|
||||
|
||||
# utility function: appends path `path` to path `basepath`, properly
|
||||
# handling cases when `path` may be relative or absolute.
|
||||
macro ( _append_path basepath path result )
|
||||
if ( IS_ABSOLUTE "${path}" )
|
||||
set ( ${result} "${path}" )
|
||||
else ()
|
||||
set ( ${result} "${basepath}/${path}" )
|
||||
endif ()
|
||||
endmacro ()
|
||||
|
||||
# install_lua_executable ( target source )
|
||||
# Automatically generate a binary if srlua package is available
|
||||
# The application or its source will be placed into /bin
|
||||
# If the application source did not have .lua suffix then it will be added
|
||||
# USE: lua_executable ( sputnik src/sputnik.lua )
|
||||
macro ( install_lua_executable _name _source )
|
||||
get_filename_component ( _source_name ${_source} NAME_WE )
|
||||
# Find srlua and glue
|
||||
find_program( SRLUA_EXECUTABLE NAMES srlua )
|
||||
find_program( GLUE_EXECUTABLE NAMES glue )
|
||||
# Executable output
|
||||
set ( _exe ${CMAKE_CURRENT_BINARY_DIR}/${_name}${CMAKE_EXECUTABLE_SUFFIX} )
|
||||
if ( NOT SKIP_LUA_WRAPPER AND SRLUA_EXECUTABLE AND GLUE_EXECUTABLE )
|
||||
# Generate binary gluing the lua code to srlua, this is a robuust approach for most systems
|
||||
add_custom_command(
|
||||
OUTPUT ${_exe}
|
||||
COMMAND ${GLUE_EXECUTABLE}
|
||||
ARGS ${SRLUA_EXECUTABLE} ${_source} ${_exe}
|
||||
DEPENDS ${_source}
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
VERBATIM
|
||||
)
|
||||
# Make sure we have a target associated with the binary
|
||||
add_custom_target(${_name} ALL
|
||||
DEPENDS ${_exe}
|
||||
)
|
||||
# Install with run permissions
|
||||
install ( PROGRAMS ${_exe} DESTINATION ${INSTALL_BIN} COMPONENT Runtime)
|
||||
# Also install source as optional resurce
|
||||
install ( FILES ${_source} DESTINATION ${INSTALL_FOO} COMPONENT Other )
|
||||
else()
|
||||
# Install into bin as is but without the lua suffix, we assume the executable uses UNIX shebang/hash-bang magic
|
||||
install ( PROGRAMS ${_source} DESTINATION ${INSTALL_BIN}
|
||||
RENAME ${_source_name}
|
||||
COMPONENT Runtime
|
||||
)
|
||||
endif()
|
||||
endmacro ()
|
||||
|
||||
macro ( _lua_module_helper is_install _name )
|
||||
parse_arguments ( _MODULE "LINK;ALL_IN_ONE" "" ${ARGN} )
|
||||
# _target is CMake-compatible target name for module (e.g. socket_core).
|
||||
# _module is relative path of target (e.g. socket/core),
|
||||
# without extension (e.g. .lua/.so/.dll).
|
||||
# _MODULE_SRC is list of module source files (e.g. .lua and .c files).
|
||||
# _MODULE_NAMES is list of module names (e.g. socket.core).
|
||||
if ( _MODULE_ALL_IN_ONE )
|
||||
string ( REGEX REPLACE "\\..*" "" _target "${_name}" )
|
||||
string ( REGEX REPLACE "\\..*" "" _module "${_name}" )
|
||||
set ( _target "${_target}_all_in_one")
|
||||
set ( _MODULE_SRC ${_MODULE_ALL_IN_ONE} )
|
||||
set ( _MODULE_NAMES ${_name} ${_MODULE_DEFAULT_ARGS} )
|
||||
else ()
|
||||
string ( REPLACE "." "_" _target "${_name}" )
|
||||
string ( REPLACE "." "/" _module "${_name}" )
|
||||
set ( _MODULE_SRC ${_MODULE_DEFAULT_ARGS} )
|
||||
set ( _MODULE_NAMES ${_name} )
|
||||
endif ()
|
||||
if ( NOT _MODULE_SRC )
|
||||
message ( FATAL_ERROR "no module sources specified" )
|
||||
endif ()
|
||||
list ( GET _MODULE_SRC 0 _first_source )
|
||||
|
||||
get_filename_component ( _ext ${_first_source} EXT )
|
||||
if ( _ext STREQUAL ".lua" ) # Lua source module
|
||||
list ( LENGTH _MODULE_SRC _len )
|
||||
if ( _len GREATER 1 )
|
||||
message ( FATAL_ERROR "more than one source file specified" )
|
||||
endif ()
|
||||
|
||||
set ( _module "${_module}.lua" )
|
||||
|
||||
get_filename_component ( _module_dir ${_module} PATH )
|
||||
get_filename_component ( _module_filename ${_module} NAME )
|
||||
_append_path ( "${CMAKE_CURRENT_SOURCE_DIR}" "${_first_source}" _module_path )
|
||||
list ( APPEND _lua_modules "${_name}" "${_module_path}" )
|
||||
|
||||
if ( ${is_install} )
|
||||
install ( FILES ${_first_source} DESTINATION ${INSTALL_LMOD}/${_module_dir}
|
||||
RENAME ${_module_filename}
|
||||
COMPONENT Runtime
|
||||
)
|
||||
endif ()
|
||||
else () # Lua C binary module
|
||||
enable_language ( C )
|
||||
find_package ( Lua REQUIRED )
|
||||
include_directories ( ${LUA_INCLUDE_DIR} )
|
||||
|
||||
set ( _module "${_module}${CMAKE_SHARED_MODULE_SUFFIX}" )
|
||||
|
||||
get_filename_component ( _module_dir ${_module} PATH )
|
||||
get_filename_component ( _module_filenamebase ${_module} NAME_WE )
|
||||
foreach ( _thisname ${_MODULE_NAMES} )
|
||||
list ( APPEND _lua_modules "${_thisname}"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/\${CMAKE_CFG_INTDIR}/${_module}" )
|
||||
endforeach ()
|
||||
|
||||
add_library( ${_target} MODULE ${_MODULE_SRC})
|
||||
target_link_libraries ( ${_target} ${LUA_LIBRARY} ${_MODULE_LINK} )
|
||||
set_target_properties ( ${_target} PROPERTIES LIBRARY_OUTPUT_DIRECTORY
|
||||
"${_module_dir}" PREFIX "" OUTPUT_NAME "${_module_filenamebase}" )
|
||||
if ( ${is_install} )
|
||||
install ( TARGETS ${_target} DESTINATION ${INSTALL_CMOD}/${_module_dir} COMPONENT Runtime)
|
||||
endif ()
|
||||
endif ()
|
||||
endmacro ()
|
||||
|
||||
# add_lua_module
|
||||
# Builds a Lua source module into a destination locatable by Lua
|
||||
# require syntax.
|
||||
# Binary modules are also supported where this function takes sources and
|
||||
# libraries to compile separated by LINK keyword.
|
||||
# USE: add_lua_module ( socket.http src/http.lua )
|
||||
# USE2: add_lua_module ( mime.core src/mime.c )
|
||||
# USE3: add_lua_module ( socket.core ${SRC_SOCKET} LINK ${LIB_SOCKET} )
|
||||
# USE4: add_lua_module ( ssl.context ssl.core ALL_IN_ONE src/context.c src/ssl.c )
|
||||
# This form builds an "all-in-one" module (e.g. ssl.so or ssl.dll containing
|
||||
# both modules ssl.context and ssl.core). The CMake target name will be
|
||||
# ssl_all_in_one.
|
||||
# Also sets variable _module_path (relative path where module typically
|
||||
# would be installed).
|
||||
macro ( add_lua_module )
|
||||
_lua_module_helper ( 0 ${ARGN} )
|
||||
endmacro ()
|
||||
|
||||
|
||||
# install_lua_module
|
||||
# This is the same as `add_lua_module` but also installs the module.
|
||||
# USE: install_lua_module ( socket.http src/http.lua )
|
||||
# USE2: install_lua_module ( mime.core src/mime.c )
|
||||
# USE3: install_lua_module ( socket.core ${SRC_SOCKET} LINK ${LIB_SOCKET} )
|
||||
macro ( install_lua_module )
|
||||
_lua_module_helper ( 1 ${ARGN} )
|
||||
endmacro ()
|
||||
|
||||
# Builds string representing Lua table mapping Lua modules names to file
|
||||
# paths. Used internally.
|
||||
macro ( _make_module_table _outvar )
|
||||
set ( ${_outvar} )
|
||||
list ( LENGTH _lua_modules _n )
|
||||
if ( ${_n} GREATER 0 ) # avoids cmake complaint
|
||||
foreach ( _i RANGE 1 ${_n} 2 )
|
||||
list ( GET _lua_modules ${_i} _path )
|
||||
math ( EXPR _ii ${_i}-1 )
|
||||
list ( GET _lua_modules ${_ii} _name )
|
||||
set ( ${_outvar} "${_table} ['${_name}'] = '${_path}'\;\n")
|
||||
endforeach ()
|
||||
endif ()
|
||||
set ( ${_outvar}
|
||||
"local modules = {
|
||||
${_table}}" )
|
||||
endmacro ()
|
||||
|
||||
# add_lua_test ( _testfile [ WORKING_DIRECTORY _working_dir ] )
|
||||
# Runs Lua script `_testfile` under CTest tester.
|
||||
# Optional named argument `WORKING_DIRECTORY` is current working directory to
|
||||
# run test under (defaults to ${CMAKE_CURRENT_BINARY_DIR}).
|
||||
# Both paths, if relative, are relative to ${CMAKE_CURRENT_SOURCE_DIR}.
|
||||
# Any modules previously defined with install_lua_module are automatically
|
||||
# preloaded (via package.preload) prior to running the test script.
|
||||
# Under LuaDist, set test=true in config.lua to enable testing.
|
||||
# USE: add_lua_test ( test/test1.lua [args...] [WORKING_DIRECTORY dir])
|
||||
macro ( add_lua_test _testfile )
|
||||
if ( NOT SKIP_TESTING )
|
||||
parse_arguments ( _ARG "WORKING_DIRECTORY" "" ${ARGN} )
|
||||
include ( CTest )
|
||||
find_program ( LUA NAMES lua lua.bat )
|
||||
get_filename_component ( TESTFILEABS ${_testfile} ABSOLUTE )
|
||||
get_filename_component ( TESTFILENAME ${_testfile} NAME )
|
||||
get_filename_component ( TESTFILEBASE ${_testfile} NAME_WE )
|
||||
|
||||
# Write wrapper script.
|
||||
# Note: One simple way to allow the script to find modules is
|
||||
# to just put them in package.preload.
|
||||
set ( TESTWRAPPER ${CMAKE_CURRENT_BINARY_DIR}/${TESTFILENAME} )
|
||||
_make_module_table ( _table )
|
||||
set ( TESTWRAPPERSOURCE
|
||||
"local CMAKE_CFG_INTDIR = ... or '.'
|
||||
${_table}
|
||||
local function preload_modules(modules)
|
||||
for name, path in pairs(modules) do
|
||||
if path:match'%.lua' then
|
||||
package.preload[name] = assert(loadfile(path))
|
||||
else
|
||||
local name = name:gsub('.*%-', '') -- remove any hyphen prefix
|
||||
local symbol = 'luaopen_' .. name:gsub('%.', '_')
|
||||
--improve: generalize to support all-in-one loader?
|
||||
local path = path:gsub('%$%{CMAKE_CFG_INTDIR%}', CMAKE_CFG_INTDIR)
|
||||
package.preload[name] = assert(package.loadlib(path, symbol))
|
||||
end
|
||||
end
|
||||
end
|
||||
preload_modules(modules)
|
||||
arg[0] = '${TESTFILEABS}'
|
||||
table.remove(arg, 1)
|
||||
return assert(loadfile '${TESTFILEABS}')(unpack(arg))
|
||||
" )
|
||||
if ( _ARG_WORKING_DIRECTORY )
|
||||
get_filename_component (
|
||||
TESTCURRENTDIRABS ${_ARG_WORKING_DIRECTORY} ABSOLUTE )
|
||||
# note: CMake 2.6 (unlike 2.8) lacks WORKING_DIRECTORY parameter.
|
||||
set ( _pre ${CMAKE_COMMAND} -E chdir "${TESTCURRENTDIRABS}" )
|
||||
endif ()
|
||||
file ( WRITE ${TESTWRAPPER} ${TESTWRAPPERSOURCE})
|
||||
add_test ( NAME ${TESTFILEBASE} COMMAND ${_pre} ${LUA}
|
||||
${TESTWRAPPER} "${CMAKE_CFG_INTDIR}"
|
||||
${_ARG_DEFAULT_ARGS} )
|
||||
endif ()
|
||||
# see also http://gdcm.svn.sourceforge.net/viewvc/gdcm/Sandbox/CMakeModules/UsePythonTest.cmake
|
||||
# Note: ${CMAKE_CFG_INTDIR} is a command-line argument to allow proper
|
||||
# expansion by the native build tool.
|
||||
endmacro ()
|
||||
|
||||
|
||||
# Converts Lua source file `_source` to binary string embedded in C source
|
||||
# file `_target`. Optionally compiles Lua source to byte code (not available
|
||||
# under LuaJIT2, which doesn't have a bytecode loader). Additionally, Lua
|
||||
# versions of bin2c [1] and luac [2] may be passed respectively as additional
|
||||
# arguments.
|
||||
#
|
||||
# [1] http://lua-users.org/wiki/BinToCee
|
||||
# [2] http://lua-users.org/wiki/LuaCompilerInLua
|
||||
function ( add_lua_bin2c _target _source )
|
||||
find_program ( LUA NAMES lua lua.bat )
|
||||
execute_process ( COMMAND ${LUA} -e "string.dump(function()end)"
|
||||
RESULT_VARIABLE _LUA_DUMP_RESULT ERROR_QUIET )
|
||||
if ( NOT ${_LUA_DUMP_RESULT} )
|
||||
SET ( HAVE_LUA_DUMP true )
|
||||
endif ()
|
||||
message ( "-- string.dump=${HAVE_LUA_DUMP}" )
|
||||
|
||||
if ( ARGV2 )
|
||||
get_filename_component ( BIN2C ${ARGV2} ABSOLUTE )
|
||||
set ( BIN2C ${LUA} ${BIN2C} )
|
||||
else ()
|
||||
find_program ( BIN2C NAMES bin2c bin2c.bat )
|
||||
endif ()
|
||||
if ( HAVE_LUA_DUMP )
|
||||
if ( ARGV3 )
|
||||
get_filename_component ( LUAC ${ARGV3} ABSOLUTE )
|
||||
set ( LUAC ${LUA} ${LUAC} )
|
||||
else ()
|
||||
find_program ( LUAC NAMES luac luac.bat )
|
||||
endif ()
|
||||
endif ( HAVE_LUA_DUMP )
|
||||
message ( "-- bin2c=${BIN2C}" )
|
||||
message ( "-- luac=${LUAC}" )
|
||||
|
||||
get_filename_component ( SOURCEABS ${_source} ABSOLUTE )
|
||||
if ( HAVE_LUA_DUMP )
|
||||
get_filename_component ( SOURCEBASE ${_source} NAME_WE )
|
||||
add_custom_command (
|
||||
OUTPUT ${_target} DEPENDS ${_source}
|
||||
COMMAND ${LUAC} -o ${CMAKE_CURRENT_BINARY_DIR}/${SOURCEBASE}.lo
|
||||
${SOURCEABS}
|
||||
COMMAND ${BIN2C} ${CMAKE_CURRENT_BINARY_DIR}/${SOURCEBASE}.lo
|
||||
">${_target}" )
|
||||
else ()
|
||||
add_custom_command (
|
||||
OUTPUT ${_target} DEPENDS ${SOURCEABS}
|
||||
COMMAND ${BIN2C} ${_source} ">${_target}" )
|
||||
endif ()
|
||||
endfunction()
|
15
3rdparty/lsqlite3/dist.info
vendored
15
3rdparty/lsqlite3/dist.info
vendored
@ -1,15 +0,0 @@
|
||||
--- This dist file is part of LuaDist project
|
||||
|
||||
name = "lsqlite3"
|
||||
version = "0.6devel"
|
||||
|
||||
desc = "LuaSQLite 3 is a thin wrapper around the public domain SQLite3 database engine."
|
||||
author = "Tiago Dionizio, Doug Currie"
|
||||
license = "MIT"
|
||||
url = "http://luaforge.net/projects/luasqlite/"
|
||||
maintainer = "Peter Kapec"
|
||||
|
||||
depends = {
|
||||
"lua ~> 5.1",
|
||||
"libsqlite3 >=3.5"
|
||||
}
|
893
3rdparty/lsqlite3/doc/lsqlite3.html
vendored
893
3rdparty/lsqlite3/doc/lsqlite3.html
vendored
@ -1,893 +0,0 @@
|
||||
<HTML>
|
||||
<HEAD>
|
||||
<TITLE>LuaSQLite 3</TITLE>
|
||||
<LINK REV="made" HREF="mailto:unknown@du216771.users">
|
||||
</HEAD>
|
||||
|
||||
<BODY>
|
||||
|
||||
<A NAME="__index__"></A>
|
||||
<!-- INDEX BEGIN -->
|
||||
|
||||
<UL>
|
||||
|
||||
<LI><A HREF="#name">NAME</A></LI>
|
||||
<LI><A HREF="#overview">OVERVIEW</A></LI>
|
||||
<LI><A HREF="#download">DOWNLOAD</A></LI>
|
||||
<LI><A HREF="#installation">INSTALLATION</A></LI>
|
||||
<LI><A HREF="#examples">EXAMPLES</A></LI>
|
||||
<LI><A HREF="#verification tests">VERIFICATION TESTS</A></LI>
|
||||
<LI><A HREF="#reference">REFERENCE</A></LI>
|
||||
<LI><A HREF="#sqlite3 functions">SQLite3 functions</A></LI>
|
||||
<UL>
|
||||
|
||||
<LI><A HREF="#sqlite3.complete">sqlite3.complete</A></LI>
|
||||
<LI><A HREF="#sqlite3.open">sqlite3.open</A></LI>
|
||||
<LI><A HREF="#sqlite3.open_memory">sqlite3.open_memory</A></LI>
|
||||
<LI><A HREF="#sqlite3.temp_directory">sqlite3.temp_directory</A></LI>
|
||||
<LI><A HREF="#sqlite3.version">sqlite3.version</A></LI>
|
||||
</UL>
|
||||
|
||||
<LI><A HREF="#database methods">Database methods</A></LI>
|
||||
<UL>
|
||||
|
||||
<LI><A HREF="#db:busy_handler">db:busy_handler</A></LI>
|
||||
<LI><A HREF="#db:busy_timeout">db:busy_timeout</A></LI>
|
||||
<LI><A HREF="#db:changes">db:changes</A></LI>
|
||||
<LI><A HREF="#db:close">db:close</A></LI>
|
||||
<LI><A HREF="#db:close_vm">db:close_vm</A></LI>
|
||||
<LI><A HREF="#db:create_aggregate">db:create_aggregate</A></LI>
|
||||
<LI><A HREF="#db:create_collation">db:create_collation</A></LI>
|
||||
<LI><A HREF="#db:create_function">db:create_function</A></LI>
|
||||
<LI><A HREF="#db:errcode">db:errcode</A></LI>
|
||||
<LI><A HREF="#db:errmsg">db:errmsg</A></LI>
|
||||
<LI><A HREF="#db:exec">db:exec</A></LI>
|
||||
<LI><A HREF="#db:interrupt">db:interrupt</A></LI>
|
||||
<LI><A HREF="#db:isopen">db:isopen</A></LI>
|
||||
<LI><A HREF="#db:last_insert_rowid">db:last_insert_rowid</A></LI>
|
||||
<LI><A HREF="#db:nrows">db:nrows</A></LI>
|
||||
<LI><A HREF="#db:prepare">db:prepare</A></LI>
|
||||
<LI><A HREF="#db:progress_handler">db:progress_handler</A></LI>
|
||||
<LI><A HREF="#db:rows">db:rows</A></LI>
|
||||
<LI><A HREF="#db:total_changes">db:total_changes</A></LI>
|
||||
<LI><A HREF="#db:trace">db:trace</A></LI>
|
||||
<LI><A HREF="#db:urows">db:urows</A></LI>
|
||||
</UL>
|
||||
|
||||
<LI><A HREF="#methods for prepared statements">Methods for prepared statements</A></LI>
|
||||
<UL>
|
||||
|
||||
<LI><A HREF="#stmt:bind">stmt:bind</A></LI>
|
||||
<LI><A HREF="#stmt:bind_blob">stmt:bind_blob</A></LI>
|
||||
<LI><A HREF="#stmt:bind_names">stmt:bind_names</A></LI>
|
||||
<LI><A HREF="#stmt:bind_parameter_count">stmt:bind_parameter_count</A></LI>
|
||||
<LI><A HREF="#stmt:bind_parameter_name">stmt:bind_parameter_name</A></LI>
|
||||
<LI><A HREF="#stmt:bind_values">stmt:bind_values</A></LI>
|
||||
<LI><A HREF="#stmt:columns">stmt:columns</A></LI>
|
||||
<LI><A HREF="#stmt:finalize">stmt:finalize</A></LI>
|
||||
<LI><A HREF="#stmt:get_name">stmt:get_name</A></LI>
|
||||
<LI><A HREF="#stmt:get_named_types">stmt:get_named_types</A></LI>
|
||||
<LI><A HREF="#stmt:get_named_values">stmt:get_named_values</A></LI>
|
||||
<LI><A HREF="#stmt:get_names">stmt:get_names</A></LI>
|
||||
<LI><A HREF="#stmt:get_type">stmt:get_type</A></LI>
|
||||
<LI><A HREF="#stmt:get_types">stmt:get_types</A></LI>
|
||||
<LI><A HREF="#stmt:get_unames">stmt:get_unames</A></LI>
|
||||
<LI><A HREF="#stmt:get_utypes">stmt:get_utypes</A></LI>
|
||||
<LI><A HREF="#stmt:get_uvalues">stmt:get_uvalues</A></LI>
|
||||
<LI><A HREF="#stmt:get_value">stmt:get_value</A></LI>
|
||||
<LI><A HREF="#stmt:get_values">stmt:get_values</A></LI>
|
||||
<LI><A HREF="#stmt:isopen">stmt:isopen</A></LI>
|
||||
<LI><A HREF="#stmt:nrows">stmt:nrows</A></LI>
|
||||
<LI><A HREF="#stmt:reset">stmt:reset</A></LI>
|
||||
<LI><A HREF="#stmt:rows">stmt:rows</A></LI>
|
||||
<LI><A HREF="#stmt:step">stmt:step</A></LI>
|
||||
<LI><A HREF="#stmt:urows">stmt:urows</A></LI>
|
||||
</UL>
|
||||
|
||||
<LI><A HREF="#methods for callback contexts">Methods for callback contexts</A></LI>
|
||||
<UL>
|
||||
|
||||
<LI><A HREF="#context:aggregate_count">context:aggregate_count</A></LI>
|
||||
<LI><A HREF="#context:get_aggregate_data">context:get_aggregate_data</A></LI>
|
||||
<LI><A HREF="#context:set_aggregate_data">context:set_aggregate_data</A></LI>
|
||||
<LI><A HREF="#context:result">context:result</A></LI>
|
||||
<LI><A HREF="#context:result_null">context:result_null</A></LI>
|
||||
<LI><A HREF="#context:result_number">context:result_number</A></LI>
|
||||
<LI><A HREF="#context:result_int">context:result_int</A></LI>
|
||||
<LI><A HREF="#context:result_text">context:result_text</A></LI>
|
||||
<LI><A HREF="#context:result_blob">context:result_blob</A></LI>
|
||||
<LI><A HREF="#context:result_error">context:result_error</A></LI>
|
||||
<LI><A HREF="#context:user_data">context:user_data</A></LI>
|
||||
</UL>
|
||||
|
||||
<LI><A HREF="#numerical error and result codes">Numerical error and result codes</A></LI>
|
||||
<LI><A HREF="#version">VERSION</A></LI>
|
||||
<LI><A HREF="#credits">CREDITS</A></LI>
|
||||
<LI><A HREF="#license">LICENSE</A></LI>
|
||||
</UL>
|
||||
<!-- INDEX END -->
|
||||
|
||||
<HR>
|
||||
<P>
|
||||
<HR>
|
||||
<H1><A NAME="name">NAME</A></H1>
|
||||
<P><STRONG>LuaSQLite 3</STRONG> - a Lua 5.1 wrapper for the SQLite3 library</P>
|
||||
<P>
|
||||
<HR>
|
||||
<H1><A NAME="overview">OVERVIEW</A></H1>
|
||||
<P><STRONG>LuaSQLite 3</STRONG> is a thin wrapper around the public domain SQLite3
|
||||
database engine.</P>
|
||||
<P>The <CODE>lsqlite3</CODE> module supports the creation and manipulation of
|
||||
SQLite3 databases. After a <CODE>require('lsqlite3')</CODE> the exported
|
||||
functions are called with prefix <CODE>sqlite3</CODE>. However, most sqlite3
|
||||
functions are called via an object-oriented interface to either
|
||||
database or SQL statement objects; see below for details.</P>
|
||||
<P>This documentation does not attempt to describe how SQLite3 itself
|
||||
works, it just describes the Lua binding and the available functions.
|
||||
For more information about the SQL features supported by SQLite3 and
|
||||
details about the syntax of SQL statements and queries, please see the
|
||||
<STRONG>SQLite3 documentation</STRONG> <A HREF="http://www.sqlite.org/">http://www.sqlite.org/</A>. Using some of the
|
||||
advanced features (how to use callbacks, for instance) will require
|
||||
some familiarity with the SQLite3 API.</P>
|
||||
<P>
|
||||
<HR>
|
||||
<H1><A NAME="download">DOWNLOAD</A></H1>
|
||||
<P><STRONG>LuaSQLite 3</STRONG> source code can be downloaded from its
|
||||
LuaForge (<A HREF="http://luaforge.net/projects/luasqlite/">http://luaforge.net/projects/luasqlite/</A>) page.</P>
|
||||
<P>You will also need to build or obtain an SQLite3 loadable library
|
||||
(DLL or .so). See <A HREF="http://www.sqlite.org/">http://www.sqlite.org/</A> for obtaining SQLite3
|
||||
source code or downloading a binary SQLite3 library.</P>
|
||||
<P>
|
||||
<HR>
|
||||
<H1><A NAME="installation">INSTALLATION</A></H1>
|
||||
<P>A <EM>Makefile</EM> is provided; it assumes an SQLite3 library is already
|
||||
installed.</P>
|
||||
<P>
|
||||
<HR>
|
||||
<H1><A NAME="examples">EXAMPLES</A></H1>
|
||||
<P>The distribution contains an <EM>examples</EM> directory. The unit tests
|
||||
also show some example use.</P>
|
||||
<P>
|
||||
<HR>
|
||||
<H1><A NAME="verification tests">VERIFICATION TESTS</A></H1>
|
||||
<P>The distribution contains some units tests using Michael Roth's
|
||||
<CODE>lunit</CODE> (which is also included). Some of the tests were also derived
|
||||
from Michael's <STRONG>lua-sqlite3</STRONG> module, and more unit tests added by
|
||||
Doug Currie.</P>
|
||||
<P>The distribution also contains some functional tests by Tiago.</P>
|
||||
<P>This version of <CODE>lsqlite3</CODE> was tested with SQLite 3.4.2.</P>
|
||||
<P>
|
||||
<HR>
|
||||
<H1><A NAME="reference">REFERENCE</A></H1>
|
||||
<P>
|
||||
<HR>
|
||||
<H1><A NAME="sqlite3 functions">SQLite3 functions</A></H1>
|
||||
<P>
|
||||
<H2><A NAME="sqlite3.complete">sqlite3.complete</A></H2>
|
||||
<PRE>
|
||||
sqlite3.complete(sql)</PRE>
|
||||
<P>Returns true if the string <CODE>sql</CODE> comprises one or more complete SQL
|
||||
statements and false otherwise.</P>
|
||||
<P>
|
||||
<H2><A NAME="sqlite3.open">sqlite3.open</A></H2>
|
||||
<PRE>
|
||||
sqlite3.open(filename)</PRE>
|
||||
<P>Opens (or creates if it does not exist) an SQLite database with name
|
||||
<CODE>filename</CODE> and returns its handle as userdata (the returned object
|
||||
should be used for all further method calls in connection with this
|
||||
specific database, see <A HREF="#database methods">Database methods</A>). Example:</P>
|
||||
<PRE>
|
||||
myDB=sqlite3.open('MyDatabase.sqlite3') -- open
|
||||
-- do some database calls...
|
||||
myDB:close() -- close</PRE>
|
||||
<P>In case of an error, the function returns nil, an error code and an
|
||||
error message.</P>
|
||||
<P>
|
||||
<H2><A NAME="sqlite3.open_memory">sqlite3.open_memory</A></H2>
|
||||
<PRE>
|
||||
sqlite3.open_memory()</PRE>
|
||||
<P>Opens an SQLite database <STRONG>in memory</STRONG> and returns its handle as
|
||||
userdata. In case of an error, the function returns nil, an error code
|
||||
and an error message. (In-memory databases are volatile as they are
|
||||
never stored on disk.)</P>
|
||||
<P>
|
||||
<H2><A NAME="sqlite3.temp_directory">sqlite3.temp_directory</A></H2>
|
||||
<PRE>
|
||||
sqlite3.temp_directory([temp])</PRE>
|
||||
<P>Sets or queries the directory used by SQLite for temporary files. If
|
||||
string <CODE>temp</CODE> is a directory name or nil, the temporary directory is
|
||||
set accordingly and the old value is returned. If <CODE>temp</CODE> is missing,
|
||||
the function simply returns the current temporary directory.</P>
|
||||
<P>
|
||||
<H2><A NAME="sqlite3.version">sqlite3.version</A></H2>
|
||||
<PRE>
|
||||
sqlite3.version()</PRE>
|
||||
<P>Returns a string with SQLite version information, in the form 'x.y[.z]'.</P>
|
||||
<P>
|
||||
<HR>
|
||||
<H1><A NAME="database methods">Database methods</A></H1>
|
||||
<P>After opening a database with <A HREF="#sqlite3.open"><CODE>sqlite3.open()</CODE></A> or
|
||||
<A HREF="#sqlite3.open_memory"><CODE>sqlite3.open_memory()</CODE></A>
|
||||
the returned database object should be used for all further method calls
|
||||
in connection with that database. An open database object supports the
|
||||
following methods.</P>
|
||||
<P>
|
||||
<H2><A NAME="db:busy_handler">db:busy_handler</A></H2>
|
||||
<PRE>
|
||||
db:busy_handler([func[,udata]])</PRE>
|
||||
<P>Sets or removes a busy handler for a database. <CODE>func</CODE> is either a Lua
|
||||
function that implements the busy handler or nil to remove a previously
|
||||
set handler. This function returns nothing.</P>
|
||||
<P>The handler function is called with two parameters: <CODE>udata</CODE> and the
|
||||
number of (re-)tries for a pending transaction. It should return nil,
|
||||
false or 0 if the transaction is to be aborted. All other values will
|
||||
result in another attempt to perform the transaction. (See the SQLite
|
||||
documentation for important hints about writing busy handlers.)</P>
|
||||
<P>
|
||||
<H2><A NAME="db:busy_timeout">db:busy_timeout</A></H2>
|
||||
<PRE>
|
||||
db:busy_timeout(t)</PRE>
|
||||
<P>Sets a busy handler that waits for <CODE>t</CODE> milliseconds if a transaction
|
||||
cannot proceed. Calling this function will remove any busy handler set
|
||||
by <A HREF="#db:busy_handler"><CODE>db:busy_handler()</CODE></A>; calling it with an argument
|
||||
less than or equal to 0 will turn off all busy handlers.</P>
|
||||
<P>
|
||||
<H2><A NAME="db:changes">db:changes</A></H2>
|
||||
<PRE>
|
||||
db:changes()</PRE>
|
||||
<P>This function returns the number of database rows that were changed (or
|
||||
inserted or deleted) by the most recent SQL statement. Only changes that
|
||||
are directly specified by INSERT, UPDATE, or DELETE statements are
|
||||
counted. Auxiliary changes caused by triggers are not counted. Use
|
||||
<A HREF="#db:total_changes"><CODE>db:total_changes()</CODE></A> to find the total number of
|
||||
changes.</P>
|
||||
<P>
|
||||
<H2><A NAME="db:close">db:close</A></H2>
|
||||
<PRE>
|
||||
db:close()</PRE>
|
||||
<P>Closes a database. All SQL statements prepared using
|
||||
<A HREF="#db:prepare"><CODE>db:prepare()</CODE></A> should
|
||||
have been finalized before this function is called. The function returns
|
||||
<CODE>sqlite3.OK</CODE> on success or else a numerical error code (see the list of
|
||||
<A HREF="#numerical error and result codes">Numerical error and result codes</A>).</P>
|
||||
<P>
|
||||
<H2><A NAME="db:close_vm">db:close_vm</A></H2>
|
||||
<PRE>
|
||||
db:close_vm(temponly)</PRE>
|
||||
<P>Finalizes all statements that have not been explicitly finalized. If
|
||||
<CODE>temponly</CODE> is true, only internal, temporary statements are finalized.
|
||||
This function returns nothing.</P>
|
||||
<P>
|
||||
<H2><A NAME="db:create_aggregate">db:create_aggregate</A></H2>
|
||||
<PRE>
|
||||
db:create_aggregate(name,nargs,step,final)</PRE>
|
||||
<P>This function creates an aggregate callback function. Aggregates perform
|
||||
an operation over all rows in a query. <CODE>name</CODE> is a string with the name
|
||||
of the aggregate function as given in an SQL statement; <CODE>nargs</CODE> is the
|
||||
number of arguments this call will provide. <CODE>step</CODE> is the actual Lua
|
||||
function that gets called once for every row; it should accept a function
|
||||
context (see <A HREF="#methods for callback contexts">Methods for callback contexts</A>) plus the same number of
|
||||
parameters as given in <CODE>nargs</CODE>. <CODE>final</CODE> is a function that is called
|
||||
once after all rows have been processed; it receives one argument, the
|
||||
function context.</P>
|
||||
<P>The function context can be used inside the two callback functions to
|
||||
communicate with SQLite3. Here is a simple example:</P>
|
||||
<PRE>
|
||||
db:exec[=[
|
||||
CREATE TABLE numbers(num1,num2);
|
||||
INSERT INTO numbers VALUES(1,11);
|
||||
INSERT INTO numbers VALUES(2,22);
|
||||
INSERT INTO numbers VALUES(3,33);
|
||||
]=]
|
||||
local num_sum=0
|
||||
local function oneRow(context,num) -- add one column in all rows
|
||||
num_sum=num_sum+num
|
||||
end
|
||||
local function afterLast(context) -- return sum after last row has been processed
|
||||
context:result_number(num_sum)
|
||||
num_sum=0
|
||||
end
|
||||
db:create_aggregate("do_the_sums",1,oneRow,afterLast)
|
||||
for sum in db:urows('SELECT do_the_sums(num1) FROM numbers') do print("Sum of col 1:",sum) end
|
||||
for sum in db:urows('SELECT do_the_sums(num2) FROM numbers') do print("Sum of col 2:",sum) end</PRE>
|
||||
<P>This prints:</P>
|
||||
<PRE>
|
||||
Sum of col 1: 6
|
||||
Sum of col 2: 66</PRE>
|
||||
<P>
|
||||
<H2><A NAME="db:create_collation">db:create_collation</A></H2>
|
||||
<PRE>
|
||||
db:create_collation(name,func)</PRE>
|
||||
<P>This creates a collation callback. A collation callback is used to
|
||||
establish a collation order, mostly for string comparisons and sorting
|
||||
purposes. <CODE>name</CODE> is a string with the name of the collation to be created;
|
||||
<CODE>func</CODE> is a function that accepts two string arguments, compares them
|
||||
and returns 0 if both strings are identical, -1 if the first argument is
|
||||
lower in the collation order than the second and 1 if the first argument
|
||||
is higher in the collation order than the second. A simple example:</P>
|
||||
<PRE>
|
||||
local function collate(s1,s2)
|
||||
s1=s1:lower()
|
||||
s2=s2:lower()
|
||||
if s1==s2 then return 0
|
||||
elseif s1<s2 then return -1
|
||||
else return 1 end
|
||||
end
|
||||
db:exec[=[
|
||||
CREATE TABLE test(id INTEGER PRIMARY KEY,content COLLATE CINSENS);
|
||||
INSERT INTO test VALUES(NULL,'hello world');
|
||||
INSERT INTO test VALUES(NULL,'Buenos dias');
|
||||
INSERT INTO test VALUES(NULL,'HELLO WORLD');
|
||||
]=]
|
||||
db:create_collation('CINSENS',collate)
|
||||
for row in db:nrows('SELECT * FROM test') do print(row.id,row.content) end</PRE>
|
||||
<P>
|
||||
<H2><A NAME="db:create_function">db:create_function</A></H2>
|
||||
<PRE>
|
||||
db:create_function(name,nargs,func)</PRE>
|
||||
<P>This function creates a callback function. Callback function are called
|
||||
by SQLite3 once for every row in a query. <CODE>name</CODE> is a string with the
|
||||
name of the callback function as given in an SQL statement; <CODE>nargs</CODE> is
|
||||
the number of arguments this call will provide. <CODE>func</CODE> is the actual Lua
|
||||
function that gets called once for every row; it should accept a
|
||||
function context (see <A HREF="#methods for callback contexts">Methods for callback contexts</A>) plus the same
|
||||
number of parameters as given in nargs. Here is an example:</P>
|
||||
<PRE>
|
||||
db:exec'CREATE TABLE test(col1,col2,col3)'
|
||||
db:exec'INSERT INTO test VALUES(1,2,4)'
|
||||
db:exec'INSERT INTO test VALUES(2,4,9)'
|
||||
db:exec'INSERT INTO test VALUES(3,6,16)'
|
||||
db:create_function('sum_cols',3,function(ctx,a,b,c)
|
||||
ctx:result_number(a+b+c)
|
||||
end))
|
||||
for col1,col2,col3,sum in db:urows('SELECT *,sum_cols(col1,col2,col3) FROM test') do
|
||||
util.printf('%2i+%2i+%2i=%2i\n',col1,col2,col3,sum)
|
||||
end</PRE>
|
||||
<P>
|
||||
<H2><A NAME="db:errcode">db:errcode</A></H2>
|
||||
<PRE>
|
||||
db:errcode()
|
||||
db:error_code()</PRE>
|
||||
<P>Returns the numerical result code (or extended result code) for the most
|
||||
recent failed call associated with database db. See
|
||||
<A HREF="#numerical error and result codes">Numerical error and result codes</A> for details.</P>
|
||||
<P>
|
||||
<H2><A NAME="db:errmsg">db:errmsg</A></H2>
|
||||
<PRE>
|
||||
db:errmsg()
|
||||
db:error_message()</PRE>
|
||||
<P>Returns a string that contains an error message for the most recent
|
||||
failed call associated with database db.</P>
|
||||
<P>
|
||||
<H2><A NAME="db:exec">db:exec</A></H2>
|
||||
<PRE>
|
||||
db:exec(sql[,func[,udata]])
|
||||
db:execute(sql[,func[,udata]])</PRE>
|
||||
<P>Compiles and executes the SQL <CODE>statement(s)</CODE> given in string <CODE>sql</CODE>. The
|
||||
statements are simply executed one after the other and not stored. The
|
||||
function returns <CODE>sqlite3.OK</CODE> on success or else a numerical error code
|
||||
(see <A HREF="#numerical error and result codes">Numerical error and result codes</A>).</P>
|
||||
<P>If one or more of the SQL statements are queries, then the callback
|
||||
function specified in <CODE>func</CODE> is invoked once for each row of the query
|
||||
result (if <CODE>func</CODE> is nil, no callback is invoked). The callback receives
|
||||
four arguments: <CODE>udata</CODE> (the third parameter of the <CODE>db:exec()</CODE> call),
|
||||
the number of columns in the row, a table with the column values and
|
||||
another table with the column names. The callback function should return
|
||||
0. If the callback returns a non-zero value then the query is aborted,
|
||||
all subsequent SQL statements are skipped and <CODE>db:exec()</CODE> returns
|
||||
<CODE>sqlite3.ABORT</CODE>. Here is a simple example:</P>
|
||||
<PRE>
|
||||
sql=[=[
|
||||
CREATE TABLE numbers(num1,num2,str);
|
||||
INSERT INTO numbers VALUES(1,11,"ABC");
|
||||
INSERT INTO numbers VALUES(2,22,"DEF");
|
||||
INSERT INTO numbers VALUES(3,33,"UVW");
|
||||
INSERT INTO numbers VALUES(4,44,"XYZ");
|
||||
SELECT * FROM numbers;
|
||||
]=]
|
||||
function showrow(udata,cols,values,names)
|
||||
assert(udata=='test_udata')
|
||||
print('exec:')
|
||||
for i=1,cols do print('',names[i],values[i]) end
|
||||
return 0
|
||||
end
|
||||
db:exec(sql,showrow,'test_udata')</PRE>
|
||||
<P>
|
||||
<H2><A NAME="db:interrupt">db:interrupt</A></H2>
|
||||
<PRE>
|
||||
db:interrupt()</PRE>
|
||||
<P>This function causes any pending database operation to abort and return
|
||||
at the next opportunity. This function returns nothing.</P>
|
||||
<P>
|
||||
<H2><A NAME="db:isopen">db:isopen</A></H2>
|
||||
<PRE>
|
||||
db:isopen()</PRE>
|
||||
<P>Returns true if database db is open, false otherwise.</P>
|
||||
<P>
|
||||
<H2><A NAME="db:last_insert_rowid">db:last_insert_rowid</A></H2>
|
||||
<PRE>
|
||||
db:last_insert_rowid()</PRE>
|
||||
<P>This function returns the rowid of the most recent INSERT into the
|
||||
database. If no inserts have ever occurred, 0 is returned. (Each row in
|
||||
an SQLite table has a unique 64-bit signed integer key called the
|
||||
'rowid'. This id is always available as an undeclared column named
|
||||
ROWID, OID, or _ROWID_. If the table has a column of type INTEGER
|
||||
PRIMARY KEY then that column is another alias for the rowid.)</P>
|
||||
<P>If an INSERT occurs within a trigger, then the rowid of the inserted row
|
||||
is returned as long as the trigger is running. Once the trigger
|
||||
terminates, the value returned reverts to the last value inserted before
|
||||
the trigger fired.</P>
|
||||
<P>
|
||||
<H2><A NAME="db:nrows">db:nrows</A></H2>
|
||||
<PRE>
|
||||
db:nrows(sql)</PRE>
|
||||
<P>Creates an iterator that returns the successive rows selected by the SQL
|
||||
statement given in string <CODE>sql</CODE>. Each call to the iterator returns a
|
||||
table in which the named fields correspond to the columns in the database.
|
||||
Here is an example:</P>
|
||||
<PRE>
|
||||
db:exec[=[
|
||||
CREATE TABLE numbers(num1,num2);
|
||||
INSERT INTO numbers VALUES(1,11);
|
||||
INSERT INTO numbers VALUES(2,22);
|
||||
INSERT INTO numbers VALUES(3,33);
|
||||
]=]
|
||||
for a in db:nrows('SELECT * FROM numbers') do table.print(a) end</PRE>
|
||||
<P>This script prints:</P>
|
||||
<PRE>
|
||||
num2: 11
|
||||
num1: 1
|
||||
num2: 22
|
||||
num1: 2
|
||||
num2: 33
|
||||
num1: 3</PRE>
|
||||
<P>
|
||||
<H2><A NAME="db:prepare">db:prepare</A></H2>
|
||||
<PRE>
|
||||
db:prepare(sql)</PRE>
|
||||
<P>This function compiles the SQL statement in string <CODE>sql</CODE> into an internal
|
||||
representation and returns this as userdata. The returned object should
|
||||
be used for all further method calls in connection with this specific
|
||||
SQL statement (see <A HREF="#methods for prepared statements">Methods for prepared statements</A>).</P>
|
||||
<P>
|
||||
<H2><A NAME="db:progress_handler">db:progress_handler</A></H2>
|
||||
<PRE>
|
||||
db:progress_handler(n,func,udata)</PRE>
|
||||
<P>This function installs a callback function <CODE>func</CODE> that is invoked
|
||||
periodically during long-running calls to <A HREF="#db:exec"><CODE>db:exec()</CODE></A>
|
||||
or <A HREF="#stmt:step"><CODE>stmt:step()</CODE></A>. The
|
||||
progress callback is invoked once for every <CODE>n</CODE> internal operations,
|
||||
where <CODE>n</CODE> is the first argument to this function. <CODE>udata</CODE> is passed to
|
||||
the progress callback function each time it is invoked. If a call to
|
||||
<CODE>db:exec()</CODE> or <CODE>stmt:step()</CODE> results in fewer than <CODE>n</CODE> operations
|
||||
being executed, then the progress callback is never invoked. Only a
|
||||
single progress callback function may be registered for each opened
|
||||
database and a call to this function will overwrite any previously set
|
||||
callback function. To remove the progress callback altogether, pass nil
|
||||
as the second argument.</P>
|
||||
<P>If the progress callback returns a result other than 0, then the current
|
||||
query is immediately terminated, any database changes are rolled back
|
||||
and the containing <CODE>db:exec()</CODE> or <CODE>stmt:step()</CODE> call returns
|
||||
<CODE>sqlite3.INTERRUPT</CODE>. This feature can be used to cancel long-running
|
||||
queries.</P>
|
||||
<P>
|
||||
<H2><A NAME="db:rows">db:rows</A></H2>
|
||||
<PRE>
|
||||
db:rows(sql)</PRE>
|
||||
<P>Creates an iterator that returns the successive rows selected by the SQL
|
||||
statement given in string <CODE>sql</CODE>. Each call to the iterator returns a table
|
||||
in which the numerical indices 1 to n correspond to the selected columns
|
||||
1 to n in the database. Here is an example:</P>
|
||||
<PRE>
|
||||
db:exec[=[
|
||||
CREATE TABLE numbers(num1,num2);
|
||||
INSERT INTO numbers VALUES(1,11);
|
||||
INSERT INTO numbers VALUES(2,22);
|
||||
INSERT INTO numbers VALUES(3,33);
|
||||
]=]
|
||||
for a in db:rows('SELECT * FROM numbers') do table.print(a) end</PRE>
|
||||
<P>This script prints:</P>
|
||||
<PRE>
|
||||
1: 1
|
||||
2: 11
|
||||
1: 2
|
||||
2: 22
|
||||
1: 3
|
||||
2: 33</PRE>
|
||||
<P>
|
||||
<H2><A NAME="db:total_changes">db:total_changes</A></H2>
|
||||
<PRE>
|
||||
db:total_changes()</PRE>
|
||||
<P>This function returns the number of database rows that have been
|
||||
modified by INSERT, UPDATE or DELETE statements since the database was
|
||||
opened. This includes UPDATE, INSERT and DELETE statements executed as
|
||||
part of trigger programs. All changes are counted as soon as the
|
||||
statement that produces them is completed by calling either
|
||||
<A HREF="#stmt:reset"><CODE>stmt:reset()</CODE></A> or <A HREF="#stmt:finalize"><CODE>stmt:finalize()</CODE></A>.</P>
|
||||
<P>
|
||||
<H2><A NAME="db:trace">db:trace</A></H2>
|
||||
<PRE>
|
||||
db:trace(func,udata)</PRE>
|
||||
<P>This function installs a trace callback handler. <CODE>func</CODE> is a Lua
|
||||
function that is called by SQLite3 just before the evaluation of an SQL
|
||||
statement. This callback receives two arguments: the first is the
|
||||
<CODE>udata</CODE> argument used when the callback was installed; the second is a
|
||||
string with the SQL statement about to be executed.</P>
|
||||
<P>
|
||||
<H2><A NAME="db:urows">db:urows</A></H2>
|
||||
<PRE>
|
||||
db:urows(sql)</PRE>
|
||||
<P>Creates an iterator that returns the successive rows selected by the SQL
|
||||
statement given in string <CODE>sql</CODE>. Each call to the iterator returns the
|
||||
values that correspond to the columns in the currently selected row.
|
||||
Here is an example:</P>
|
||||
<PRE>
|
||||
db:exec[=[
|
||||
CREATE TABLE numbers(num1,num2);
|
||||
INSERT INTO numbers VALUES(1,11);
|
||||
INSERT INTO numbers VALUES(2,22);
|
||||
INSERT INTO numbers VALUES(3,33);
|
||||
]=]
|
||||
for num1,num2 in db:urows('SELECT * FROM numbers') do print(num1,num2) end</PRE>
|
||||
<P>This script prints:</P>
|
||||
<PRE>
|
||||
1 11
|
||||
2 22
|
||||
3 33</PRE>
|
||||
<P>
|
||||
<HR>
|
||||
<H1><A NAME="methods for prepared statements">Methods for prepared statements</A></H1>
|
||||
<P>After creating a prepared statement with <A HREF="#db:prepare"><CODE>db:prepare()</CODE></A>
|
||||
the returned statement object should be used for all further calls in
|
||||
connection with that statement. Statement objects support the following
|
||||
methods.</P>
|
||||
<P>
|
||||
<H2><A NAME="stmt:bind">stmt:bind</A></H2>
|
||||
<PRE>
|
||||
stmt:bind(n[,value])</PRE>
|
||||
<P>Binds value to statement parameter <CODE>n</CODE>. If the type of value is string
|
||||
or number, it is bound as text or double, respectively. If <CODE>value</CODE> is a
|
||||
boolean or nil or missing, any previous binding is removed. The function
|
||||
returns <CODE>sqlite3.OK</CODE> on success or else a numerical error code (see
|
||||
<A HREF="#numerical error and result codes">Numerical error and result codes</A>).</P>
|
||||
<P>
|
||||
<H2><A NAME="stmt:bind_blob">stmt:bind_blob</A></H2>
|
||||
<PRE>
|
||||
stmt:bind_blob(n,blob)</PRE>
|
||||
<P>Binds string <CODE>blob</CODE> (which can be a binary string) as a blob to
|
||||
statement parameter <CODE>n</CODE>. The function returns <CODE>sqlite3.OK</CODE> on success
|
||||
or else a numerical error code (see <A HREF="#numerical error and result codes">Numerical error and result codes</A>).</P>
|
||||
<P>
|
||||
<H2><A NAME="stmt:bind_names">stmt:bind_names</A></H2>
|
||||
<PRE>
|
||||
stmt:bind_names(nametable)</PRE>
|
||||
<P>Binds the values in <CODE>nametable</CODE> to statement parameters. If the
|
||||
statement parameters are named (i.e., of the form ``:AAA'' or ``$AAA'')
|
||||
then this function looks for appropriately named fields in <CODE>nametable</CODE>;
|
||||
if the statement parameters are
|
||||
not named, it looks for numerical fields 1 to the number of statement
|
||||
parameters. The function returns <CODE>sqlite3.OK</CODE> on success or else a
|
||||
numerical error code (see <A HREF="#numerical error and result codes">Numerical error and result codes</A>).</P>
|
||||
<P>
|
||||
<H2><A NAME="stmt:bind_parameter_count">stmt:bind_parameter_count</A></H2>
|
||||
<PRE>
|
||||
stmt:bind_parameter_count()</PRE>
|
||||
<P>Returns the largest statement parameter index in prepared statement
|
||||
<CODE>stmt</CODE>. When the statement parameters are of the forms ``:AAA'' or ``?'',
|
||||
then they are assigned sequentially increasing numbers beginning with
|
||||
one, so the value returned is the number of parameters. However if the
|
||||
same statement parameter name is used multiple times, each occurrence
|
||||
is given the same number, so the value returned is the number of unique
|
||||
statement parameter names.</P>
|
||||
<P>If statement parameters of the form ``?NNN'' are used (where NNN is an
|
||||
integer) then there might be gaps in the numbering and the value
|
||||
returned by this interface is the index of the statement parameter with
|
||||
the largest index value.</P>
|
||||
<P>
|
||||
<H2><A NAME="stmt:bind_parameter_name">stmt:bind_parameter_name</A></H2>
|
||||
<PRE>
|
||||
stmt:bind_parameter_name(n)</PRE>
|
||||
<P>Returns the name of the <CODE>n</CODE>-th parameter in prepared statement <CODE>stmt</CODE>.
|
||||
Statement parameters of the form ``:AAA'' or ``@AAA'' or ``$VVV'' have a name
|
||||
which is the string ``:AAA'' or ``@AAA'' or ``$VVV''. In other words, the
|
||||
initial ``:'' or ``$'' or ``@'' is included as part of the name. Parameters
|
||||
of the form ``?'' or ``?NNN'' have no name. The first bound parameter has
|
||||
an index of 1.
|
||||
If the value <CODE>n</CODE> is out of range or if the <CODE>n</CODE>-th parameter is
|
||||
nameless, then nil is returned. The function returns <CODE>sqlite3.OK</CODE> on
|
||||
success or else a numerical error code (see
|
||||
<A HREF="#numerical error and result codes">Numerical error and result codes</A>)</P>
|
||||
<P>
|
||||
<H2><A NAME="stmt:bind_values">stmt:bind_values</A></H2>
|
||||
<PRE>
|
||||
stmt:bind_values(value1,value2,...,valueN)</PRE>
|
||||
<P>Binds the given values to statement parameters. The function returns
|
||||
<CODE>sqlite3.OK</CODE> on success or else a numerical error code (see
|
||||
<A HREF="#numerical error and result codes">Numerical error and result codes</A>).</P>
|
||||
<P>
|
||||
<H2><A NAME="stmt:columns">stmt:columns</A></H2>
|
||||
<PRE>
|
||||
stmt:columns()</PRE>
|
||||
<P>Returns the number of columns in the result set returned by statement
|
||||
stmt or 0 if the statement does not return data (for example an UPDATE).</P>
|
||||
<P>
|
||||
<H2><A NAME="stmt:finalize">stmt:finalize</A></H2>
|
||||
<PRE>
|
||||
stmt:finalize()</PRE>
|
||||
<P>This function frees prepared statement stmt. If the statement was
|
||||
executed successfully, or not executed at all, then <CODE>sqlite3.OK</CODE> is
|
||||
returned. If execution of the statement failed then an error code is
|
||||
returned.</P>
|
||||
<P>
|
||||
<H2><A NAME="stmt:get_name">stmt:get_name</A></H2>
|
||||
<PRE>
|
||||
stmt:get_name(n)</PRE>
|
||||
<P>Returns the name of column <CODE>n</CODE> in the result set of statement stmt. (The
|
||||
left-most column is number 0.)</P>
|
||||
<P>
|
||||
<H2><A NAME="stmt:get_named_types">stmt:get_named_types</A></H2>
|
||||
<PRE>
|
||||
stmt:get_named_types()</PRE>
|
||||
<P>Returns a table with the names and types of all columns in the result
|
||||
set of statement stmt.</P>
|
||||
<P>
|
||||
<H2><A NAME="stmt:get_named_values">stmt:get_named_values</A></H2>
|
||||
<PRE>
|
||||
stmt:get_named_values()</PRE>
|
||||
<P>This function returns a table with names and values of all columns in
|
||||
the current result row of a query.</P>
|
||||
<P>
|
||||
<H2><A NAME="stmt:get_names">stmt:get_names</A></H2>
|
||||
<PRE>
|
||||
stmt:get_names()</PRE>
|
||||
<P>This function returns an array with the names of all columns in the
|
||||
result set returned by statement stmt.</P>
|
||||
<P>
|
||||
<H2><A NAME="stmt:get_type">stmt:get_type</A></H2>
|
||||
<PRE>
|
||||
stmt:get_type(n)</PRE>
|
||||
<P>Returns the type of column <CODE>n</CODE> in the result set of statement stmt. (The
|
||||
left-most column is number 0.)</P>
|
||||
<P>
|
||||
<H2><A NAME="stmt:get_types">stmt:get_types</A></H2>
|
||||
<PRE>
|
||||
stmt:get_types()</PRE>
|
||||
<P>This function returns an array with the types of all columns in the
|
||||
result set returned by statement stmt.</P>
|
||||
<P>
|
||||
<H2><A NAME="stmt:get_unames">stmt:get_unames</A></H2>
|
||||
<PRE>
|
||||
stmt:get_unames()</PRE>
|
||||
<P>This function returns a list with the names of all columns in the result
|
||||
set returned by statement stmt.</P>
|
||||
<P>
|
||||
<H2><A NAME="stmt:get_utypes">stmt:get_utypes</A></H2>
|
||||
<PRE>
|
||||
stmt:get_utypes()</PRE>
|
||||
<P>This function returns a list with the types of all columns in the result
|
||||
set returned by statement stmt.</P>
|
||||
<P>
|
||||
<H2><A NAME="stmt:get_uvalues">stmt:get_uvalues</A></H2>
|
||||
<PRE>
|
||||
stmt:get_uvalues()</PRE>
|
||||
<P>This function returns a list with the values of all columns in the
|
||||
current result row of a query.</P>
|
||||
<P>
|
||||
<H2><A NAME="stmt:get_value">stmt:get_value</A></H2>
|
||||
<PRE>
|
||||
stmt:get_value(n)</PRE>
|
||||
<P>Returns the value of column <CODE>n</CODE> in the result set of statement stmt. (The
|
||||
left-most column is number 0.)</P>
|
||||
<P>
|
||||
<H2><A NAME="stmt:get_values">stmt:get_values</A></H2>
|
||||
<PRE>
|
||||
stmt:get_values()</PRE>
|
||||
<P>This function returns an array with the values of all columns in the
|
||||
result set returned by statement stmt.</P>
|
||||
<P>
|
||||
<H2><A NAME="stmt:isopen">stmt:isopen</A></H2>
|
||||
<PRE>
|
||||
stmt:isopen()</PRE>
|
||||
<P>Returns true if stmt has not yet been finalized, false otherwise.</P>
|
||||
<P>
|
||||
<H2><A NAME="stmt:nrows">stmt:nrows</A></H2>
|
||||
<PRE>
|
||||
stmt:nrows()</PRE>
|
||||
<P>Returns an function that iterates over the names and values of the
|
||||
result set of statement <CODE>stmt</CODE>. Each iteration returns a table with the
|
||||
names and values for the current row.
|
||||
This is the prepared statement equivalent of <A HREF="#db:nrows"><CODE>db:nrows()</CODE></A>.</P>
|
||||
<P>
|
||||
<H2><A NAME="stmt:reset">stmt:reset</A></H2>
|
||||
<PRE>
|
||||
stmt:reset()</PRE>
|
||||
<P>This function resets SQL statement <CODE>stmt</CODE>, so that it is ready to be
|
||||
re-executed. Any statement variables that had values bound to them using
|
||||
the <CODE>stmt:bind*()</CODE> functions retain their values.</P>
|
||||
<P>
|
||||
<H2><A NAME="stmt:rows">stmt:rows</A></H2>
|
||||
<PRE>
|
||||
stmt:rows()</PRE>
|
||||
<P>Returns an function that iterates over the values of the result set of
|
||||
statement stmt. Each iteration returns an array with the values for the
|
||||
current row.
|
||||
This is the prepared statement equivalent of <A HREF="#db:rows"><CODE>db:rows()</CODE></A>.</P>
|
||||
<P>
|
||||
<H2><A NAME="stmt:step">stmt:step</A></H2>
|
||||
<PRE>
|
||||
stmt:step()</PRE>
|
||||
<P>This function must be called to evaluate the (next iteration of the)
|
||||
prepared statement stmt. It will return one of the following values:</P>
|
||||
<UL>
|
||||
<LI>
|
||||
<CODE>sqlite3.BUSY</CODE>: the engine was unable to acquire the locks needed. If the
|
||||
statement is a COMMIT or occurs outside of an explicit transaction, then
|
||||
you can retry the statement. If the statement is not a COMMIT and occurs
|
||||
within a explicit transaction then you should rollback the transaction
|
||||
before continuing.
|
||||
<P></P>
|
||||
<LI>
|
||||
<CODE>sqlite3.DONE</CODE>: the statement has finished executing successfully.
|
||||
<A HREF="#stmt:step"><CODE>stmt:step()</CODE></A> should not be called again on this statement
|
||||
without first calling <A HREF="#stmt:reset"><CODE>stmt:reset()</CODE></A> to reset the virtual
|
||||
machine back to the initial state.
|
||||
<P></P>
|
||||
<LI>
|
||||
<CODE>sqlite3.ROW</CODE>: this is returned each time a new row of data is ready for
|
||||
processing by the caller. The values may be accessed using the column
|
||||
access functions. <A HREF="#stmt:step"><CODE>stmt:step()</CODE></A> can be called again to
|
||||
retrieve the next row of data.
|
||||
<P></P>
|
||||
<LI>
|
||||
<CODE>sqlite3.ERROR</CODE>: a run-time error (such as a constraint violation) has
|
||||
occurred. <A HREF="#stmt:step"><CODE>stmt:step()</CODE></A> should not be called again. More
|
||||
information may be found by calling <A HREF="#db:errmsg"><CODE>db:errmsg()</CODE></A>. A more
|
||||
specific error
|
||||
code (can be obtained by calling <A HREF="#stmt:reset"><CODE>stmt:reset()</CODE></A>.
|
||||
<P></P>
|
||||
<LI>
|
||||
<CODE>sqlite3.MISUSE</CODE>: the function was called inappropriately, perhaps
|
||||
because the statement has already been finalized or a previous call to
|
||||
<A HREF="#stmt:step"><CODE>stmt:step()</CODE></A> has returned <CODE>sqlite3.ERROR</CODE> or
|
||||
<CODE>sqlite3.DONE</CODE>.
|
||||
<P></P></UL>
|
||||
<P>
|
||||
<H2><A NAME="stmt:urows">stmt:urows</A></H2>
|
||||
<PRE>
|
||||
stmt:urows()</PRE>
|
||||
<P>Returns an function that iterates over the values of the result set of
|
||||
statement stmt. Each iteration returns the values for the current row.
|
||||
This is the prepared statement equivalent of <A HREF="#db:urows"><CODE>db:urows()</CODE></A>.</P>
|
||||
<P>
|
||||
<HR>
|
||||
<H1><A NAME="methods for callback contexts">Methods for callback contexts</A></H1>
|
||||
<P>A callback context is available as a parameter inside the callback
|
||||
functions <A HREF="#db:create_aggregate"><CODE>db:create_aggregate()</CODE></A> and
|
||||
<A HREF="#db:create_function"><CODE>db:create_function()</CODE></A>. It can be used
|
||||
to get further information about the state of a query.</P>
|
||||
<P>
|
||||
<H2><A NAME="context:aggregate_count">context:aggregate_count</A></H2>
|
||||
<PRE>
|
||||
context:aggregate_count()</PRE>
|
||||
<P>Returns the number of calls to the aggregate step function.</P>
|
||||
<P>
|
||||
<H2><A NAME="context:get_aggregate_data">context:get_aggregate_data</A></H2>
|
||||
<PRE>
|
||||
context:get_aggregate_data()</PRE>
|
||||
<P>Returns the user-definable data field for callback funtions.</P>
|
||||
<P>
|
||||
<H2><A NAME="context:set_aggregate_data">context:set_aggregate_data</A></H2>
|
||||
<PRE>
|
||||
context:set_aggregate_data(udata)</PRE>
|
||||
<P>Set the user-definable data field for callback funtions to <CODE>udata</CODE>.</P>
|
||||
<P>
|
||||
<H2><A NAME="context:result">context:result</A></H2>
|
||||
<PRE>
|
||||
context:result(res)</PRE>
|
||||
<P>This function sets the result of a callback function to res. The type of
|
||||
the result depends on the type of res and is either a number or a string
|
||||
or nil. All other values will raise an error message.</P>
|
||||
<P>
|
||||
<H2><A NAME="context:result_null">context:result_null</A></H2>
|
||||
<PRE>
|
||||
context:result_null()</PRE>
|
||||
<P>This function sets the result of a callback function to nil. It returns
|
||||
nothing.</P>
|
||||
<P>
|
||||
<H2><A NAME="context:result_number">context:result_number</A></H2>
|
||||
<PRE>
|
||||
context:result_number(number)
|
||||
context:result_double(number)</PRE>
|
||||
<P>This function sets the result of a callback function to the value
|
||||
<CODE>number</CODE>. It returns nothing.</P>
|
||||
<P>
|
||||
<H2><A NAME="context:result_int">context:result_int</A></H2>
|
||||
<PRE>
|
||||
context:result_int(number)</PRE>
|
||||
<P>This function sets the result of a callback function to the integer
|
||||
value in <CODE>number</CODE>. It returns nothing.</P>
|
||||
<P>
|
||||
<H2><A NAME="context:result_text">context:result_text</A></H2>
|
||||
<PRE>
|
||||
context:result_text(str)</PRE>
|
||||
<P>This function sets the result of a callback function to the string in
|
||||
<CODE>str</CODE>. It returns nothing.</P>
|
||||
<P>
|
||||
<H2><A NAME="context:result_blob">context:result_blob</A></H2>
|
||||
<PRE>
|
||||
context:result_blob(blob)</PRE>
|
||||
<P>This function sets the result of a callback function to the binary
|
||||
string in <CODE>blob</CODE>. It returns nothing.</P>
|
||||
<P>
|
||||
<H2><A NAME="context:result_error">context:result_error</A></H2>
|
||||
<PRE>
|
||||
context:result_error(err)</PRE>
|
||||
<P>This function sets the result of a callback function to the error value
|
||||
in <CODE>err</CODE>. It returns nothing.</P>
|
||||
<P>
|
||||
<H2><A NAME="context:user_data">context:user_data</A></H2>
|
||||
<PRE>
|
||||
context:user_data()</PRE>
|
||||
<P>Returns the userdata parameter given in the call to install the callback
|
||||
function (see <A HREF="#db:create_aggregate"><CODE>db:create_aggregate()</CODE></A> and
|
||||
<A HREF="#db:create_function"><CODE>db:create_function()</CODE></A> for details).</P>
|
||||
<P>
|
||||
<HR>
|
||||
<H1><A NAME="numerical error and result codes">Numerical error and result codes</A></H1>
|
||||
<P>The following constants are defined by module sqlite3:</P>
|
||||
<PRE>
|
||||
OK: 0 ERROR: 1 INTERNAL: 2 PERM: 3 ABORT: 4
|
||||
BUSY: 5 LOCKED: 6 NOMEM: 7 READONLY: 8 INTERRUPT: 9
|
||||
IOERR: 10 CORRUPT: 11 NOTFOUND: 12 FULL: 13 CANTOPEN: 14
|
||||
PROTOCOL: 15 EMPTY: 16 SCHEMA: 17 TOOBIG: 18 CONSTRAINT: 19
|
||||
MISMATCH: 20 MISUSE: 21 NOLFS: 22 FORMAT: 24 RANGE: 25
|
||||
NOTADB: 26 ROW: 100 DONE: 101</PRE>
|
||||
<P>For details about their exact meaning please see the <STRONG>SQLite3
|
||||
documentation</STRONG> <A HREF="http://www.sqlite.org/">http://www.sqlite.org/</A>.</P>
|
||||
<P>
|
||||
<HR>
|
||||
<H1><A NAME="version">VERSION</A></H1>
|
||||
<P>This is <CODE>lsqlite3</CODE> subversion 6, also known as ``devel-0.6''.</P>
|
||||
<P>
|
||||
<HR>
|
||||
<H1><A NAME="credits">CREDITS</A></H1>
|
||||
<P><CODE>lsqlite3</CODE> was developed by Tiago Dionizio and Doug Currie with
|
||||
contributions from Thomas Lauer and Michael Roth.</P>
|
||||
<P>This documentation is based on the ``(very) preliminary'' documents
|
||||
for the Idle-SQLite3 database module. Thanks to Thomas Lauer for
|
||||
making it available.</P>
|
||||
<P>
|
||||
<HR>
|
||||
<H1><A NAME="license">LICENSE</A></H1>
|
||||
<PRE>
|
||||
/************************************************************************
|
||||
* lsqlite3 *
|
||||
* Copyright (C) 2002-2007 Tiago Dionizio, Doug Currie *
|
||||
* All rights reserved. *
|
||||
* Author : Tiago Dionizio <tiago.dionizio@ist.utl.pt> *
|
||||
* Author : Doug Currie <doug.currie@alum.mit.edu> *
|
||||
* Library : lsqlite3 - a SQLite 3 database binding for Lua 5 *
|
||||
* *
|
||||
* 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. *
|
||||
************************************************************************/</PRE>
|
||||
|
||||
</BODY>
|
||||
|
||||
</HTML>
|
866
3rdparty/lsqlite3/doc/lsqlite3.pod
vendored
866
3rdparty/lsqlite3/doc/lsqlite3.pod
vendored
@ -1,866 +0,0 @@
|
||||
=pod
|
||||
|
||||
=head1 NAME
|
||||
|
||||
B<LuaSQLite 3> - a Lua 5.1 wrapper for the SQLite3 library
|
||||
|
||||
=head1 OVERVIEW
|
||||
|
||||
B<LuaSQLite 3> is a thin wrapper around the public domain SQLite3
|
||||
database engine.
|
||||
|
||||
The C<lsqlite3> module supports the creation and manipulation of
|
||||
SQLite3 databases. After a C<require('lsqlite3')> the exported
|
||||
functions are called with prefix C<sqlite3>. However, most sqlite3
|
||||
functions are called via an object-oriented interface to either
|
||||
database or SQL statement objects; see below for details.
|
||||
|
||||
This documentation does not attempt to describe how SQLite3 itself
|
||||
works, it just describes the Lua binding and the available functions.
|
||||
For more information about the SQL features supported by SQLite3 and
|
||||
details about the syntax of SQL statements and queries, please see the
|
||||
B<SQLite3 documentation> L<http://www.sqlite.org/>. Using some of the
|
||||
advanced features (how to use callbacks, for instance) will require
|
||||
some familiarity with the SQLite3 API.
|
||||
|
||||
=head1 DOWNLOAD
|
||||
|
||||
B<LuaSQLite 3> source code can be downloaded from its
|
||||
LuaForge (L<http://luaforge.net/projects/luasqlite/>) page.
|
||||
|
||||
You will also need to build or obtain an SQLite3 loadable library
|
||||
(DLL or .so). See L<http://www.sqlite.org/> for obtaining SQLite3
|
||||
source code or downloading a binary SQLite3 library.
|
||||
|
||||
=head1 INSTALLATION
|
||||
|
||||
A I<Makefile> is provided; it assumes an SQLite3 library is already
|
||||
installed.
|
||||
|
||||
=head1 EXAMPLES
|
||||
|
||||
The distribution contains an I<examples> directory. The unit tests
|
||||
also show some example use.
|
||||
|
||||
=head1 VERIFICATION TESTS
|
||||
|
||||
The distribution contains some units tests using Michael Roth's
|
||||
C<lunit> (which is also included). Some of the tests were also derived
|
||||
from Michael's B<lua-sqlite3> module, and more unit tests added by
|
||||
Doug Currie.
|
||||
|
||||
The distribution also contains some functional tests by Tiago.
|
||||
|
||||
This version of C<lsqlite3> was tested with SQLite 3.4.2.
|
||||
|
||||
=head1 REFERENCE
|
||||
|
||||
=head1 SQLite3 functions
|
||||
|
||||
=head2 sqlite3.complete
|
||||
|
||||
sqlite3.complete(sql)
|
||||
|
||||
Returns true if the string C<sql> comprises one or more complete SQL
|
||||
statements and false otherwise.
|
||||
|
||||
=head2 sqlite3.open
|
||||
|
||||
sqlite3.open(filename)
|
||||
|
||||
Opens (or creates if it does not exist) an SQLite database with name
|
||||
C<filename> and returns its handle as userdata (the returned object
|
||||
should be used for all further method calls in connection with this
|
||||
specific database, see L</Database methods>). Example:
|
||||
|
||||
myDB=sqlite3.open('MyDatabase.sqlite3') -- open
|
||||
-- do some database calls...
|
||||
myDB:close() -- close
|
||||
|
||||
In case of an error, the function returns nil, an error code and an
|
||||
error message.
|
||||
|
||||
=head2 sqlite3.open_memory
|
||||
|
||||
sqlite3.open_memory()
|
||||
|
||||
Opens an SQLite database B<in memory> and returns its handle as
|
||||
userdata. In case of an error, the function returns nil, an error code
|
||||
and an error message. (In-memory databases are volatile as they are
|
||||
never stored on disk.)
|
||||
|
||||
=head2 sqlite3.temp_directory
|
||||
|
||||
sqlite3.temp_directory([temp])
|
||||
|
||||
Sets or queries the directory used by SQLite for temporary files. If
|
||||
string C<temp> is a directory name or nil, the temporary directory is
|
||||
set accordingly and the old value is returned. If C<temp> is missing,
|
||||
the function simply returns the current temporary directory.
|
||||
|
||||
=head2 sqlite3.version
|
||||
|
||||
sqlite3.version()
|
||||
|
||||
Returns a string with SQLite version information, in the form 'x.y[.z]'.
|
||||
|
||||
=head1 Database methods
|
||||
|
||||
After opening a database with L<C<sqlite3.open()>|/sqlite3.open> or
|
||||
L<C<sqlite3.open_memory()>|/sqlite3.open_memory>
|
||||
the returned database object should be used for all further method calls
|
||||
in connection with that database. An open database object supports the
|
||||
following methods.
|
||||
|
||||
=head2 db:busy_handler
|
||||
|
||||
db:busy_handler([func[,udata]])
|
||||
|
||||
Sets or removes a busy handler for a database. C<func> is either a Lua
|
||||
function that implements the busy handler or nil to remove a previously
|
||||
set handler. This function returns nothing.
|
||||
|
||||
The handler function is called with two parameters: C<udata> and the
|
||||
number of (re-)tries for a pending transaction. It should return nil,
|
||||
false or 0 if the transaction is to be aborted. All other values will
|
||||
result in another attempt to perform the transaction. (See the SQLite
|
||||
documentation for important hints about writing busy handlers.)
|
||||
|
||||
=head2 db:busy_timeout
|
||||
|
||||
db:busy_timeout(t)
|
||||
|
||||
Sets a busy handler that waits for C<t> milliseconds if a transaction
|
||||
cannot proceed. Calling this function will remove any busy handler set
|
||||
by L<C<db:busy_handler()>|/db:busy_handler>; calling it with an argument
|
||||
less than or equal to 0 will turn off all busy handlers.
|
||||
|
||||
=head2 db:changes
|
||||
|
||||
db:changes()
|
||||
|
||||
This function returns the number of database rows that were changed (or
|
||||
inserted or deleted) by the most recent SQL statement. Only changes that
|
||||
are directly specified by INSERT, UPDATE, or DELETE statements are
|
||||
counted. Auxiliary changes caused by triggers are not counted. Use
|
||||
L<C<db:total_changes()>|/db:total_changes> to find the total number of
|
||||
changes.
|
||||
|
||||
=head2 db:close
|
||||
|
||||
db:close()
|
||||
|
||||
Closes a database. All SQL statements prepared using
|
||||
L<C<db:prepare()>|/db:prepare> should
|
||||
have been finalized before this function is called. The function returns
|
||||
C<sqlite3.OK> on success or else a numerical error code (see the list of
|
||||
L</Numerical error and result codes>).
|
||||
|
||||
=head2 db:close_vm
|
||||
|
||||
db:close_vm(temponly)
|
||||
|
||||
Finalizes all statements that have not been explicitly finalized. If
|
||||
C<temponly> is true, only internal, temporary statements are finalized.
|
||||
This function returns nothing.
|
||||
|
||||
=head2 db:create_aggregate
|
||||
|
||||
db:create_aggregate(name,nargs,step,final)
|
||||
|
||||
This function creates an aggregate callback function. Aggregates perform
|
||||
an operation over all rows in a query. C<name> is a string with the name
|
||||
of the aggregate function as given in an SQL statement; C<nargs> is the
|
||||
number of arguments this call will provide. C<step> is the actual Lua
|
||||
function that gets called once for every row; it should accept a function
|
||||
context (see L</Methods for callback contexts>) plus the same number of
|
||||
parameters as given in C<nargs>. C<final> is a function that is called
|
||||
once after all rows have been processed; it receives one argument, the
|
||||
function context.
|
||||
|
||||
The function context can be used inside the two callback functions to
|
||||
communicate with SQLite3. Here is a simple example:
|
||||
|
||||
db:exec[=[
|
||||
CREATE TABLE numbers(num1,num2);
|
||||
INSERT INTO numbers VALUES(1,11);
|
||||
INSERT INTO numbers VALUES(2,22);
|
||||
INSERT INTO numbers VALUES(3,33);
|
||||
]=]
|
||||
local num_sum=0
|
||||
local function oneRow(context,num) -- add one column in all rows
|
||||
num_sum=num_sum+num
|
||||
end
|
||||
local function afterLast(context) -- return sum after last row has been processed
|
||||
context:result_number(num_sum)
|
||||
num_sum=0
|
||||
end
|
||||
db:create_aggregate("do_the_sums",1,oneRow,afterLast)
|
||||
for sum in db:urows('SELECT do_the_sums(num1) FROM numbers') do print("Sum of col 1:",sum) end
|
||||
for sum in db:urows('SELECT do_the_sums(num2) FROM numbers') do print("Sum of col 2:",sum) end
|
||||
|
||||
This prints:
|
||||
|
||||
Sum of col 1: 6
|
||||
Sum of col 2: 66
|
||||
|
||||
=head2 db:create_collation
|
||||
|
||||
db:create_collation(name,func)
|
||||
|
||||
This creates a collation callback. A collation callback is used to
|
||||
establish a collation order, mostly for string comparisons and sorting
|
||||
purposes. C<name> is a string with the name of the collation to be created;
|
||||
C<func> is a function that accepts two string arguments, compares them
|
||||
and returns 0 if both strings are identical, -1 if the first argument is
|
||||
lower in the collation order than the second and 1 if the first argument
|
||||
is higher in the collation order than the second. A simple example:
|
||||
|
||||
local function collate(s1,s2)
|
||||
s1=s1:lower()
|
||||
s2=s2:lower()
|
||||
if s1==s2 then return 0
|
||||
elseif s1<s2 then return -1
|
||||
else return 1 end
|
||||
end
|
||||
db:exec[=[
|
||||
CREATE TABLE test(id INTEGER PRIMARY KEY,content COLLATE CINSENS);
|
||||
INSERT INTO test VALUES(NULL,'hello world');
|
||||
INSERT INTO test VALUES(NULL,'Buenos dias');
|
||||
INSERT INTO test VALUES(NULL,'HELLO WORLD');
|
||||
]=]
|
||||
db:create_collation('CINSENS',collate)
|
||||
for row in db:nrows('SELECT * FROM test') do print(row.id,row.content) end
|
||||
|
||||
=head2 db:create_function
|
||||
|
||||
db:create_function(name,nargs,func)
|
||||
|
||||
This function creates a callback function. Callback function are called
|
||||
by SQLite3 once for every row in a query. C<name> is a string with the
|
||||
name of the callback function as given in an SQL statement; C<nargs> is
|
||||
the number of arguments this call will provide. C<func> is the actual Lua
|
||||
function that gets called once for every row; it should accept a
|
||||
function context (see L</Methods for callback contexts>) plus the same
|
||||
number of parameters as given in nargs. Here is an example:
|
||||
|
||||
db:exec'CREATE TABLE test(col1,col2,col3)'
|
||||
db:exec'INSERT INTO test VALUES(1,2,4)'
|
||||
db:exec'INSERT INTO test VALUES(2,4,9)'
|
||||
db:exec'INSERT INTO test VALUES(3,6,16)'
|
||||
db:create_function('sum_cols',3,function(ctx,a,b,c)
|
||||
ctx:result_number(a+b+c)
|
||||
end))
|
||||
for col1,col2,col3,sum in db:urows('SELECT *,sum_cols(col1,col2,col3) FROM test') do
|
||||
util.printf('%2i+%2i+%2i=%2i\n',col1,col2,col3,sum)
|
||||
end
|
||||
|
||||
=head2 db:errcode
|
||||
|
||||
db:errcode()
|
||||
db:error_code()
|
||||
|
||||
Returns the numerical result code (or extended result code) for the most
|
||||
recent failed call associated with database db. See
|
||||
L</Numerical error and result codes> for details.
|
||||
|
||||
=head2 db:errmsg
|
||||
|
||||
db:errmsg()
|
||||
db:error_message()
|
||||
|
||||
Returns a string that contains an error message for the most recent
|
||||
failed call associated with database db.
|
||||
|
||||
=head2 db:exec
|
||||
|
||||
db:exec(sql[,func[,udata]])
|
||||
db:execute(sql[,func[,udata]])
|
||||
|
||||
Compiles and executes the SQL statement(s) given in string C<sql>. The
|
||||
statements are simply executed one after the other and not stored. The
|
||||
function returns C<sqlite3.OK> on success or else a numerical error code
|
||||
(see L</Numerical error and result codes>).
|
||||
|
||||
If one or more of the SQL statements are queries, then the callback
|
||||
function specified in C<func> is invoked once for each row of the query
|
||||
result (if C<func> is nil, no callback is invoked). The callback receives
|
||||
four arguments: C<udata> (the third parameter of the C<db:exec()> call),
|
||||
the number of columns in the row, a table with the column values and
|
||||
another table with the column names. The callback function should return
|
||||
0. If the callback returns a non-zero value then the query is aborted,
|
||||
all subsequent SQL statements are skipped and C<db:exec()> returns
|
||||
C<sqlite3.ABORT>. Here is a simple example:
|
||||
|
||||
sql=[=[
|
||||
CREATE TABLE numbers(num1,num2,str);
|
||||
INSERT INTO numbers VALUES(1,11,"ABC");
|
||||
INSERT INTO numbers VALUES(2,22,"DEF");
|
||||
INSERT INTO numbers VALUES(3,33,"UVW");
|
||||
INSERT INTO numbers VALUES(4,44,"XYZ");
|
||||
SELECT * FROM numbers;
|
||||
]=]
|
||||
function showrow(udata,cols,values,names)
|
||||
assert(udata=='test_udata')
|
||||
print('exec:')
|
||||
for i=1,cols do print('',names[i],values[i]) end
|
||||
return 0
|
||||
end
|
||||
db:exec(sql,showrow,'test_udata')
|
||||
|
||||
=head2 db:interrupt
|
||||
|
||||
db:interrupt()
|
||||
|
||||
This function causes any pending database operation to abort and return
|
||||
at the next opportunity. This function returns nothing.
|
||||
|
||||
=head2 db:isopen
|
||||
|
||||
db:isopen()
|
||||
|
||||
Returns true if database db is open, false otherwise.
|
||||
|
||||
=head2 db:last_insert_rowid
|
||||
|
||||
db:last_insert_rowid()
|
||||
|
||||
This function returns the rowid of the most recent INSERT into the
|
||||
database. If no inserts have ever occurred, 0 is returned. (Each row in
|
||||
an SQLite table has a unique 64-bit signed integer key called the
|
||||
'rowid'. This id is always available as an undeclared column named
|
||||
ROWID, OID, or _ROWID_. If the table has a column of type INTEGER
|
||||
PRIMARY KEY then that column is another alias for the rowid.)
|
||||
|
||||
If an INSERT occurs within a trigger, then the rowid of the inserted row
|
||||
is returned as long as the trigger is running. Once the trigger
|
||||
terminates, the value returned reverts to the last value inserted before
|
||||
the trigger fired.
|
||||
|
||||
=head2 db:nrows
|
||||
|
||||
db:nrows(sql)
|
||||
|
||||
Creates an iterator that returns the successive rows selected by the SQL
|
||||
statement given in string C<sql>. Each call to the iterator returns a
|
||||
table in which the named fields correspond to the columns in the database.
|
||||
Here is an example:
|
||||
|
||||
db:exec[=[
|
||||
CREATE TABLE numbers(num1,num2);
|
||||
INSERT INTO numbers VALUES(1,11);
|
||||
INSERT INTO numbers VALUES(2,22);
|
||||
INSERT INTO numbers VALUES(3,33);
|
||||
]=]
|
||||
for a in db:nrows('SELECT * FROM numbers') do table.print(a) end
|
||||
|
||||
This script prints:
|
||||
|
||||
num2: 11
|
||||
num1: 1
|
||||
num2: 22
|
||||
num1: 2
|
||||
num2: 33
|
||||
num1: 3
|
||||
|
||||
=head2 db:prepare
|
||||
|
||||
db:prepare(sql)
|
||||
|
||||
This function compiles the SQL statement in string C<sql> into an internal
|
||||
representation and returns this as userdata. The returned object should
|
||||
be used for all further method calls in connection with this specific
|
||||
SQL statement (see L</Methods for prepared statements>).
|
||||
|
||||
=head2 db:progress_handler
|
||||
|
||||
db:progress_handler(n,func,udata)
|
||||
|
||||
This function installs a callback function C<func> that is invoked
|
||||
periodically during long-running calls to L<C<db:exec()>|/db:exec>
|
||||
or L<C<stmt:step()>|/stmt:step>. The
|
||||
progress callback is invoked once for every C<n> internal operations,
|
||||
where C<n> is the first argument to this function. C<udata> is passed to
|
||||
the progress callback function each time it is invoked. If a call to
|
||||
C<db:exec()> or C<stmt:step()> results in fewer than C<n> operations
|
||||
being executed, then the progress callback is never invoked. Only a
|
||||
single progress callback function may be registered for each opened
|
||||
database and a call to this function will overwrite any previously set
|
||||
callback function. To remove the progress callback altogether, pass nil
|
||||
as the second argument.
|
||||
|
||||
If the progress callback returns a result other than 0, then the current
|
||||
query is immediately terminated, any database changes are rolled back
|
||||
and the containing C<db:exec()> or C<stmt:step()> call returns
|
||||
C<sqlite3.INTERRUPT>. This feature can be used to cancel long-running
|
||||
queries.
|
||||
|
||||
=head2 db:rows
|
||||
|
||||
db:rows(sql)
|
||||
|
||||
Creates an iterator that returns the successive rows selected by the SQL
|
||||
statement given in string C<sql>. Each call to the iterator returns a table
|
||||
in which the numerical indices 1 to n correspond to the selected columns
|
||||
1 to n in the database. Here is an example:
|
||||
|
||||
db:exec[=[
|
||||
CREATE TABLE numbers(num1,num2);
|
||||
INSERT INTO numbers VALUES(1,11);
|
||||
INSERT INTO numbers VALUES(2,22);
|
||||
INSERT INTO numbers VALUES(3,33);
|
||||
]=]
|
||||
for a in db:rows('SELECT * FROM numbers') do table.print(a) end
|
||||
|
||||
This script prints:
|
||||
|
||||
1: 1
|
||||
2: 11
|
||||
1: 2
|
||||
2: 22
|
||||
1: 3
|
||||
2: 33
|
||||
|
||||
=head2 db:total_changes
|
||||
|
||||
db:total_changes()
|
||||
|
||||
This function returns the number of database rows that have been
|
||||
modified by INSERT, UPDATE or DELETE statements since the database was
|
||||
opened. This includes UPDATE, INSERT and DELETE statements executed as
|
||||
part of trigger programs. All changes are counted as soon as the
|
||||
statement that produces them is completed by calling either
|
||||
L<C<stmt:reset()>|/stmt:reset> or L<C<stmt:finalize()>|/stmt:finalize>.
|
||||
|
||||
=head2 db:trace
|
||||
|
||||
db:trace(func,udata)
|
||||
|
||||
This function installs a trace callback handler. C<func> is a Lua
|
||||
function that is called by SQLite3 just before the evaluation of an SQL
|
||||
statement. This callback receives two arguments: the first is the
|
||||
C<udata> argument used when the callback was installed; the second is a
|
||||
string with the SQL statement about to be executed.
|
||||
|
||||
=head2 db:urows
|
||||
|
||||
db:urows(sql)
|
||||
|
||||
Creates an iterator that returns the successive rows selected by the SQL
|
||||
statement given in string C<sql>. Each call to the iterator returns the
|
||||
values that correspond to the columns in the currently selected row.
|
||||
Here is an example:
|
||||
|
||||
db:exec[=[
|
||||
CREATE TABLE numbers(num1,num2);
|
||||
INSERT INTO numbers VALUES(1,11);
|
||||
INSERT INTO numbers VALUES(2,22);
|
||||
INSERT INTO numbers VALUES(3,33);
|
||||
]=]
|
||||
for num1,num2 in db:urows('SELECT * FROM numbers') do print(num1,num2) end
|
||||
|
||||
This script prints:
|
||||
|
||||
1 11
|
||||
2 22
|
||||
3 33
|
||||
|
||||
=head1 Methods for prepared statements
|
||||
|
||||
After creating a prepared statement with L<C<db:prepare()>|/db:prepare>
|
||||
the returned statement object should be used for all further calls in
|
||||
connection with that statement. Statement objects support the following
|
||||
methods.
|
||||
|
||||
=head2 stmt:bind
|
||||
|
||||
stmt:bind(n[,value])
|
||||
|
||||
Binds value to statement parameter C<n>. If the type of value is string
|
||||
or number, it is bound as text or double, respectively. If C<value> is a
|
||||
boolean or nil or missing, any previous binding is removed. The function
|
||||
returns C<sqlite3.OK> on success or else a numerical error code (see
|
||||
L</Numerical error and result codes>).
|
||||
|
||||
=head2 stmt:bind_blob
|
||||
|
||||
stmt:bind_blob(n,blob)
|
||||
|
||||
Binds string C<blob> (which can be a binary string) as a blob to
|
||||
statement parameter C<n>. The function returns C<sqlite3.OK> on success
|
||||
or else a numerical error code (see L</Numerical error and result codes>).
|
||||
|
||||
=head2 stmt:bind_names
|
||||
|
||||
stmt:bind_names(nametable)
|
||||
|
||||
Binds the values in C<nametable> to statement parameters. If the
|
||||
statement parameters are named (i.e., of the form ":AAA" or "$AAA")
|
||||
then this function looks for appropriately named fields in C<nametable>;
|
||||
if the statement parameters are
|
||||
not named, it looks for numerical fields 1 to the number of statement
|
||||
parameters. The function returns C<sqlite3.OK> on success or else a
|
||||
numerical error code (see L</Numerical error and result codes>).
|
||||
|
||||
=head2 stmt:bind_parameter_count
|
||||
|
||||
stmt:bind_parameter_count()
|
||||
|
||||
Returns the largest statement parameter index in prepared statement
|
||||
C<stmt>. When the statement parameters are of the forms ":AAA" or "?",
|
||||
then they are assigned sequentially increasing numbers beginning with
|
||||
one, so the value returned is the number of parameters. However if the
|
||||
same statement parameter name is used multiple times, each occurrence
|
||||
is given the same number, so the value returned is the number of unique
|
||||
statement parameter names.
|
||||
|
||||
If statement parameters of the form "?NNN" are used (where NNN is an
|
||||
integer) then there might be gaps in the numbering and the value
|
||||
returned by this interface is the index of the statement parameter with
|
||||
the largest index value.
|
||||
|
||||
=head2 stmt:bind_parameter_name
|
||||
|
||||
stmt:bind_parameter_name(n)
|
||||
|
||||
Returns the name of the C<n>-th parameter in prepared statement C<stmt>.
|
||||
Statement parameters of the form ":AAA" or "@AAA" or "$VVV" have a name
|
||||
which is the string ":AAA" or "@AAA" or "$VVV". In other words, the
|
||||
initial ":" or "$" or "@" is included as part of the name. Parameters
|
||||
of the form "?" or "?NNN" have no name. The first bound parameter has
|
||||
an index of 1.
|
||||
If the value C<n> is out of range or if the C<n>-th parameter is
|
||||
nameless, then nil is returned. The function returns C<sqlite3.OK> on
|
||||
success or else a numerical error code (see
|
||||
L</Numerical error and result codes>)
|
||||
|
||||
=head2 stmt:bind_values
|
||||
|
||||
stmt:bind_values(value1,value2,...,valueN)
|
||||
|
||||
Binds the given values to statement parameters. The function returns
|
||||
C<sqlite3.OK> on success or else a numerical error code (see
|
||||
L</Numerical error and result codes>).
|
||||
|
||||
=head2 stmt:columns
|
||||
|
||||
stmt:columns()
|
||||
|
||||
Returns the number of columns in the result set returned by statement
|
||||
stmt or 0 if the statement does not return data (for example an UPDATE).
|
||||
|
||||
=head2 stmt:finalize
|
||||
|
||||
stmt:finalize()
|
||||
|
||||
This function frees prepared statement stmt. If the statement was
|
||||
executed successfully, or not executed at all, then C<sqlite3.OK> is
|
||||
returned. If execution of the statement failed then an error code is
|
||||
returned.
|
||||
|
||||
=head2 stmt:get_name
|
||||
|
||||
stmt:get_name(n)
|
||||
|
||||
Returns the name of column C<n> in the result set of statement stmt. (The
|
||||
left-most column is number 0.)
|
||||
|
||||
=head2 stmt:get_named_types
|
||||
|
||||
stmt:get_named_types()
|
||||
|
||||
Returns a table with the names and types of all columns in the result
|
||||
set of statement stmt.
|
||||
|
||||
=head2 stmt:get_named_values
|
||||
|
||||
stmt:get_named_values()
|
||||
|
||||
This function returns a table with names and values of all columns in
|
||||
the current result row of a query.
|
||||
|
||||
=head2 stmt:get_names
|
||||
|
||||
stmt:get_names()
|
||||
|
||||
This function returns an array with the names of all columns in the
|
||||
result set returned by statement stmt.
|
||||
|
||||
=head2 stmt:get_type
|
||||
|
||||
stmt:get_type(n)
|
||||
|
||||
Returns the type of column C<n> in the result set of statement stmt. (The
|
||||
left-most column is number 0.)
|
||||
|
||||
=head2 stmt:get_types
|
||||
|
||||
stmt:get_types()
|
||||
|
||||
This function returns an array with the types of all columns in the
|
||||
result set returned by statement stmt.
|
||||
|
||||
=head2 stmt:get_unames
|
||||
|
||||
stmt:get_unames()
|
||||
|
||||
This function returns a list with the names of all columns in the result
|
||||
set returned by statement stmt.
|
||||
|
||||
=head2 stmt:get_utypes
|
||||
|
||||
stmt:get_utypes()
|
||||
|
||||
This function returns a list with the types of all columns in the result
|
||||
set returned by statement stmt.
|
||||
|
||||
=head2 stmt:get_uvalues
|
||||
|
||||
stmt:get_uvalues()
|
||||
|
||||
This function returns a list with the values of all columns in the
|
||||
current result row of a query.
|
||||
|
||||
=head2 stmt:get_value
|
||||
|
||||
stmt:get_value(n)
|
||||
|
||||
Returns the value of column C<n> in the result set of statement stmt. (The
|
||||
left-most column is number 0.)
|
||||
|
||||
=head2 stmt:get_values
|
||||
|
||||
stmt:get_values()
|
||||
|
||||
This function returns an array with the values of all columns in the
|
||||
result set returned by statement stmt.
|
||||
|
||||
=head2 stmt:isopen
|
||||
|
||||
stmt:isopen()
|
||||
|
||||
Returns true if stmt has not yet been finalized, false otherwise.
|
||||
|
||||
=head2 stmt:nrows
|
||||
|
||||
stmt:nrows()
|
||||
|
||||
Returns an function that iterates over the names and values of the
|
||||
result set of statement C<stmt>. Each iteration returns a table with the
|
||||
names and values for the current row.
|
||||
This is the prepared statement equivalent of L<C<db:nrows()>|/db:nrows>.
|
||||
|
||||
=head2 stmt:reset
|
||||
|
||||
stmt:reset()
|
||||
|
||||
This function resets SQL statement C<stmt>, so that it is ready to be
|
||||
re-executed. Any statement variables that had values bound to them using
|
||||
the C<stmt:bind*()> functions retain their values.
|
||||
|
||||
=head2 stmt:rows
|
||||
|
||||
stmt:rows()
|
||||
|
||||
Returns an function that iterates over the values of the result set of
|
||||
statement stmt. Each iteration returns an array with the values for the
|
||||
current row.
|
||||
This is the prepared statement equivalent of L<C<db:rows()>|/db:rows>.
|
||||
|
||||
=head2 stmt:step
|
||||
|
||||
stmt:step()
|
||||
|
||||
This function must be called to evaluate the (next iteration of the)
|
||||
prepared statement stmt. It will return one of the following values:
|
||||
|
||||
=over 4
|
||||
|
||||
=item *
|
||||
|
||||
C<sqlite3.BUSY>: the engine was unable to acquire the locks needed. If the
|
||||
statement is a COMMIT or occurs outside of an explicit transaction, then
|
||||
you can retry the statement. If the statement is not a COMMIT and occurs
|
||||
within a explicit transaction then you should rollback the transaction
|
||||
before continuing.
|
||||
|
||||
=item *
|
||||
|
||||
C<sqlite3.DONE>: the statement has finished executing successfully.
|
||||
L<C<stmt:step()>|/stmt:step> should not be called again on this statement
|
||||
without first calling L<C<stmt:reset()>|/stmt:reset> to reset the virtual
|
||||
machine back to the initial state.
|
||||
|
||||
=item *
|
||||
|
||||
C<sqlite3.ROW>: this is returned each time a new row of data is ready for
|
||||
processing by the caller. The values may be accessed using the column
|
||||
access functions. L<C<stmt:step()>|/stmt:step> can be called again to
|
||||
retrieve the next row of data.
|
||||
|
||||
=item *
|
||||
|
||||
C<sqlite3.ERROR>: a run-time error (such as a constraint violation) has
|
||||
occurred. L<C<stmt:step()>|/stmt:step> should not be called again. More
|
||||
information may be found by calling L<C<db:errmsg()>|/db:errmsg>. A more
|
||||
specific error
|
||||
code (can be obtained by calling L<C<stmt:reset()>|/stmt:reset>.
|
||||
|
||||
=item *
|
||||
|
||||
C<sqlite3.MISUSE>: the function was called inappropriately, perhaps
|
||||
because the statement has already been finalized or a previous call to
|
||||
L<C<stmt:step()>|/stmt:step> has returned C<sqlite3.ERROR> or
|
||||
C<sqlite3.DONE>.
|
||||
|
||||
=back
|
||||
|
||||
=head2 stmt:urows
|
||||
|
||||
stmt:urows()
|
||||
|
||||
Returns an function that iterates over the values of the result set of
|
||||
statement stmt. Each iteration returns the values for the current row.
|
||||
This is the prepared statement equivalent of L<C<db:urows()>|/db:urows>.
|
||||
|
||||
=head1 Methods for callback contexts
|
||||
|
||||
A callback context is available as a parameter inside the callback
|
||||
functions L<C<db:create_aggregate()>|/db:create_aggregate> and
|
||||
L<C<db:create_function()>|/db:create_function>. It can be used
|
||||
to get further information about the state of a query.
|
||||
|
||||
=head2 context:aggregate_count
|
||||
|
||||
context:aggregate_count()
|
||||
|
||||
Returns the number of calls to the aggregate step function.
|
||||
|
||||
=head2 context:get_aggregate_data
|
||||
|
||||
context:get_aggregate_data()
|
||||
|
||||
Returns the user-definable data field for callback funtions.
|
||||
|
||||
=head2 context:set_aggregate_data
|
||||
|
||||
context:set_aggregate_data(udata)
|
||||
|
||||
Set the user-definable data field for callback funtions to C<udata>.
|
||||
|
||||
=head2 context:result
|
||||
|
||||
context:result(res)
|
||||
|
||||
This function sets the result of a callback function to res. The type of
|
||||
the result depends on the type of res and is either a number or a string
|
||||
or nil. All other values will raise an error message.
|
||||
|
||||
=head2 context:result_null
|
||||
|
||||
context:result_null()
|
||||
|
||||
This function sets the result of a callback function to nil. It returns
|
||||
nothing.
|
||||
|
||||
=head2 context:result_number
|
||||
|
||||
context:result_number(number)
|
||||
context:result_double(number)
|
||||
|
||||
This function sets the result of a callback function to the value
|
||||
C<number>. It returns nothing.
|
||||
|
||||
=head2 context:result_int
|
||||
|
||||
context:result_int(number)
|
||||
|
||||
This function sets the result of a callback function to the integer
|
||||
value in C<number>. It returns nothing.
|
||||
|
||||
=head2 context:result_text
|
||||
|
||||
context:result_text(str)
|
||||
|
||||
This function sets the result of a callback function to the string in
|
||||
C<str>. It returns nothing.
|
||||
|
||||
=head2 context:result_blob
|
||||
|
||||
context:result_blob(blob)
|
||||
|
||||
This function sets the result of a callback function to the binary
|
||||
string in C<blob>. It returns nothing.
|
||||
|
||||
=head2 context:result_error
|
||||
|
||||
context:result_error(err)
|
||||
|
||||
This function sets the result of a callback function to the error value
|
||||
in C<err>. It returns nothing.
|
||||
|
||||
=head2 context:user_data
|
||||
|
||||
context:user_data()
|
||||
|
||||
Returns the userdata parameter given in the call to install the callback
|
||||
function (see L<C<db:create_aggregate()>|/db:create_aggregate> and
|
||||
L<C<db:create_function()>|/db:create_function> for details).
|
||||
|
||||
=head1 Numerical error and result codes
|
||||
|
||||
The following constants are defined by module sqlite3:
|
||||
|
||||
OK: 0 ERROR: 1 INTERNAL: 2 PERM: 3 ABORT: 4
|
||||
BUSY: 5 LOCKED: 6 NOMEM: 7 READONLY: 8 INTERRUPT: 9
|
||||
IOERR: 10 CORRUPT: 11 NOTFOUND: 12 FULL: 13 CANTOPEN: 14
|
||||
PROTOCOL: 15 EMPTY: 16 SCHEMA: 17 TOOBIG: 18 CONSTRAINT: 19
|
||||
MISMATCH: 20 MISUSE: 21 NOLFS: 22 FORMAT: 24 RANGE: 25
|
||||
NOTADB: 26 ROW: 100 DONE: 101
|
||||
|
||||
For details about their exact meaning please see the B<SQLite3
|
||||
documentation> L<http://www.sqlite.org/>.
|
||||
|
||||
=head1 VERSION
|
||||
|
||||
This is C<lsqlite3> subversion 6, also known as "devel-0.6".
|
||||
|
||||
=head1 CREDITS
|
||||
|
||||
C<lsqlite3> was developed by Tiago Dionizio and Doug Currie with
|
||||
contributions from Thomas Lauer and Michael Roth.
|
||||
|
||||
This documentation is based on the "(very) preliminary" documents
|
||||
for the Idle-SQLite3 database module. Thanks to Thomas Lauer for
|
||||
making it available.
|
||||
|
||||
=head1 LICENSE
|
||||
|
||||
/************************************************************************
|
||||
* lsqlite3 *
|
||||
* Copyright (C) 2002-2007 Tiago Dionizio, Doug Currie *
|
||||
* All rights reserved. *
|
||||
* Author : Tiago Dionizio <tiago.dionizio@ist.utl.pt> *
|
||||
* Author : Doug Currie <doug.currie@alum.mit.edu> *
|
||||
* Library : lsqlite3 - a SQLite 3 database binding for Lua 5 *
|
||||
* *
|
||||
* 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. *
|
||||
************************************************************************/
|
||||
|
7
3rdparty/lsqlite3/doc/pod2html.pl
vendored
7
3rdparty/lsqlite3/doc/pod2html.pl
vendored
@ -1,7 +0,0 @@
|
||||
#!perl
|
||||
|
||||
use Pod::Html;
|
||||
|
||||
pod2html @ARGV;
|
||||
|
||||
__END__
|
35
3rdparty/lsqlite3/examples/aggregate.lua
vendored
35
3rdparty/lsqlite3/examples/aggregate.lua
vendored
@ -1,35 +0,0 @@
|
||||
|
||||
require("lsqlite3")
|
||||
|
||||
local db = sqlite3.open_memory()
|
||||
|
||||
assert( db:exec "CREATE TABLE test (col1, col2)" )
|
||||
assert( db:exec "INSERT INTO test VALUES (1, 2)" )
|
||||
assert( db:exec "INSERT INTO test VALUES (2, 4)" )
|
||||
assert( db:exec "INSERT INTO test VALUES (3, 6)" )
|
||||
assert( db:exec "INSERT INTO test VALUES (4, 8)" )
|
||||
assert( db:exec "INSERT INTO test VALUES (5, 10)" )
|
||||
|
||||
do
|
||||
|
||||
local square_error_sum = 0
|
||||
|
||||
local function step(ctx, a, b)
|
||||
local error = a - b
|
||||
local square_error = error * error
|
||||
square_error_sum = square_error_sum + square_error
|
||||
end
|
||||
|
||||
local function final(ctx)
|
||||
ctx:result_number( square_error_sum / ctx:aggregate_count() )
|
||||
end
|
||||
|
||||
assert( db:create_aggregate("my_stats", 2, step, final) )
|
||||
|
||||
end
|
||||
|
||||
--for a,b in db:urows("SELECT col1, col2 FROM test")
|
||||
--do print("a b: ", a, b) end
|
||||
|
||||
for my_stats in db:urows("SELECT my_stats(col1, col2) FROM test")
|
||||
do print("my_stats:", my_stats) end
|
21
3rdparty/lsqlite3/examples/function.lua
vendored
21
3rdparty/lsqlite3/examples/function.lua
vendored
@ -1,21 +0,0 @@
|
||||
|
||||
require("lsqlite3")
|
||||
|
||||
|
||||
local db = sqlite3.open_memory()
|
||||
|
||||
assert( db:exec "CREATE TABLE test (col1, col2)" )
|
||||
assert( db:exec "INSERT INTO test VALUES (1, 2)" )
|
||||
assert( db:exec "INSERT INTO test VALUES (2, 4)" )
|
||||
assert( db:exec "INSERT INTO test VALUES (3, 6)" )
|
||||
assert( db:exec "INSERT INTO test VALUES (4, 8)" )
|
||||
assert( db:exec "INSERT INTO test VALUES (5, 10)" )
|
||||
|
||||
assert( db:create_function("my_sum", 2, function(ctx, a, b)
|
||||
ctx:result_number( a + b )
|
||||
end))
|
||||
|
||||
|
||||
for col1, col2, sum in db:urows("SELECT *, my_sum(col1, col2) FROM test") do
|
||||
print(col1, col2, sum)
|
||||
end
|
122
3rdparty/lsqlite3/examples/order.lua
vendored
122
3rdparty/lsqlite3/examples/order.lua
vendored
@ -1,122 +0,0 @@
|
||||
|
||||
require("lsqlite3")
|
||||
|
||||
local db = assert( sqlite3:open_memory() )
|
||||
|
||||
assert( db:exec[[
|
||||
|
||||
CREATE TABLE customer (
|
||||
id INTEGER PRIMARY KEY,
|
||||
name VARCHAR(40)
|
||||
);
|
||||
|
||||
CREATE TABLE invoice (
|
||||
id INTEGER PRIMARY KEY,
|
||||
customer INTEGER NOT NULL,
|
||||
title VARCHAR(80) NOT NULL,
|
||||
article1 VARCHAR(40) NOT NULL,
|
||||
price1 REAL NOT NULL,
|
||||
article2 VARCHAR(40),
|
||||
price2 REAL
|
||||
);
|
||||
|
||||
CREATE TABLE invoice_overflow (
|
||||
id INTEGER PRIMARY KEY,
|
||||
invoice INTEGER NOT NULL,
|
||||
article VARCHAR(40) NOT NULL,
|
||||
price REAL NOT NULL
|
||||
);
|
||||
|
||||
INSERT INTO customer VALUES(
|
||||
1, "Michael" );
|
||||
|
||||
INSERT INTO invoice VALUES(
|
||||
1, 1, "Computer parts", "harddisc", 89.90, "floppy", 9.99 );
|
||||
|
||||
INSERT INTO customer VALUES(
|
||||
2, "John" );
|
||||
|
||||
INSERT INTO invoice VALUES(
|
||||
2, 2, "Somme food", "apples", 2.79, "pears", 5.99 );
|
||||
|
||||
INSERT INTO invoice_overflow VALUES(
|
||||
NULL, 2, "grapes", 6.34 );
|
||||
|
||||
INSERT INTO invoice_overflow VALUES(
|
||||
NULL, 2, "strawberries", 4.12 );
|
||||
|
||||
INSERT INTO invoice_overflow VALUES(
|
||||
NULL, 2, "tomatoes", 6.17 );
|
||||
|
||||
INSERT INTO invoice VALUES(
|
||||
3, 2, "A new car", "Cybercar XL-1000", 65000.00, NULL, NULL );
|
||||
|
||||
]] )
|
||||
|
||||
|
||||
local function customer_name(id)
|
||||
local stmt = db:prepare("SELECT name FROM customer WHERE id = ?")
|
||||
stmt:bind_values(id)
|
||||
stmt:step()
|
||||
local r = stmt:get_uvalues()
|
||||
stmt:finalize()
|
||||
return r
|
||||
end
|
||||
|
||||
|
||||
local function all_invoices()
|
||||
return db:nrows("SELECT id, customer, title FROM invoice")
|
||||
end
|
||||
|
||||
|
||||
local function all_articles(invoice)
|
||||
|
||||
local function iterator()
|
||||
local stmt, row
|
||||
|
||||
-- Get the articles that are contained in the invoice table itself.
|
||||
stmt = db:prepare("SELECT article1, price1, article2, price2 FROM invoice WHERE id = ?")
|
||||
stmt:bind_values(invoice)
|
||||
stmt:step()
|
||||
row = stmt:get_named_values()
|
||||
|
||||
-- Every Invoice has at least one article.
|
||||
coroutine.yield(row.article1, row.price1)
|
||||
|
||||
-- Maybe the Invoice has a second article?
|
||||
if row.article2 then
|
||||
|
||||
-- Yes, there is a second article, so return it.
|
||||
coroutine.yield(row.article2, row.price2)
|
||||
|
||||
-- When there was an second article, maybe there are even
|
||||
-- more articles in the overflow table? We will see...
|
||||
|
||||
stmt = db:prepare("SELECT article, price FROM invoice_overflow WHERE invoice = ? ORDER BY id")
|
||||
stmt:bind_values(invoice)
|
||||
|
||||
for row in stmt:nrows() do
|
||||
coroutine.yield(row.article, row.price)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return coroutine.wrap(iterator)
|
||||
end
|
||||
|
||||
|
||||
for invoice in all_invoices() do
|
||||
local id = invoice.id
|
||||
local name = customer_name(invoice.customer)
|
||||
local title = invoice.title
|
||||
|
||||
print()
|
||||
print("Invoice #"..id..", "..name..": '"..title.."'")
|
||||
print("----------------------------------------")
|
||||
|
||||
for article, price in all_articles(id) do
|
||||
print( string.format("%20s %8.2f", article, price) )
|
||||
end
|
||||
|
||||
print()
|
||||
end
|
16
3rdparty/lsqlite3/examples/simple.lua
vendored
16
3rdparty/lsqlite3/examples/simple.lua
vendored
@ -1,16 +0,0 @@
|
||||
|
||||
require("lsqlite3")
|
||||
|
||||
local db = sqlite3.open_memory()
|
||||
|
||||
db:exec[[
|
||||
CREATE TABLE test (id INTEGER PRIMARY KEY, content);
|
||||
|
||||
INSERT INTO test VALUES (NULL, 'Hello World');
|
||||
INSERT INTO test VALUES (NULL, 'Hello Lua');
|
||||
INSERT INTO test VALUES (NULL, 'Hello Sqlite3')
|
||||
]]
|
||||
|
||||
for row in db:nrows("SELECT * FROM test") do
|
||||
print(row.id, row.content)
|
||||
end
|
22
3rdparty/lsqlite3/examples/smart.lua
vendored
22
3rdparty/lsqlite3/examples/smart.lua
vendored
@ -1,22 +0,0 @@
|
||||
|
||||
require("lsqlite3")
|
||||
|
||||
local db = sqlite3.open_memory()
|
||||
|
||||
db:exec[[ CREATE TABLE test (id INTEGER PRIMARY KEY, content) ]]
|
||||
|
||||
local stmt = db:prepare[[ INSERT INTO test VALUES (:key, :value) ]]
|
||||
|
||||
stmt:bind_names{ key = 1, value = "Hello World" }
|
||||
stmt:step()
|
||||
stmt:reset()
|
||||
stmt:bind_names{ key = 2, value = "Hello Lua" }
|
||||
stmt:step()
|
||||
stmt:reset()
|
||||
stmt:bind_names{ key = 3, value = "Hello Sqlite3" }
|
||||
stmt:step()
|
||||
stmt:finalize()
|
||||
|
||||
for row in db:nrows("SELECT * FROM test") do
|
||||
print(row.id, row.content)
|
||||
end
|
39
3rdparty/lsqlite3/examples/statement.lua
vendored
39
3rdparty/lsqlite3/examples/statement.lua
vendored
@ -1,39 +0,0 @@
|
||||
|
||||
require("lsqlite3")
|
||||
|
||||
local db = sqlite3.open_memory()
|
||||
|
||||
db:exec[[
|
||||
CREATE TABLE test (
|
||||
id INTEGER PRIMARY KEY,
|
||||
content VARCHAR
|
||||
);
|
||||
]]
|
||||
|
||||
local insert_stmt = assert( db:prepare("INSERT INTO test VALUES (NULL, ?)") )
|
||||
|
||||
local function insert(data)
|
||||
insert_stmt:bind_values(data)
|
||||
insert_stmt:step()
|
||||
insert_stmt:reset()
|
||||
end
|
||||
|
||||
local select_stmt = assert( db:prepare("SELECT * FROM test") )
|
||||
|
||||
local function select()
|
||||
for row in select_stmt:nrows() do
|
||||
print(row.id, row.content)
|
||||
end
|
||||
end
|
||||
|
||||
insert("Hello World")
|
||||
print("First:")
|
||||
select()
|
||||
|
||||
insert("Hello Lua")
|
||||
print("Second:")
|
||||
select()
|
||||
|
||||
insert("Hello Sqlite3")
|
||||
print("Third:")
|
||||
select()
|
20
3rdparty/lsqlite3/examples/tracing.lua
vendored
20
3rdparty/lsqlite3/examples/tracing.lua
vendored
@ -1,20 +0,0 @@
|
||||
|
||||
require("lsqlite3")
|
||||
|
||||
local db = sqlite3.open_memory()
|
||||
|
||||
db:trace( function(ud, sql)
|
||||
print("Sqlite Trace:", sql)
|
||||
end )
|
||||
|
||||
db:exec[[
|
||||
CREATE TABLE test ( id INTEGER PRIMARY KEY, content VARCHAR );
|
||||
|
||||
INSERT INTO test VALUES (NULL, 'Hello World');
|
||||
INSERT INTO test VALUES (NULL, 'Hello Lua');
|
||||
INSERT INTO test VALUES (NULL, 'Hello Sqlite3');
|
||||
]]
|
||||
|
||||
for row in db:rows("SELECT * FROM test") do
|
||||
-- NOP
|
||||
end
|
2157
3rdparty/lsqlite3/lsqlite3.c
vendored
2157
3rdparty/lsqlite3/lsqlite3.c
vendored
File diff suppressed because it is too large
Load Diff
2
3rdparty/lsqlite3/lsqlite3.def
vendored
2
3rdparty/lsqlite3/lsqlite3.def
vendored
@ -1,2 +0,0 @@
|
||||
EXPORTS
|
||||
luaopen_lsqlite3
|
693
3rdparty/lsqlite3/lunit.lua
vendored
693
3rdparty/lsqlite3/lunit.lua
vendored
@ -1,693 +0,0 @@
|
||||
|
||||
--[[--------------------------------------------------------------------------
|
||||
|
||||
This file is part of lunit 0.4pre (alpha).
|
||||
|
||||
For Details about lunit look at: http://www.nessie.de/mroth/lunit/
|
||||
|
||||
Author: Michael Roth <mroth@nessie.de>
|
||||
|
||||
Copyright (c) 2004 Michael Roth <mroth@nessie.de>
|
||||
|
||||
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.
|
||||
|
||||
--]]--------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
|
||||
-----------------------
|
||||
-- Intialize package --
|
||||
-----------------------
|
||||
|
||||
local P = { }
|
||||
lunit = P
|
||||
|
||||
-- Import
|
||||
local type = type
|
||||
local print = print
|
||||
local ipairs = ipairs
|
||||
local pairs = pairs
|
||||
local string = string
|
||||
local table = table
|
||||
local pcall = pcall
|
||||
local xpcall = xpcall
|
||||
local traceback = debug.traceback
|
||||
local error = error
|
||||
local setmetatable = setmetatable
|
||||
local rawset = rawset
|
||||
local orig_assert = assert
|
||||
local getfenv = getfenv
|
||||
local setfenv = setfenv
|
||||
local tostring = tostring
|
||||
|
||||
|
||||
-- Start package scope
|
||||
setfenv(1, P)
|
||||
|
||||
|
||||
|
||||
|
||||
--------------------------------
|
||||
-- Private data and functions --
|
||||
--------------------------------
|
||||
|
||||
local run_testcase
|
||||
local do_assert, check_msg
|
||||
local stats = { }
|
||||
local testcases = { }
|
||||
local stats_inc, tc_mt
|
||||
|
||||
|
||||
|
||||
|
||||
--------------------------
|
||||
-- Type check functions --
|
||||
--------------------------
|
||||
|
||||
function is_nil(x)
|
||||
return type(x) == "nil"
|
||||
end
|
||||
|
||||
function is_boolean(x)
|
||||
return type(x) == "boolean"
|
||||
end
|
||||
|
||||
function is_number(x)
|
||||
return type(x) == "number"
|
||||
end
|
||||
|
||||
function is_string(x)
|
||||
return type(x) == "string"
|
||||
end
|
||||
|
||||
function is_table(x)
|
||||
return type(x) == "table"
|
||||
end
|
||||
|
||||
function is_function(x)
|
||||
return type(x) == "function"
|
||||
end
|
||||
|
||||
function is_thread(x)
|
||||
return type(x) == "thread"
|
||||
end
|
||||
|
||||
function is_userdata(x)
|
||||
return type(x) == "userdata"
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
----------------------
|
||||
-- Assert functions --
|
||||
----------------------
|
||||
|
||||
function assert(assertion, msg)
|
||||
stats_inc("assertions")
|
||||
check_msg("assert", msg)
|
||||
do_assert(not not assertion, "assertion failed (was: "..tostring(assertion)..")", msg) -- (convert assertion to bool)
|
||||
return assertion
|
||||
end
|
||||
|
||||
|
||||
function assert_fail(msg)
|
||||
stats_inc("assertions")
|
||||
check_msg("assert_fail", msg)
|
||||
do_assert(false, "failure", msg)
|
||||
end
|
||||
|
||||
|
||||
function assert_true(actual, msg)
|
||||
stats_inc("assertions")
|
||||
check_msg("assert_true", msg)
|
||||
do_assert(is_boolean(actual), "true expected but was a "..type(actual), msg)
|
||||
do_assert(actual == true, "true expected but was false", msg)
|
||||
return actual
|
||||
end
|
||||
|
||||
|
||||
function assert_false(actual, msg)
|
||||
stats_inc("assertions")
|
||||
check_msg("assert_false", msg)
|
||||
do_assert(is_boolean(actual), "false expected but was a "..type(actual), msg)
|
||||
do_assert(actual == false, "false expected but was true", msg)
|
||||
return actual
|
||||
end
|
||||
|
||||
|
||||
function assert_equal(expected, actual, msg)
|
||||
stats_inc("assertions")
|
||||
check_msg("assert_equal", msg)
|
||||
do_assert(expected == actual, "expected '"..tostring(expected).."' but was '"..tostring(actual).."'", msg)
|
||||
return actual
|
||||
end
|
||||
|
||||
|
||||
function assert_not_equal(unexpected, actual, msg)
|
||||
stats_inc("assertions")
|
||||
check_msg("assert_not_equal", msg)
|
||||
do_assert(unexpected ~= actual, "'"..tostring(expected).."' not expected but was one", msg)
|
||||
return actual
|
||||
end
|
||||
|
||||
|
||||
function assert_match(pattern, actual, msg)
|
||||
stats_inc("assertions")
|
||||
check_msg("assert_match", msg)
|
||||
do_assert(is_string(pattern), "assert_match expects the pattern as a string")
|
||||
do_assert(is_string(actual), "expected a string to match pattern '"..pattern.."' but was a '"..type(actual).."'", msg)
|
||||
do_assert(not not string.find(actual, pattern), "expected '"..actual.."' to match pattern '"..pattern.."' but doesn't", msg)
|
||||
return actual
|
||||
end
|
||||
|
||||
|
||||
function assert_not_match(pattern, actual, msg)
|
||||
stats_inc("assertions")
|
||||
check_msg("assert_not_match", msg)
|
||||
do_assert(is_string(actual), "expected a string to not match pattern '"..pattern.."' but was a '"..type(actual).."'", msg)
|
||||
do_assert(string.find(actual, pattern) == nil, "expected '"..actual.."' to not match pattern '"..pattern.."' but it does", msg)
|
||||
return actual
|
||||
end
|
||||
|
||||
|
||||
function assert_nil(actual, msg)
|
||||
stats_inc("assertions")
|
||||
check_msg("assert_nil", msg)
|
||||
do_assert(is_nil(actual), "nil expected but was a "..type(actual), msg)
|
||||
return actual
|
||||
end
|
||||
|
||||
|
||||
function assert_not_nil(actual, msg)
|
||||
stats_inc("assertions")
|
||||
check_msg("assert_not_nil", msg)
|
||||
do_assert(not is_nil(actual), "nil not expected but was one", msg)
|
||||
return actual
|
||||
end
|
||||
|
||||
|
||||
function assert_boolean(actual, msg)
|
||||
stats_inc("assertions")
|
||||
check_msg("assert_boolean", msg)
|
||||
do_assert(is_boolean(actual), "boolean expected but was a "..type(actual), msg)
|
||||
return actual
|
||||
end
|
||||
|
||||
|
||||
function assert_not_boolean(actual, msg)
|
||||
stats_inc("assertions")
|
||||
check_msg("assert_not_boolean", msg)
|
||||
do_assert(not is_boolean(actual), "boolean not expected but was one", msg)
|
||||
return actual
|
||||
end
|
||||
|
||||
|
||||
function assert_number(actual, msg)
|
||||
stats_inc("assertions")
|
||||
check_msg("assert_number", msg)
|
||||
do_assert(is_number(actual), "number expected but was a "..type(actual), msg)
|
||||
return actual
|
||||
end
|
||||
|
||||
|
||||
function assert_not_number(actual, msg)
|
||||
stats_inc("assertions")
|
||||
check_msg("assert_not_number", msg)
|
||||
do_assert(not is_number(actual), "number not expected but was one", msg)
|
||||
return actual
|
||||
end
|
||||
|
||||
|
||||
function assert_string(actual, msg)
|
||||
stats_inc("assertions")
|
||||
check_msg("assert_string", msg)
|
||||
do_assert(is_string(actual), "string expected but was a "..type(actual), msg)
|
||||
return actual
|
||||
end
|
||||
|
||||
|
||||
function assert_not_string(actual, msg)
|
||||
stats_inc("assertions")
|
||||
check_msg("assert_not_string", msg)
|
||||
do_assert(not is_string(actual), "string not expected but was one", msg)
|
||||
return actual
|
||||
end
|
||||
|
||||
|
||||
function assert_table(actual, msg)
|
||||
stats_inc("assertions")
|
||||
check_msg("assert_table", msg)
|
||||
do_assert(is_table(actual), "table expected but was a "..type(actual), msg)
|
||||
return actual
|
||||
end
|
||||
|
||||
|
||||
function assert_not_table(actual, msg)
|
||||
stats_inc("assertions")
|
||||
check_msg("assert_not_table", msg)
|
||||
do_assert(not is_table(actual), "table not expected but was one", msg)
|
||||
return actual
|
||||
end
|
||||
|
||||
|
||||
function assert_function(actual, msg)
|
||||
stats_inc("assertions")
|
||||
check_msg("assert_function", msg)
|
||||
do_assert(is_function(actual), "function expected but was a "..type(actual), msg)
|
||||
return actual
|
||||
end
|
||||
|
||||
|
||||
function assert_not_function(actual, msg)
|
||||
stats_inc("assertions")
|
||||
check_msg("assert_not_function", msg)
|
||||
do_assert(not is_function(actual), "function not expected but was one", msg)
|
||||
return actual
|
||||
end
|
||||
|
||||
|
||||
function assert_thread(actual, msg)
|
||||
stats_inc("assertions")
|
||||
check_msg("assert_thread", msg)
|
||||
do_assert(is_thread(actual), "thread expected but was a "..type(actual), msg)
|
||||
return actual
|
||||
end
|
||||
|
||||
|
||||
function assert_not_thread(actual, msg)
|
||||
stats_inc("assertions")
|
||||
check_msg("assert_not_thread", msg)
|
||||
do_assert(not is_thread(actual), "thread not expected but was one", msg)
|
||||
return actual
|
||||
end
|
||||
|
||||
|
||||
function assert_userdata(actual, msg)
|
||||
stats_inc("assertions")
|
||||
check_msg("assert_userdata", msg)
|
||||
do_assert(is_userdata(actual), "userdata expected but was a "..type(actual), msg)
|
||||
return actual
|
||||
end
|
||||
|
||||
|
||||
function assert_not_userdata(actual, msg)
|
||||
stats_inc("assertions")
|
||||
check_msg("assert_not_userdata", msg)
|
||||
do_assert(not is_userdata(actual), "userdata not expected but was one", msg)
|
||||
return actual
|
||||
end
|
||||
|
||||
|
||||
function assert_error(msg, func)
|
||||
stats_inc("assertions")
|
||||
if is_nil(func) then func, msg = msg, nil end
|
||||
check_msg("assert_error", msg)
|
||||
do_assert(is_function(func), "assert_error expects a function as the last argument but it was a "..type(func))
|
||||
local ok, errmsg = pcall(func)
|
||||
do_assert(ok == false, "error expected but no error occurred", msg)
|
||||
end
|
||||
|
||||
|
||||
function assert_pass(msg, func)
|
||||
stats_inc("assertions")
|
||||
if is_nil(func) then func, msg = msg, nil end
|
||||
check_msg("assert_pass", msg)
|
||||
do_assert(is_function(func), "assert_pass expects a function as the last argument but it was a "..type(func))
|
||||
local ok, errmsg = pcall(func)
|
||||
if not ok then do_assert(ok == true, "no error expected but error was: "..errmsg, msg) end
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
-----------------------------------------------------------
|
||||
-- Assert implementation that assumes it was called from --
|
||||
-- lunit code which was called directly from user code. --
|
||||
-----------------------------------------------------------
|
||||
|
||||
function do_assert(assertion, base_msg, user_msg)
|
||||
orig_assert(is_boolean(assertion))
|
||||
orig_assert(is_string(base_msg))
|
||||
orig_assert(is_string(user_msg) or is_nil(user_msg))
|
||||
if not assertion then
|
||||
if user_msg then
|
||||
error(base_msg..": "..user_msg, 3)
|
||||
else
|
||||
error(base_msg.."!", 3)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-------------------------------------------
|
||||
-- Checks the msg argument in assert_xxx --
|
||||
-------------------------------------------
|
||||
|
||||
function check_msg(name, msg)
|
||||
orig_assert(is_string(name))
|
||||
if not (is_nil(msg) or is_string(msg)) then
|
||||
error("lunit."..name.."() expects the optional message as a string but it was a "..type(msg).."!" ,3)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
-------------------------------------
|
||||
-- Creates a new TestCase 'Object' --
|
||||
-------------------------------------
|
||||
|
||||
function TestCase(name)
|
||||
do_assert(is_string(name), "lunit.TestCase() needs a string as an argument")
|
||||
local tc = {
|
||||
__lunit_name = name;
|
||||
__lunit_setup = nil;
|
||||
__lunit_tests = { };
|
||||
__lunit_teardown = nil;
|
||||
}
|
||||
setmetatable(tc, tc_mt)
|
||||
table.insert(testcases, tc)
|
||||
return tc
|
||||
end
|
||||
|
||||
tc_mt = {
|
||||
__newindex = function(tc, key, value)
|
||||
rawset(tc, key, value)
|
||||
if is_string(key) and is_function(value) then
|
||||
local name = string.lower(key)
|
||||
if string.find(name, "^test") or string.find(name, "test$") then
|
||||
table.insert(tc.__lunit_tests, key)
|
||||
elseif name == "setup" then
|
||||
tc.__lunit_setup = value
|
||||
elseif name == "teardown" then
|
||||
tc.__lunit_teardown = value
|
||||
end
|
||||
end
|
||||
end
|
||||
}
|
||||
|
||||
|
||||
|
||||
-----------------------------------------
|
||||
-- Wrap Functions in a TestCase object --
|
||||
-----------------------------------------
|
||||
|
||||
function wrap(name, ...)
|
||||
if is_function(name) then
|
||||
table.insert({...}, 1, name)
|
||||
name = "Anonymous Testcase"
|
||||
end
|
||||
|
||||
local tc = TestCase(name)
|
||||
for index, test in ipairs({...}) do
|
||||
tc["Test #"..index] = test
|
||||
end
|
||||
return tc
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
----------------------------------
|
||||
-- Runs the complete Test Suite --
|
||||
----------------------------------
|
||||
|
||||
function run()
|
||||
|
||||
---------------------------
|
||||
-- Initialize statistics --
|
||||
---------------------------
|
||||
|
||||
stats.testcases = 0 -- Total number of Test Cases
|
||||
stats.tests = 0 -- Total number of all Tests in all Test Cases
|
||||
stats.run = 0 -- Number of Tests run
|
||||
stats.notrun = 0 -- Number of Tests not run
|
||||
stats.failed = 0 -- Number of Tests failed
|
||||
stats.warnings = 0 -- Number of Warnings (teardown)
|
||||
stats.errors = 0 -- Number of Errors (setup)
|
||||
stats.passed = 0 -- Number of Test passed
|
||||
stats.assertions = 0 -- Number of all assertions made in all Test in all Test Cases
|
||||
|
||||
--------------------------------
|
||||
-- Count Test Cases and Tests --
|
||||
--------------------------------
|
||||
|
||||
stats.testcases = table.getn(testcases)
|
||||
|
||||
for _, tc in ipairs(testcases) do
|
||||
stats_inc("tests" , table.getn(tc.__lunit_tests))
|
||||
end
|
||||
|
||||
------------------
|
||||
-- Print Header --
|
||||
------------------
|
||||
|
||||
print()
|
||||
print("#### Test Suite with "..stats.tests.." Tests in "..stats.testcases.." Test Cases loaded.")
|
||||
|
||||
------------------------
|
||||
-- Run all Test Cases --
|
||||
------------------------
|
||||
|
||||
for _, tc in ipairs(testcases) do
|
||||
run_testcase(tc)
|
||||
end
|
||||
|
||||
------------------
|
||||
-- Print Footer --
|
||||
------------------
|
||||
|
||||
print()
|
||||
print("#### Test Suite finished.")
|
||||
|
||||
local msg_assertions = stats.assertions.." Assertions checked. "
|
||||
local msg_passed = stats.passed == stats.tests and "All Tests passed" or stats.passed.." Tests passed"
|
||||
local msg_failed = stats.failed > 0 and ", "..stats.failed.." failed" or ""
|
||||
local msg_run = stats.notrun > 0 and ", "..stats.notrun.." not run" or ""
|
||||
local msg_warn = stats.warnings > 0 and ", "..stats.warnings.." warnings" or ""
|
||||
|
||||
print()
|
||||
print(msg_assertions..msg_passed..msg_failed..msg_run..msg_warn.."!")
|
||||
|
||||
-----------------
|
||||
-- Return code --
|
||||
-----------------
|
||||
|
||||
if stats.passed == stats.tests then
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
-----------------------------
|
||||
-- Runs a single Test Case --
|
||||
-----------------------------
|
||||
|
||||
function run_testcase(tc)
|
||||
|
||||
orig_assert(is_table(tc))
|
||||
orig_assert(is_table(tc.__lunit_tests))
|
||||
orig_assert(is_string(tc.__lunit_name))
|
||||
orig_assert(is_nil(tc.__lunit_setup) or is_function(tc.__lunit_setup))
|
||||
orig_assert(is_nil(tc.__lunit_teardown) or is_function(tc.__lunit_teardown))
|
||||
|
||||
----------------------------------
|
||||
-- Protected call to a function --
|
||||
----------------------------------
|
||||
|
||||
local function call(errprefix, func)
|
||||
orig_assert(is_string(errprefix))
|
||||
orig_assert(is_function(func))
|
||||
local ok, errmsg = xpcall(function() func(tc) end, traceback)
|
||||
if not ok then
|
||||
print()
|
||||
print(errprefix..": "..errmsg)
|
||||
end
|
||||
return ok
|
||||
end
|
||||
|
||||
------------------------------------
|
||||
-- Calls setup() on the Test Case --
|
||||
------------------------------------
|
||||
|
||||
local function setup(testname)
|
||||
if tc.__lunit_setup then
|
||||
return call("ERROR: "..testname..": setup() failed", tc.__lunit_setup)
|
||||
else
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
------------------------------------------
|
||||
-- Calls a single Test on the Test Case --
|
||||
------------------------------------------
|
||||
|
||||
local function run(testname)
|
||||
orig_assert(is_string(testname))
|
||||
orig_assert(is_function(tc[testname]))
|
||||
local ok = call("FAIL: "..testname, tc[testname])
|
||||
if not ok then
|
||||
stats_inc("failed")
|
||||
else
|
||||
stats_inc("passed")
|
||||
end
|
||||
return ok
|
||||
end
|
||||
|
||||
---------------------------------------
|
||||
-- Calls teardown() on the Test Case --
|
||||
---------------------------------------
|
||||
|
||||
local function teardown(testname)
|
||||
if tc.__lunit_teardown then
|
||||
if not call("WARNING: "..testname..": teardown() failed", tc.__lunit_teardown) then
|
||||
stats_inc("warnings")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
---------------------------------
|
||||
-- Run all Tests on a TestCase --
|
||||
---------------------------------
|
||||
|
||||
print()
|
||||
print("#### Running '"..tc.__lunit_name.."' ("..table.getn(tc.__lunit_tests).." Tests)...")
|
||||
|
||||
for _, testname in ipairs(tc.__lunit_tests) do
|
||||
if setup(testname) then
|
||||
run(testname)
|
||||
stats_inc("run")
|
||||
teardown(testname)
|
||||
else
|
||||
print("WARN: Skipping '"..testname.."'...")
|
||||
stats_inc("notrun")
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
---------------------
|
||||
-- Import function --
|
||||
---------------------
|
||||
|
||||
function import(name)
|
||||
|
||||
do_assert(is_string(name), "lunit.import() expects a single string as argument")
|
||||
|
||||
local user_env = getfenv(2)
|
||||
|
||||
--------------------------------------------------
|
||||
-- Installs a specific function in the user env --
|
||||
--------------------------------------------------
|
||||
|
||||
local function install(funcname)
|
||||
user_env[funcname] = P[funcname]
|
||||
end
|
||||
|
||||
|
||||
----------------------------------------------------------
|
||||
-- Install functions matching a pattern in the user env --
|
||||
----------------------------------------------------------
|
||||
|
||||
local function install_pattern(pattern)
|
||||
for funcname, _ in pairs(P) do
|
||||
if string.find(funcname, pattern) then
|
||||
install(funcname)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
------------------------------------------------------------
|
||||
-- Installs assert() and all assert_xxx() in the user env --
|
||||
------------------------------------------------------------
|
||||
|
||||
local function install_asserts()
|
||||
install_pattern("^assert.*")
|
||||
end
|
||||
|
||||
-------------------------------------------
|
||||
-- Installs all is_xxx() in the user env --
|
||||
-------------------------------------------
|
||||
|
||||
local function install_tests()
|
||||
install_pattern("^is_.+")
|
||||
end
|
||||
|
||||
if name == "asserts" or name == "assertions" then
|
||||
install_asserts()
|
||||
elseif name == "tests" or name == "checks" then
|
||||
install_tests()
|
||||
elseif name == "all" then
|
||||
install_asserts()
|
||||
install_tests()
|
||||
install("TestCase")
|
||||
elseif string.find(name, "^assert.*") and P[name] then
|
||||
install(name)
|
||||
elseif string.find(name, "^is_.+") and P[name] then
|
||||
install(name)
|
||||
elseif name == "TestCase" then
|
||||
install("TestCase")
|
||||
else
|
||||
error("luniit.import(): invalid function '"..name.."' to import", 2)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
--------------------------------------------------
|
||||
-- Installs a private environment on the caller --
|
||||
--------------------------------------------------
|
||||
|
||||
function setprivfenv()
|
||||
local new_env = { }
|
||||
local new_env_mt = { __index = getfenv(2) }
|
||||
setmetatable(new_env, new_env_mt)
|
||||
setfenv(2, new_env)
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
--------------------------------------------------
|
||||
-- Increments a counter in the statistics table --
|
||||
--------------------------------------------------
|
||||
|
||||
function stats_inc(varname, value)
|
||||
orig_assert(is_table(stats))
|
||||
orig_assert(is_string(varname))
|
||||
orig_assert(is_nil(value) or is_number(value))
|
||||
if not stats[varname] then return end
|
||||
stats[varname] = stats[varname] + (value or 1)
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
153
3rdparty/lsqlite3/test.lua
vendored
153
3rdparty/lsqlite3/test.lua
vendored
@ -1,153 +0,0 @@
|
||||
require("lsqlite3")
|
||||
|
||||
local width = 78
|
||||
local function line(pref, suff)
|
||||
pref = pref or ''
|
||||
suff = suff or ''
|
||||
local len = width - 2 - string.len(pref) - string.len(suff)
|
||||
print(pref .. string.rep('-', len) .. suff)
|
||||
end
|
||||
|
||||
local db, vm
|
||||
local assert_, assert = assert, function (test)
|
||||
if (not test) then
|
||||
error(db:errmsg(), 2)
|
||||
end
|
||||
end
|
||||
|
||||
line(sqlite3.version())
|
||||
|
||||
os.remove('test.db')
|
||||
db = sqlite3.open('test.db')
|
||||
|
||||
line(nil, 'db:exec')
|
||||
db:exec('CREATE TABLE t(a, b)')
|
||||
|
||||
line(nil, 'prepare')
|
||||
vm = db:prepare('insert into t values(?, :bork)')
|
||||
assert(vm, db:errmsg())
|
||||
assert(vm:bind_parameter_count() == 2)
|
||||
assert(vm:bind_values(2, 4) == sqlite3.OK)
|
||||
assert(vm:step() == sqlite3.DONE)
|
||||
assert(vm:reset() == sqlite3.OK)
|
||||
assert(vm:bind_names{ 'pork', bork = 'nono' } == sqlite3.OK)
|
||||
assert(vm:step() == sqlite3.DONE)
|
||||
assert(vm:reset() == sqlite3.OK)
|
||||
assert(vm:bind_names{ bork = 'sisi' } == sqlite3.OK)
|
||||
assert(vm:step() == sqlite3.DONE)
|
||||
assert(vm:reset() == sqlite3.OK)
|
||||
assert(vm:bind_names{ 1 } == sqlite3.OK)
|
||||
assert(vm:step() == sqlite3.DONE)
|
||||
assert(vm:finalize() == sqlite3.OK)
|
||||
|
||||
line("select * from t", 'db:exec')
|
||||
|
||||
assert(db:exec('select * from t', function (ud, ncols, values, names)
|
||||
--table.setn(values, 2)
|
||||
print(unpack(values))
|
||||
return sqlite3.OK
|
||||
end) == sqlite3.OK)
|
||||
|
||||
line("select * from t", 'db:prepare')
|
||||
|
||||
vm = db:prepare('select * from t')
|
||||
assert(vm, db:errmsg())
|
||||
print(vm:get_unames())
|
||||
while (vm:step() == sqlite3.ROW) do
|
||||
print(vm:get_uvalues())
|
||||
end
|
||||
assert(vm:finalize() == sqlite3.OK)
|
||||
|
||||
|
||||
|
||||
line('udf', 'scalar')
|
||||
|
||||
local function do_query(sql)
|
||||
local r
|
||||
local vm = db:prepare(sql)
|
||||
assert(vm, db:errmsg())
|
||||
print('====================================')
|
||||
print(vm:get_unames())
|
||||
print('------------------------------------')
|
||||
r = vm:step()
|
||||
while (r == sqlite3.ROW) do
|
||||
print(vm:get_uvalues())
|
||||
r = vm:step()
|
||||
end
|
||||
assert(r == sqlite3.DONE)
|
||||
assert(vm:finalize() == sqlite3.OK)
|
||||
print('====================================')
|
||||
end
|
||||
|
||||
local function udf1_scalar(ctx, v)
|
||||
local ud = ctx:user_data()
|
||||
ud.r = (ud.r or '') .. tostring(v)
|
||||
ctx:result_text(ud.r)
|
||||
end
|
||||
|
||||
db:create_function('udf1', 1, udf1_scalar, { })
|
||||
do_query('select udf1(a) from t')
|
||||
|
||||
|
||||
line('udf', 'aggregate')
|
||||
|
||||
local function udf2_aggregate(ctx, ...)
|
||||
local ud = ctx:get_aggregate_data()
|
||||
if (not ud) then
|
||||
ud = {}
|
||||
ctx:set_aggregate_data(ud)
|
||||
end
|
||||
ud.r = (ud.r or 0) + 2
|
||||
end
|
||||
|
||||
local function udf2_aggregate_finalize(ctx, v)
|
||||
local ud = ctx:get_aggregate_data()
|
||||
ctx:result_number(ud and ud.r or 0)
|
||||
end
|
||||
|
||||
db:create_aggregate('udf2', 1, udf2_aggregate, udf2_aggregate_finalize, { })
|
||||
do_query('select udf2(a) from t')
|
||||
|
||||
if (true) then
|
||||
line(nil, '100 insert exec')
|
||||
db:exec('delete from t')
|
||||
local t = os.time()
|
||||
for i = 1, 100 do
|
||||
db:exec('insert into t values('..i..', '..(i * 2 * -1^i)..')')
|
||||
end
|
||||
print('elapsed: '..(os.time() - t))
|
||||
do_query('select count(*) from t')
|
||||
|
||||
line(nil, '100000 insert exec T')
|
||||
db:exec('delete from t')
|
||||
local t = os.time()
|
||||
db:exec('begin')
|
||||
for i = 1, 100000 do
|
||||
db:exec('insert into t values('..i..', '..(i * 2 * -1^i)..')')
|
||||
end
|
||||
db:exec('commit')
|
||||
print('elapsed: '..(os.time() - t))
|
||||
do_query('select count(*) from t')
|
||||
|
||||
line(nil, '100000 insert prepare/bind T')
|
||||
db:exec('delete from t')
|
||||
local t = os.time()
|
||||
local vm = db:prepare('insert into t values(?, ?)')
|
||||
db:exec('begin')
|
||||
for i = 1, 100000 do
|
||||
vm:bind_values(i, i * 2 * -1^i)
|
||||
vm:step()
|
||||
vm:reset()
|
||||
end
|
||||
vm:finalize()
|
||||
db:exec('commit')
|
||||
print('elapsed: '..(os.time() - t))
|
||||
do_query('select count(*) from t')
|
||||
|
||||
end
|
||||
|
||||
line(nil, "db:close")
|
||||
|
||||
assert(db:close() == sqlite3.OK)
|
||||
|
||||
line(sqlite3.version())
|
587
3rdparty/lsqlite3/tests-sqlite3.lua
vendored
587
3rdparty/lsqlite3/tests-sqlite3.lua
vendored
@ -1,587 +0,0 @@
|
||||
|
||||
--[[--------------------------------------------------------------------------
|
||||
|
||||
Author: Michael Roth <mroth@nessie.de>
|
||||
|
||||
Copyright (c) 2004, 2005 Michael Roth <mroth@nessie.de>
|
||||
|
||||
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.
|
||||
|
||||
--]]--------------------------------------------------------------------------
|
||||
|
||||
|
||||
require "lsqlite3"
|
||||
|
||||
require "lunit"
|
||||
|
||||
lunit.setprivfenv()
|
||||
lunit.import "assertions"
|
||||
lunit.import "checks"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
-------------------------------
|
||||
-- Basic open and close test --
|
||||
-------------------------------
|
||||
|
||||
lunit.wrap("open_memory", function()
|
||||
local db = assert_userdata( sqlite3.open_memory() )
|
||||
assert( db:close() )
|
||||
end)
|
||||
|
||||
lunit.wrap("open", function()
|
||||
local filename = "/tmp/__lua-sqlite3-20040906135849." .. os.time()
|
||||
local db = assert_userdata( sqlite3.open(filename) )
|
||||
assert( db:close() )
|
||||
os.remove(filename)
|
||||
end)
|
||||
|
||||
|
||||
|
||||
-------------------------------------
|
||||
-- Presence of db member functions --
|
||||
-------------------------------------
|
||||
|
||||
local db_funcs = lunit.TestCase("Database Member Functions")
|
||||
|
||||
function db_funcs:setup()
|
||||
self.db = assert( sqlite3.open_memory() )
|
||||
end
|
||||
|
||||
function db_funcs:teardown()
|
||||
assert( self.db:close() )
|
||||
end
|
||||
|
||||
function db_funcs:test()
|
||||
local db = self.db
|
||||
assert_function( db.close )
|
||||
assert_function( db.exec )
|
||||
--e assert_function( db.irows )
|
||||
assert_function( db.rows )
|
||||
--e assert_function( db.cols )
|
||||
--e assert_function( db.first_irow )
|
||||
--e assert_function( db.first_row )
|
||||
--e assert_function( db.first_cols )
|
||||
assert_function( db.prepare )
|
||||
assert_function( db.interrupt )
|
||||
assert_function( db.last_insert_rowid )
|
||||
assert_function( db.changes )
|
||||
assert_function( db.total_changes )
|
||||
end
|
||||
|
||||
|
||||
|
||||
---------------------------------------
|
||||
-- Presence of stmt member functions --
|
||||
---------------------------------------
|
||||
|
||||
local stmt_funcs = lunit.TestCase("Statement Member Functions")
|
||||
|
||||
function stmt_funcs:setup()
|
||||
self.db = assert( sqlite3.open_memory() )
|
||||
self.stmt = assert( self.db:prepare("CREATE TABLE test (id, content)") )
|
||||
end
|
||||
|
||||
function stmt_funcs:teardown()
|
||||
--e- assert( self.stmt:close() )
|
||||
assert( self.stmt:finalize() ) --e+
|
||||
assert( self.db:close() )
|
||||
end
|
||||
|
||||
function stmt_funcs:test()
|
||||
local stmt = self.stmt
|
||||
--e assert_function( stmt.close )
|
||||
assert_function( stmt.reset )
|
||||
--e assert_function( stmt.exec )
|
||||
assert_function( stmt.bind )
|
||||
--e assert_function( stmt.irows )
|
||||
--e assert_function( stmt.rows )
|
||||
--e assert_function( stmt.cols )
|
||||
--e assert_function( stmt.first_irow )
|
||||
--e assert_function( stmt.first_row )
|
||||
--e assert_function( stmt.first_cols )
|
||||
--e assert_function( stmt.column_names )
|
||||
--e assert_function( stmt.column_decltypes )
|
||||
--e assert_function( stmt.column_count )
|
||||
--e +
|
||||
assert_function( stmt.isopen )
|
||||
assert_function( stmt.step )
|
||||
assert_function( stmt.reset )
|
||||
assert_function( stmt.finalize )
|
||||
assert_function( stmt.columns )
|
||||
assert_function( stmt.bind )
|
||||
assert_function( stmt.bind_values )
|
||||
assert_function( stmt.bind_names )
|
||||
assert_function( stmt.bind_blob )
|
||||
assert_function( stmt.bind_parameter_count )
|
||||
assert_function( stmt.bind_parameter_name )
|
||||
assert_function( stmt.get_value )
|
||||
assert_function( stmt.get_values )
|
||||
assert_function( stmt.get_name )
|
||||
assert_function( stmt.get_names )
|
||||
assert_function( stmt.get_type )
|
||||
assert_function( stmt.get_types )
|
||||
assert_function( stmt.get_uvalues )
|
||||
assert_function( stmt.get_unames )
|
||||
assert_function( stmt.get_utypes )
|
||||
assert_function( stmt.get_named_values )
|
||||
assert_function( stmt.get_named_types )
|
||||
assert_function( stmt.idata )
|
||||
assert_function( stmt.inames )
|
||||
assert_function( stmt.itypes )
|
||||
assert_function( stmt.data )
|
||||
assert_function( stmt.type )
|
||||
--e +
|
||||
end
|
||||
|
||||
|
||||
|
||||
------------------
|
||||
-- Tests basics --
|
||||
------------------
|
||||
|
||||
local basics = lunit.TestCase("Basics")
|
||||
|
||||
function basics:setup()
|
||||
self.db = assert_userdata( sqlite3.open_memory() )
|
||||
end
|
||||
|
||||
function basics:teardown()
|
||||
assert_number( self.db:close() )
|
||||
end
|
||||
|
||||
function basics:create_table()
|
||||
assert_number( self.db:exec("CREATE TABLE test (id, name)") )
|
||||
end
|
||||
|
||||
function basics:drop_table()
|
||||
assert_number( self.db:exec("DROP TABLE test") )
|
||||
end
|
||||
|
||||
function basics:insert(id, name)
|
||||
assert_number( self.db:exec("INSERT INTO test VALUES ("..id..", '"..name.."')") )
|
||||
end
|
||||
|
||||
function basics:update(id, name)
|
||||
assert_number( self.db:exec("UPDATE test SET name = '"..name.."' WHERE id = "..id) )
|
||||
end
|
||||
|
||||
function basics:test_create_drop()
|
||||
self:create_table()
|
||||
self:drop_table()
|
||||
end
|
||||
|
||||
function basics:test_multi_create_drop()
|
||||
self:create_table()
|
||||
self:drop_table()
|
||||
self:create_table()
|
||||
self:drop_table()
|
||||
end
|
||||
|
||||
function basics:test_insert()
|
||||
self:create_table()
|
||||
self:insert(1, "Hello World")
|
||||
self:insert(2, "Hello Lua")
|
||||
self:insert(3, "Hello sqlite3")
|
||||
end
|
||||
|
||||
function basics:test_update()
|
||||
self:create_table()
|
||||
self:insert(1, "Hello Home")
|
||||
self:insert(2, "Hello Lua")
|
||||
self:update(1, "Hello World")
|
||||
end
|
||||
|
||||
|
||||
---------------------------------
|
||||
-- Statement Column Info Tests --
|
||||
---------------------------------
|
||||
|
||||
lunit.wrap("Column Info Test", function()
|
||||
local db = assert_userdata( sqlite3.open_memory() )
|
||||
assert_number( db:exec("CREATE TABLE test (id INTEGER, name TEXT)") )
|
||||
local stmt = assert_userdata( db:prepare("SELECT * FROM test") )
|
||||
|
||||
assert_equal(2, stmt:columns(), "Wrong number of columns." )
|
||||
|
||||
local names = assert_table( stmt:get_names() )
|
||||
assert_equal(2, #(names), "Wrong number of names.")
|
||||
assert_equal("id", names[1] )
|
||||
assert_equal("name", names[2] )
|
||||
|
||||
local types = assert_table( stmt:get_types() )
|
||||
assert_equal(2, #(types), "Wrong number of declaration types.")
|
||||
assert_equal("INTEGER", types[1] )
|
||||
assert_equal("TEXT", types[2] )
|
||||
|
||||
assert_equal( sqlite3.OK, stmt:finalize() )
|
||||
assert_equal( sqlite3.OK, db:close() )
|
||||
end)
|
||||
|
||||
|
||||
|
||||
---------------------
|
||||
-- Statement Tests --
|
||||
---------------------
|
||||
|
||||
st = lunit.TestCase("Statement Tests")
|
||||
|
||||
function st:setup()
|
||||
self.db = assert( sqlite3.open_memory() )
|
||||
assert_equal( sqlite3.OK, self.db:exec("CREATE TABLE test (id, name)") )
|
||||
assert_equal( sqlite3.OK, self.db:exec("INSERT INTO test VALUES (1, 'Hello World')") )
|
||||
assert_equal( sqlite3.OK, self.db:exec("INSERT INTO test VALUES (2, 'Hello Lua')") )
|
||||
assert_equal( sqlite3.OK, self.db:exec("INSERT INTO test VALUES (3, 'Hello sqlite3')") )
|
||||
end
|
||||
|
||||
function st:teardown()
|
||||
assert_equal( sqlite3.OK, self.db:close() )
|
||||
end
|
||||
|
||||
function st:check_content(expected)
|
||||
local stmt = assert( self.db:prepare("SELECT * FROM test ORDER BY id") )
|
||||
local i = 0
|
||||
for row in stmt:rows() do
|
||||
i = i + 1
|
||||
assert( i <= #(expected), "Too many rows." )
|
||||
assert_equal(2, #(row), "Two result column expected.")
|
||||
assert_equal(i, row[1], "Wrong 'id'.")
|
||||
assert_equal(expected[i], row[2], "Wrong 'name'.")
|
||||
end
|
||||
assert_equal( #(expected), i, "Too few rows." )
|
||||
assert_number( stmt:finalize() )
|
||||
end
|
||||
|
||||
function st:test_setup()
|
||||
assert_pass(function() self:check_content{ "Hello World", "Hello Lua", "Hello sqlite3" } end)
|
||||
assert_error(function() self:check_content{ "Hello World", "Hello Lua" } end)
|
||||
assert_error(function() self:check_content{ "Hello World", "Hello Lua", "Hello sqlite3", "To much" } end)
|
||||
assert_error(function() self:check_content{ "Hello World", "Hello Lua", "Wrong" } end)
|
||||
assert_error(function() self:check_content{ "Hello World", "Wrong", "Hello sqlite3" } end)
|
||||
assert_error(function() self:check_content{ "Wrong", "Hello Lua", "Hello sqlite3" } end)
|
||||
end
|
||||
|
||||
function st:test_questionmark_args()
|
||||
local stmt = assert_userdata( self.db:prepare("INSERT INTO test VALUES (?, ?)") )
|
||||
assert_number( stmt:bind_values(0, "Test") )
|
||||
assert_error(function() stmt:bind_values("To few") end)
|
||||
assert_error(function() stmt:bind_values(0, "Test", "To many") end)
|
||||
end
|
||||
|
||||
function st:test_questionmark()
|
||||
local stmt = assert_userdata( self.db:prepare("INSERT INTO test VALUES (?, ?)") )
|
||||
assert_number( stmt:bind_values(4, "Good morning") )
|
||||
assert_number( stmt:step() )
|
||||
assert_number( stmt:reset() )
|
||||
self:check_content{ "Hello World", "Hello Lua", "Hello sqlite3", "Good morning" }
|
||||
assert_number( stmt:bind_values(5, "Foo Bar") )
|
||||
assert_number( stmt:step() )
|
||||
assert_number( stmt:reset() )
|
||||
self:check_content{ "Hello World", "Hello Lua", "Hello sqlite3", "Good morning", "Foo Bar" }
|
||||
assert_number( stmt:finalize() )
|
||||
end
|
||||
|
||||
--[===[
|
||||
function st:test_questionmark_multi()
|
||||
local stmt = assert_userdata( self.db:prepare([[
|
||||
INSERT INTO test VALUES (?, ?); INSERT INTO test VALUES (?, ?) ]]))
|
||||
assert( stmt:bind_values(5, "Foo Bar", 4, "Good morning") )
|
||||
assert_number( stmt:step() )
|
||||
assert_number( stmt:reset() )
|
||||
self:check_content{ "Hello World", "Hello Lua", "Hello sqlite3", "Good morning", "Foo Bar" }
|
||||
assert_number( stmt:finalize() )
|
||||
end
|
||||
]===]
|
||||
|
||||
function st:test_identifiers()
|
||||
local stmt = assert_userdata( self.db:prepare("INSERT INTO test VALUES (:id, :name)") )
|
||||
assert_number( stmt:bind_values(4, "Good morning") )
|
||||
assert_number( stmt:step() )
|
||||
assert_number( stmt:reset() )
|
||||
self:check_content{ "Hello World", "Hello Lua", "Hello sqlite3", "Good morning" }
|
||||
assert_number( stmt:bind_values(5, "Foo Bar") )
|
||||
assert_number( stmt:step() )
|
||||
assert_number( stmt:reset() )
|
||||
self:check_content{ "Hello World", "Hello Lua", "Hello sqlite3", "Good morning", "Foo Bar" }
|
||||
assert_number( stmt:finalize() )
|
||||
end
|
||||
|
||||
--[===[
|
||||
function st:test_identifiers_multi()
|
||||
local stmt = assert_table( self.db:prepare([[
|
||||
INSERT INTO test VALUES (:id1, :name1); INSERT INTO test VALUES (:id2, :name2) ]]))
|
||||
assert( stmt:bind_values(5, "Foo Bar", 4, "Good morning") )
|
||||
assert( stmt:exec() )
|
||||
self:check_content{ "Hello World", "Hello Lua", "Hello sqlite3", "Good morning", "Foo Bar" }
|
||||
end
|
||||
]===]
|
||||
|
||||
function st:test_identifiers_names()
|
||||
--local stmt = assert_userdata( self.db:prepare({"name", "id"}, "INSERT INTO test VALUES (:id, $name)") )
|
||||
local stmt = assert_userdata( self.db:prepare("INSERT INTO test VALUES (:id, $name)") )
|
||||
assert_number( stmt:bind_names({name="Good morning", id=4}) )
|
||||
assert_number( stmt:step() )
|
||||
assert_number( stmt:reset() )
|
||||
self:check_content{ "Hello World", "Hello Lua", "Hello sqlite3", "Good morning" }
|
||||
assert_number( stmt:bind_names({name="Foo Bar", id=5}) )
|
||||
assert_number( stmt:step() )
|
||||
assert_number( stmt:reset() )
|
||||
self:check_content{ "Hello World", "Hello Lua", "Hello sqlite3", "Good morning", "Foo Bar" }
|
||||
assert_number( stmt:finalize() )
|
||||
end
|
||||
|
||||
--[===[
|
||||
function st:test_identifiers_multi_names()
|
||||
local stmt = assert_table( self.db:prepare( {"name", "id1", "id2"},[[
|
||||
INSERT INTO test VALUES (:id1, $name); INSERT INTO test VALUES ($id2, :name) ]]))
|
||||
assert( stmt:bind_values("Hoho", 4, 5) )
|
||||
assert( stmt:exec() )
|
||||
self:check_content{ "Hello World", "Hello Lua", "Hello sqlite3", "Hoho", "Hoho" }
|
||||
end
|
||||
]===]
|
||||
|
||||
function st:test_colon_identifiers_names()
|
||||
local stmt = assert_userdata( self.db:prepare("INSERT INTO test VALUES (:id, :name)") )
|
||||
assert_number( stmt:bind_names({name="Good morning", id=4}) )
|
||||
assert_number( stmt:step() )
|
||||
assert_number( stmt:reset() )
|
||||
self:check_content{ "Hello World", "Hello Lua", "Hello sqlite3", "Good morning" }
|
||||
assert_number( stmt:bind_names({name="Foo Bar", id=5}) )
|
||||
assert_number( stmt:step() )
|
||||
assert_number( stmt:reset() )
|
||||
self:check_content{ "Hello World", "Hello Lua", "Hello sqlite3", "Good morning", "Foo Bar" }
|
||||
assert_number( stmt:finalize() )
|
||||
end
|
||||
|
||||
--[===[
|
||||
function st:test_colon_identifiers_multi_names()
|
||||
local stmt = assert_table( self.db:prepare( {":name", ":id1", ":id2"},[[
|
||||
INSERT INTO test VALUES (:id1, $name); INSERT INTO test VALUES ($id2, :name) ]]))
|
||||
assert( stmt:bind_values("Hoho", 4, 5) )
|
||||
assert( stmt:exec() )
|
||||
self:check_content{ "Hello World", "Hello Lua", "Hello sqlite3", "Hoho", "Hoho" }
|
||||
end
|
||||
|
||||
|
||||
function st:test_dollar_identifiers_names()
|
||||
local stmt = assert_table( self.db:prepare({"$name", "$id"}, "INSERT INTO test VALUES (:id, $name)") )
|
||||
assert_table( stmt:bind_values("Good morning", 4) )
|
||||
assert_table( stmt:exec() )
|
||||
self:check_content{ "Hello World", "Hello Lua", "Hello sqlite3", "Good morning" }
|
||||
assert_table( stmt:bind_values("Foo Bar", 5) )
|
||||
assert_table( stmt:exec() )
|
||||
self:check_content{ "Hello World", "Hello Lua", "Hello sqlite3", "Good morning", "Foo Bar" }
|
||||
end
|
||||
|
||||
function st:test_dollar_identifiers_multi_names()
|
||||
local stmt = assert_table( self.db:prepare( {"$name", "$id1", "$id2"},[[
|
||||
INSERT INTO test VALUES (:id1, $name); INSERT INTO test VALUES ($id2, :name) ]]))
|
||||
assert( stmt:bind_values("Hoho", 4, 5) )
|
||||
assert( stmt:exec() )
|
||||
self:check_content{ "Hello World", "Hello Lua", "Hello sqlite3", "Hoho", "Hoho" }
|
||||
end
|
||||
]===]
|
||||
|
||||
function st:test_bind_by_names()
|
||||
local stmt = assert_userdata( self.db:prepare("INSERT INTO test VALUES (:id, :name)") )
|
||||
local args = { }
|
||||
args.id = 5
|
||||
args.name = "Hello girls"
|
||||
assert( stmt:bind_names(args) )
|
||||
assert_number( stmt:step() )
|
||||
assert_number( stmt:reset() )
|
||||
args.id = 4
|
||||
args.name = "Hello boys"
|
||||
assert( stmt:bind_names(args) )
|
||||
assert_number( stmt:step() )
|
||||
assert_number( stmt:reset() )
|
||||
self:check_content{ "Hello World", "Hello Lua", "Hello sqlite3", "Hello boys", "Hello girls" }
|
||||
assert_number( stmt:finalize() )
|
||||
end
|
||||
|
||||
|
||||
|
||||
--------------------------------
|
||||
-- Tests binding of arguments --
|
||||
--------------------------------
|
||||
|
||||
b = lunit.TestCase("Binding Tests")
|
||||
|
||||
function b:setup()
|
||||
self.db = assert( sqlite3.open_memory() )
|
||||
assert_number( self.db:exec("CREATE TABLE test (id, name, u, v, w, x, y, z)") )
|
||||
end
|
||||
|
||||
function b:teardown()
|
||||
assert_number( self.db:close() )
|
||||
end
|
||||
|
||||
function b:test_auto_parameter_names()
|
||||
local stmt = assert_userdata( self.db:prepare("INSERT INTO test VALUES(:a, $b, :a2, :b2, $a, :b, $a3, $b3)") )
|
||||
local parameters = assert_number( stmt:bind_parameter_count() )
|
||||
assert_equal( 8, parameters )
|
||||
assert_equal( ":a", stmt:bind_parameter_name(1) )
|
||||
assert_equal( "$b", stmt:bind_parameter_name(2) )
|
||||
assert_equal( ":a2", stmt:bind_parameter_name(3) )
|
||||
assert_equal( ":b2", stmt:bind_parameter_name(4) )
|
||||
assert_equal( "$a", stmt:bind_parameter_name(5) )
|
||||
assert_equal( ":b", stmt:bind_parameter_name(6) )
|
||||
assert_equal( "$a3", stmt:bind_parameter_name(7) )
|
||||
assert_equal( "$b3", stmt:bind_parameter_name(8) )
|
||||
end
|
||||
|
||||
function b:test_auto_parameter_names()
|
||||
local stmt = assert_userdata( self.db:prepare("INSERT INTO test VALUES($a, $b, $a2, $b2, $a, $b, $a3, $b3)") )
|
||||
local parameters = assert_number( stmt:bind_parameter_count() )
|
||||
assert_equal( 6, parameters )
|
||||
assert_equal( "$a", stmt:bind_parameter_name(1) )
|
||||
assert_equal( "$b", stmt:bind_parameter_name(2) )
|
||||
assert_equal( "$a2", stmt:bind_parameter_name(3) )
|
||||
assert_equal( "$b2", stmt:bind_parameter_name(4) )
|
||||
assert_equal( "$a3", stmt:bind_parameter_name(5) )
|
||||
assert_equal( "$b3", stmt:bind_parameter_name(6) )
|
||||
end
|
||||
|
||||
function b:test_no_parameter_names_1()
|
||||
local stmt = assert_userdata( self.db:prepare([[ SELECT * FROM test ]]))
|
||||
local parameters = assert_number( stmt:bind_parameter_count() )
|
||||
assert_equal( 0, (parameters) )
|
||||
end
|
||||
|
||||
function b:test_no_parameter_names_2()
|
||||
local stmt = assert_userdata( self.db:prepare([[ INSERT INTO test VALUES(?, ?, ?, ?, ?, ?, ?, ?) ]]))
|
||||
local parameters = assert_number( stmt:bind_parameter_count() )
|
||||
assert_equal( 8, (parameters) )
|
||||
assert_nil( stmt:bind_parameter_name(1) )
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
--------------------------------------------
|
||||
-- Tests loop break and statement reusage --
|
||||
--------------------------------------------
|
||||
|
||||
|
||||
|
||||
----------------------------
|
||||
-- Test for bugs reported --
|
||||
----------------------------
|
||||
|
||||
bug = lunit.TestCase("Bug-Report Tests")
|
||||
|
||||
function bug:setup()
|
||||
self.db = assert( sqlite3.open_memory() )
|
||||
end
|
||||
|
||||
function bug:teardown()
|
||||
assert_number( self.db:close() )
|
||||
end
|
||||
|
||||
--[===[
|
||||
function bug:test_1()
|
||||
self.db:exec("CREATE TABLE test (id INTEGER PRIMARY KEY, value TEXT)")
|
||||
|
||||
local query = assert_userdata( self.db:prepare("SELECT id FROM test WHERE value=?") )
|
||||
|
||||
assert_table ( query:bind_values("1") )
|
||||
assert_nil ( query:first_cols() )
|
||||
assert_table ( query:bind_values("2") )
|
||||
assert_nil ( query:first_cols() )
|
||||
end
|
||||
]===]
|
||||
|
||||
function bug:test_nils() -- appeared in lua-5.1 (holes in arrays)
|
||||
local function check(arg1, arg2, arg3, arg4, arg5)
|
||||
assert_equal(1, arg1)
|
||||
assert_equal(2, arg2)
|
||||
assert_nil(arg3)
|
||||
assert_equal(4, arg4)
|
||||
assert_nil(arg5)
|
||||
end
|
||||
|
||||
self.db:create_function("test_nils", 5, function(arg1, arg2, arg3, arg4, arg5)
|
||||
check(arg1, arg2, arg3, arg4, arg5)
|
||||
end, {})
|
||||
|
||||
assert_number( self.db:exec([[ SELECT test_nils(1, 2, NULL, 4, NULL) ]]) )
|
||||
|
||||
for arg1, arg2, arg3, arg4, arg5 in self.db:urows([[ SELECT 1, 2, NULL, 4, NULL ]])
|
||||
do check(arg1, arg2, arg3, arg4, arg5)
|
||||
end
|
||||
|
||||
for row in self.db:rows([[ SELECT 1, 2, NULL, 4, NULL ]])
|
||||
do assert_table( row )
|
||||
check(row[1], row[2], row[3], row[4], row[5])
|
||||
end
|
||||
end
|
||||
|
||||
----------------------------
|
||||
-- Test for collation fun --
|
||||
----------------------------
|
||||
|
||||
colla = lunit.TestCase("Collation Tests")
|
||||
|
||||
function colla:setup()
|
||||
local function collate(s1,s2)
|
||||
-- if p then print("collation callback: ",s1,s2) end
|
||||
s1=s1:lower()
|
||||
s2=s2:lower()
|
||||
if s1==s2 then return 0
|
||||
elseif s1<s2 then return -1
|
||||
else return 1 end
|
||||
end
|
||||
self.db = assert( sqlite3.open_memory() )
|
||||
assert_nil(self.db:create_collation('CINSENS',collate))
|
||||
self.db:exec[[
|
||||
CREATE TABLE test(id INTEGER PRIMARY KEY,content COLLATE CINSENS);
|
||||
INSERT INTO test VALUES(NULL,'hello world');
|
||||
INSERT INTO test VALUES(NULL,'Buenos dias');
|
||||
INSERT INTO test VALUES(NULL,'HELLO WORLD');
|
||||
INSERT INTO test VALUES(NULL,'Guten Tag');
|
||||
INSERT INTO test VALUES(NULL,'HeLlO WoRlD');
|
||||
INSERT INTO test VALUES(NULL,'Bye for now');
|
||||
]]
|
||||
end
|
||||
|
||||
function colla:teardown()
|
||||
assert_number( self.db:close() )
|
||||
end
|
||||
|
||||
function colla:test()
|
||||
--for row in db:nrows('SELECT * FROM test') do
|
||||
-- print(row.id,row.content)
|
||||
--end
|
||||
local n = 0
|
||||
for row in self.db:nrows('SELECT * FROM test WHERE content="hElLo wOrLd"') do
|
||||
-- print(row.id,row.content)
|
||||
assert_equal (row.content:lower(), "hello world")
|
||||
n = n + 1
|
||||
end
|
||||
assert_equal (n, 3)
|
||||
end
|
||||
|
||||
lunit.run()
|
4259
3rdparty/sqlite3/shell.c
vendored
4259
3rdparty/sqlite3/shell.c
vendored
File diff suppressed because it is too large
Load Diff
151716
3rdparty/sqlite3/sqlite3.c
vendored
151716
3rdparty/sqlite3/sqlite3.c
vendored
File diff suppressed because it is too large
Load Diff
7543
3rdparty/sqlite3/sqlite3.h
vendored
7543
3rdparty/sqlite3/sqlite3.h
vendored
File diff suppressed because it is too large
Load Diff
517
3rdparty/sqlite3/sqlite3ext.h
vendored
517
3rdparty/sqlite3/sqlite3ext.h
vendored
@ -1,517 +0,0 @@
|
||||
/*
|
||||
** 2006 June 7
|
||||
**
|
||||
** The author disclaims copyright to this source code. In place of
|
||||
** a legal notice, here is a blessing:
|
||||
**
|
||||
** May you do good and not evil.
|
||||
** May you find forgiveness for yourself and forgive others.
|
||||
** May you share freely, never taking more than you give.
|
||||
**
|
||||
*************************************************************************
|
||||
** This header file defines the SQLite interface for use by
|
||||
** shared libraries that want to be imported as extensions into
|
||||
** an SQLite instance. Shared libraries that intend to be loaded
|
||||
** as extensions by SQLite should #include this file instead of
|
||||
** sqlite3.h.
|
||||
*/
|
||||
#ifndef _SQLITE3EXT_H_
|
||||
#define _SQLITE3EXT_H_
|
||||
#include "sqlite3.h"
|
||||
|
||||
typedef struct sqlite3_api_routines sqlite3_api_routines;
|
||||
|
||||
/*
|
||||
** The following structure holds pointers to all of the SQLite API
|
||||
** routines.
|
||||
**
|
||||
** WARNING: In order to maintain backwards compatibility, add new
|
||||
** interfaces to the end of this structure only. If you insert new
|
||||
** interfaces in the middle of this structure, then older different
|
||||
** versions of SQLite will not be able to load each other's shared
|
||||
** libraries!
|
||||
*/
|
||||
struct sqlite3_api_routines {
|
||||
void * (*aggregate_context)(sqlite3_context*,int nBytes);
|
||||
int (*aggregate_count)(sqlite3_context*);
|
||||
int (*bind_blob)(sqlite3_stmt*,int,const void*,int n,void(*)(void*));
|
||||
int (*bind_double)(sqlite3_stmt*,int,double);
|
||||
int (*bind_int)(sqlite3_stmt*,int,int);
|
||||
int (*bind_int64)(sqlite3_stmt*,int,sqlite_int64);
|
||||
int (*bind_null)(sqlite3_stmt*,int);
|
||||
int (*bind_parameter_count)(sqlite3_stmt*);
|
||||
int (*bind_parameter_index)(sqlite3_stmt*,const char*zName);
|
||||
const char * (*bind_parameter_name)(sqlite3_stmt*,int);
|
||||
int (*bind_text)(sqlite3_stmt*,int,const char*,int n,void(*)(void*));
|
||||
int (*bind_text16)(sqlite3_stmt*,int,const void*,int,void(*)(void*));
|
||||
int (*bind_value)(sqlite3_stmt*,int,const sqlite3_value*);
|
||||
int (*busy_handler)(sqlite3*,int(*)(void*,int),void*);
|
||||
int (*busy_timeout)(sqlite3*,int ms);
|
||||
int (*changes)(sqlite3*);
|
||||
int (*close)(sqlite3*);
|
||||
int (*collation_needed)(sqlite3*,void*,void(*)(void*,sqlite3*,
|
||||
int eTextRep,const char*));
|
||||
int (*collation_needed16)(sqlite3*,void*,void(*)(void*,sqlite3*,
|
||||
int eTextRep,const void*));
|
||||
const void * (*column_blob)(sqlite3_stmt*,int iCol);
|
||||
int (*column_bytes)(sqlite3_stmt*,int iCol);
|
||||
int (*column_bytes16)(sqlite3_stmt*,int iCol);
|
||||
int (*column_count)(sqlite3_stmt*pStmt);
|
||||
const char * (*column_database_name)(sqlite3_stmt*,int);
|
||||
const void * (*column_database_name16)(sqlite3_stmt*,int);
|
||||
const char * (*column_decltype)(sqlite3_stmt*,int i);
|
||||
const void * (*column_decltype16)(sqlite3_stmt*,int);
|
||||
double (*column_double)(sqlite3_stmt*,int iCol);
|
||||
int (*column_int)(sqlite3_stmt*,int iCol);
|
||||
sqlite_int64 (*column_int64)(sqlite3_stmt*,int iCol);
|
||||
const char * (*column_name)(sqlite3_stmt*,int);
|
||||
const void * (*column_name16)(sqlite3_stmt*,int);
|
||||
const char * (*column_origin_name)(sqlite3_stmt*,int);
|
||||
const void * (*column_origin_name16)(sqlite3_stmt*,int);
|
||||
const char * (*column_table_name)(sqlite3_stmt*,int);
|
||||
const void * (*column_table_name16)(sqlite3_stmt*,int);
|
||||
const unsigned char * (*column_text)(sqlite3_stmt*,int iCol);
|
||||
const void * (*column_text16)(sqlite3_stmt*,int iCol);
|
||||
int (*column_type)(sqlite3_stmt*,int iCol);
|
||||
sqlite3_value* (*column_value)(sqlite3_stmt*,int iCol);
|
||||
void * (*commit_hook)(sqlite3*,int(*)(void*),void*);
|
||||
int (*complete)(const char*sql);
|
||||
int (*complete16)(const void*sql);
|
||||
int (*create_collation)(sqlite3*,const char*,int,void*,
|
||||
int(*)(void*,int,const void*,int,const void*));
|
||||
int (*create_collation16)(sqlite3*,const void*,int,void*,
|
||||
int(*)(void*,int,const void*,int,const void*));
|
||||
int (*create_function)(sqlite3*,const char*,int,int,void*,
|
||||
void (*xFunc)(sqlite3_context*,int,sqlite3_value**),
|
||||
void (*xStep)(sqlite3_context*,int,sqlite3_value**),
|
||||
void (*xFinal)(sqlite3_context*));
|
||||
int (*create_function16)(sqlite3*,const void*,int,int,void*,
|
||||
void (*xFunc)(sqlite3_context*,int,sqlite3_value**),
|
||||
void (*xStep)(sqlite3_context*,int,sqlite3_value**),
|
||||
void (*xFinal)(sqlite3_context*));
|
||||
int (*create_module)(sqlite3*,const char*,const sqlite3_module*,void*);
|
||||
int (*data_count)(sqlite3_stmt*pStmt);
|
||||
sqlite3 * (*db_handle)(sqlite3_stmt*);
|
||||
int (*declare_vtab)(sqlite3*,const char*);
|
||||
int (*enable_shared_cache)(int);
|
||||
int (*errcode)(sqlite3*db);
|
||||
const char * (*errmsg)(sqlite3*);
|
||||
const void * (*errmsg16)(sqlite3*);
|
||||
int (*exec)(sqlite3*,const char*,sqlite3_callback,void*,char**);
|
||||
int (*expired)(sqlite3_stmt*);
|
||||
int (*finalize)(sqlite3_stmt*pStmt);
|
||||
void (*free)(void*);
|
||||
void (*free_table)(char**result);
|
||||
int (*get_autocommit)(sqlite3*);
|
||||
void * (*get_auxdata)(sqlite3_context*,int);
|
||||
int (*get_table)(sqlite3*,const char*,char***,int*,int*,char**);
|
||||
int (*global_recover)(void);
|
||||
void (*interruptx)(sqlite3*);
|
||||
sqlite_int64 (*last_insert_rowid)(sqlite3*);
|
||||
const char * (*libversion)(void);
|
||||
int (*libversion_number)(void);
|
||||
void *(*malloc)(int);
|
||||
char * (*mprintf)(const char*,...);
|
||||
int (*open)(const char*,sqlite3**);
|
||||
int (*open16)(const void*,sqlite3**);
|
||||
int (*prepare)(sqlite3*,const char*,int,sqlite3_stmt**,const char**);
|
||||
int (*prepare16)(sqlite3*,const void*,int,sqlite3_stmt**,const void**);
|
||||
void * (*profile)(sqlite3*,void(*)(void*,const char*,sqlite_uint64),void*);
|
||||
void (*progress_handler)(sqlite3*,int,int(*)(void*),void*);
|
||||
void *(*realloc)(void*,int);
|
||||
int (*reset)(sqlite3_stmt*pStmt);
|
||||
void (*result_blob)(sqlite3_context*,const void*,int,void(*)(void*));
|
||||
void (*result_double)(sqlite3_context*,double);
|
||||
void (*result_error)(sqlite3_context*,const char*,int);
|
||||
void (*result_error16)(sqlite3_context*,const void*,int);
|
||||
void (*result_int)(sqlite3_context*,int);
|
||||
void (*result_int64)(sqlite3_context*,sqlite_int64);
|
||||
void (*result_null)(sqlite3_context*);
|
||||
void (*result_text)(sqlite3_context*,const char*,int,void(*)(void*));
|
||||
void (*result_text16)(sqlite3_context*,const void*,int,void(*)(void*));
|
||||
void (*result_text16be)(sqlite3_context*,const void*,int,void(*)(void*));
|
||||
void (*result_text16le)(sqlite3_context*,const void*,int,void(*)(void*));
|
||||
void (*result_value)(sqlite3_context*,sqlite3_value*);
|
||||
void * (*rollback_hook)(sqlite3*,void(*)(void*),void*);
|
||||
int (*set_authorizer)(sqlite3*,int(*)(void*,int,const char*,const char*,
|
||||
const char*,const char*),void*);
|
||||
void (*set_auxdata)(sqlite3_context*,int,void*,void (*)(void*));
|
||||
char * (*snprintf)(int,char*,const char*,...);
|
||||
int (*step)(sqlite3_stmt*);
|
||||
int (*table_column_metadata)(sqlite3*,const char*,const char*,const char*,
|
||||
char const**,char const**,int*,int*,int*);
|
||||
void (*thread_cleanup)(void);
|
||||
int (*total_changes)(sqlite3*);
|
||||
void * (*trace)(sqlite3*,void(*xTrace)(void*,const char*),void*);
|
||||
int (*transfer_bindings)(sqlite3_stmt*,sqlite3_stmt*);
|
||||
void * (*update_hook)(sqlite3*,void(*)(void*,int ,char const*,char const*,
|
||||
sqlite_int64),void*);
|
||||
void * (*user_data)(sqlite3_context*);
|
||||
const void * (*value_blob)(sqlite3_value*);
|
||||
int (*value_bytes)(sqlite3_value*);
|
||||
int (*value_bytes16)(sqlite3_value*);
|
||||
double (*value_double)(sqlite3_value*);
|
||||
int (*value_int)(sqlite3_value*);
|
||||
sqlite_int64 (*value_int64)(sqlite3_value*);
|
||||
int (*value_numeric_type)(sqlite3_value*);
|
||||
const unsigned char * (*value_text)(sqlite3_value*);
|
||||
const void * (*value_text16)(sqlite3_value*);
|
||||
const void * (*value_text16be)(sqlite3_value*);
|
||||
const void * (*value_text16le)(sqlite3_value*);
|
||||
int (*value_type)(sqlite3_value*);
|
||||
char *(*vmprintf)(const char*,va_list);
|
||||
/* Added ??? */
|
||||
int (*overload_function)(sqlite3*, const char *zFuncName, int nArg);
|
||||
/* Added by 3.3.13 */
|
||||
int (*prepare_v2)(sqlite3*,const char*,int,sqlite3_stmt**,const char**);
|
||||
int (*prepare16_v2)(sqlite3*,const void*,int,sqlite3_stmt**,const void**);
|
||||
int (*clear_bindings)(sqlite3_stmt*);
|
||||
/* Added by 3.4.1 */
|
||||
int (*create_module_v2)(sqlite3*,const char*,const sqlite3_module*,void*,
|
||||
void (*xDestroy)(void *));
|
||||
/* Added by 3.5.0 */
|
||||
int (*bind_zeroblob)(sqlite3_stmt*,int,int);
|
||||
int (*blob_bytes)(sqlite3_blob*);
|
||||
int (*blob_close)(sqlite3_blob*);
|
||||
int (*blob_open)(sqlite3*,const char*,const char*,const char*,sqlite3_int64,
|
||||
int,sqlite3_blob**);
|
||||
int (*blob_read)(sqlite3_blob*,void*,int,int);
|
||||
int (*blob_write)(sqlite3_blob*,const void*,int,int);
|
||||
int (*create_collation_v2)(sqlite3*,const char*,int,void*,
|
||||
int(*)(void*,int,const void*,int,const void*),
|
||||
void(*)(void*));
|
||||
int (*file_control)(sqlite3*,const char*,int,void*);
|
||||
sqlite3_int64 (*memory_highwater)(int);
|
||||
sqlite3_int64 (*memory_used)(void);
|
||||
sqlite3_mutex *(*mutex_alloc)(int);
|
||||
void (*mutex_enter)(sqlite3_mutex*);
|
||||
void (*mutex_free)(sqlite3_mutex*);
|
||||
void (*mutex_leave)(sqlite3_mutex*);
|
||||
int (*mutex_try)(sqlite3_mutex*);
|
||||
int (*open_v2)(const char*,sqlite3**,int,const char*);
|
||||
int (*release_memory)(int);
|
||||
void (*result_error_nomem)(sqlite3_context*);
|
||||
void (*result_error_toobig)(sqlite3_context*);
|
||||
int (*sleep)(int);
|
||||
void (*soft_heap_limit)(int);
|
||||
sqlite3_vfs *(*vfs_find)(const char*);
|
||||
int (*vfs_register)(sqlite3_vfs*,int);
|
||||
int (*vfs_unregister)(sqlite3_vfs*);
|
||||
int (*xthreadsafe)(void);
|
||||
void (*result_zeroblob)(sqlite3_context*,int);
|
||||
void (*result_error_code)(sqlite3_context*,int);
|
||||
int (*test_control)(int, ...);
|
||||
void (*randomness)(int,void*);
|
||||
sqlite3 *(*context_db_handle)(sqlite3_context*);
|
||||
int (*extended_result_codes)(sqlite3*,int);
|
||||
int (*limit)(sqlite3*,int,int);
|
||||
sqlite3_stmt *(*next_stmt)(sqlite3*,sqlite3_stmt*);
|
||||
const char *(*sql)(sqlite3_stmt*);
|
||||
int (*status)(int,int*,int*,int);
|
||||
int (*backup_finish)(sqlite3_backup*);
|
||||
sqlite3_backup *(*backup_init)(sqlite3*,const char*,sqlite3*,const char*);
|
||||
int (*backup_pagecount)(sqlite3_backup*);
|
||||
int (*backup_remaining)(sqlite3_backup*);
|
||||
int (*backup_step)(sqlite3_backup*,int);
|
||||
const char *(*compileoption_get)(int);
|
||||
int (*compileoption_used)(const char*);
|
||||
int (*create_function_v2)(sqlite3*,const char*,int,int,void*,
|
||||
void (*xFunc)(sqlite3_context*,int,sqlite3_value**),
|
||||
void (*xStep)(sqlite3_context*,int,sqlite3_value**),
|
||||
void (*xFinal)(sqlite3_context*),
|
||||
void(*xDestroy)(void*));
|
||||
int (*db_config)(sqlite3*,int,...);
|
||||
sqlite3_mutex *(*db_mutex)(sqlite3*);
|
||||
int (*db_status)(sqlite3*,int,int*,int*,int);
|
||||
int (*extended_errcode)(sqlite3*);
|
||||
void (*log)(int,const char*,...);
|
||||
sqlite3_int64 (*soft_heap_limit64)(sqlite3_int64);
|
||||
const char *(*sourceid)(void);
|
||||
int (*stmt_status)(sqlite3_stmt*,int,int);
|
||||
int (*strnicmp)(const char*,const char*,int);
|
||||
int (*unlock_notify)(sqlite3*,void(*)(void**,int),void*);
|
||||
int (*wal_autocheckpoint)(sqlite3*,int);
|
||||
int (*wal_checkpoint)(sqlite3*,const char*);
|
||||
void *(*wal_hook)(sqlite3*,int(*)(void*,sqlite3*,const char*,int),void*);
|
||||
int (*blob_reopen)(sqlite3_blob*,sqlite3_int64);
|
||||
int (*vtab_config)(sqlite3*,int op,...);
|
||||
int (*vtab_on_conflict)(sqlite3*);
|
||||
/* Version 3.7.16 and later */
|
||||
int (*close_v2)(sqlite3*);
|
||||
const char *(*db_filename)(sqlite3*,const char*);
|
||||
int (*db_readonly)(sqlite3*,const char*);
|
||||
int (*db_release_memory)(sqlite3*);
|
||||
const char *(*errstr)(int);
|
||||
int (*stmt_busy)(sqlite3_stmt*);
|
||||
int (*stmt_readonly)(sqlite3_stmt*);
|
||||
int (*stricmp)(const char*,const char*);
|
||||
int (*uri_boolean)(const char*,const char*,int);
|
||||
sqlite3_int64 (*uri_int64)(const char*,const char*,sqlite3_int64);
|
||||
const char *(*uri_parameter)(const char*,const char*);
|
||||
char *(*vsnprintf)(int,char*,const char*,va_list);
|
||||
int (*wal_checkpoint_v2)(sqlite3*,const char*,int,int*,int*);
|
||||
/* Version 3.8.7 and later */
|
||||
int (*auto_extension)(void(*)(void));
|
||||
int (*bind_blob64)(sqlite3_stmt*,int,const void*,sqlite3_uint64,
|
||||
void(*)(void*));
|
||||
int (*bind_text64)(sqlite3_stmt*,int,const char*,sqlite3_uint64,
|
||||
void(*)(void*),unsigned char);
|
||||
int (*cancel_auto_extension)(void(*)(void));
|
||||
int (*load_extension)(sqlite3*,const char*,const char*,char**);
|
||||
void *(*malloc64)(sqlite3_uint64);
|
||||
sqlite3_uint64 (*msize)(void*);
|
||||
void *(*realloc64)(void*,sqlite3_uint64);
|
||||
void (*reset_auto_extension)(void);
|
||||
void (*result_blob64)(sqlite3_context*,const void*,sqlite3_uint64,
|
||||
void(*)(void*));
|
||||
void (*result_text64)(sqlite3_context*,const char*,sqlite3_uint64,
|
||||
void(*)(void*), unsigned char);
|
||||
int (*strglob)(const char*,const char*);
|
||||
};
|
||||
|
||||
/*
|
||||
** The following macros redefine the API routines so that they are
|
||||
** redirected through the global sqlite3_api structure.
|
||||
**
|
||||
** This header file is also used by the loadext.c source file
|
||||
** (part of the main SQLite library - not an extension) so that
|
||||
** it can get access to the sqlite3_api_routines structure
|
||||
** definition. But the main library does not want to redefine
|
||||
** the API. So the redefinition macros are only valid if the
|
||||
** SQLITE_CORE macros is undefined.
|
||||
*/
|
||||
#ifndef SQLITE_CORE
|
||||
#define sqlite3_aggregate_context sqlite3_api->aggregate_context
|
||||
#ifndef SQLITE_OMIT_DEPRECATED
|
||||
#define sqlite3_aggregate_count sqlite3_api->aggregate_count
|
||||
#endif
|
||||
#define sqlite3_bind_blob sqlite3_api->bind_blob
|
||||
#define sqlite3_bind_double sqlite3_api->bind_double
|
||||
#define sqlite3_bind_int sqlite3_api->bind_int
|
||||
#define sqlite3_bind_int64 sqlite3_api->bind_int64
|
||||
#define sqlite3_bind_null sqlite3_api->bind_null
|
||||
#define sqlite3_bind_parameter_count sqlite3_api->bind_parameter_count
|
||||
#define sqlite3_bind_parameter_index sqlite3_api->bind_parameter_index
|
||||
#define sqlite3_bind_parameter_name sqlite3_api->bind_parameter_name
|
||||
#define sqlite3_bind_text sqlite3_api->bind_text
|
||||
#define sqlite3_bind_text16 sqlite3_api->bind_text16
|
||||
#define sqlite3_bind_value sqlite3_api->bind_value
|
||||
#define sqlite3_busy_handler sqlite3_api->busy_handler
|
||||
#define sqlite3_busy_timeout sqlite3_api->busy_timeout
|
||||
#define sqlite3_changes sqlite3_api->changes
|
||||
#define sqlite3_close sqlite3_api->close
|
||||
#define sqlite3_collation_needed sqlite3_api->collation_needed
|
||||
#define sqlite3_collation_needed16 sqlite3_api->collation_needed16
|
||||
#define sqlite3_column_blob sqlite3_api->column_blob
|
||||
#define sqlite3_column_bytes sqlite3_api->column_bytes
|
||||
#define sqlite3_column_bytes16 sqlite3_api->column_bytes16
|
||||
#define sqlite3_column_count sqlite3_api->column_count
|
||||
#define sqlite3_column_database_name sqlite3_api->column_database_name
|
||||
#define sqlite3_column_database_name16 sqlite3_api->column_database_name16
|
||||
#define sqlite3_column_decltype sqlite3_api->column_decltype
|
||||
#define sqlite3_column_decltype16 sqlite3_api->column_decltype16
|
||||
#define sqlite3_column_double sqlite3_api->column_double
|
||||
#define sqlite3_column_int sqlite3_api->column_int
|
||||
#define sqlite3_column_int64 sqlite3_api->column_int64
|
||||
#define sqlite3_column_name sqlite3_api->column_name
|
||||
#define sqlite3_column_name16 sqlite3_api->column_name16
|
||||
#define sqlite3_column_origin_name sqlite3_api->column_origin_name
|
||||
#define sqlite3_column_origin_name16 sqlite3_api->column_origin_name16
|
||||
#define sqlite3_column_table_name sqlite3_api->column_table_name
|
||||
#define sqlite3_column_table_name16 sqlite3_api->column_table_name16
|
||||
#define sqlite3_column_text sqlite3_api->column_text
|
||||
#define sqlite3_column_text16 sqlite3_api->column_text16
|
||||
#define sqlite3_column_type sqlite3_api->column_type
|
||||
#define sqlite3_column_value sqlite3_api->column_value
|
||||
#define sqlite3_commit_hook sqlite3_api->commit_hook
|
||||
#define sqlite3_complete sqlite3_api->complete
|
||||
#define sqlite3_complete16 sqlite3_api->complete16
|
||||
#define sqlite3_create_collation sqlite3_api->create_collation
|
||||
#define sqlite3_create_collation16 sqlite3_api->create_collation16
|
||||
#define sqlite3_create_function sqlite3_api->create_function
|
||||
#define sqlite3_create_function16 sqlite3_api->create_function16
|
||||
#define sqlite3_create_module sqlite3_api->create_module
|
||||
#define sqlite3_create_module_v2 sqlite3_api->create_module_v2
|
||||
#define sqlite3_data_count sqlite3_api->data_count
|
||||
#define sqlite3_db_handle sqlite3_api->db_handle
|
||||
#define sqlite3_declare_vtab sqlite3_api->declare_vtab
|
||||
#define sqlite3_enable_shared_cache sqlite3_api->enable_shared_cache
|
||||
#define sqlite3_errcode sqlite3_api->errcode
|
||||
#define sqlite3_errmsg sqlite3_api->errmsg
|
||||
#define sqlite3_errmsg16 sqlite3_api->errmsg16
|
||||
#define sqlite3_exec sqlite3_api->exec
|
||||
#ifndef SQLITE_OMIT_DEPRECATED
|
||||
#define sqlite3_expired sqlite3_api->expired
|
||||
#endif
|
||||
#define sqlite3_finalize sqlite3_api->finalize
|
||||
#define sqlite3_free sqlite3_api->free
|
||||
#define sqlite3_free_table sqlite3_api->free_table
|
||||
#define sqlite3_get_autocommit sqlite3_api->get_autocommit
|
||||
#define sqlite3_get_auxdata sqlite3_api->get_auxdata
|
||||
#define sqlite3_get_table sqlite3_api->get_table
|
||||
#ifndef SQLITE_OMIT_DEPRECATED
|
||||
#define sqlite3_global_recover sqlite3_api->global_recover
|
||||
#endif
|
||||
#define sqlite3_interrupt sqlite3_api->interruptx
|
||||
#define sqlite3_last_insert_rowid sqlite3_api->last_insert_rowid
|
||||
#define sqlite3_libversion sqlite3_api->libversion
|
||||
#define sqlite3_libversion_number sqlite3_api->libversion_number
|
||||
#define sqlite3_malloc sqlite3_api->malloc
|
||||
#define sqlite3_mprintf sqlite3_api->mprintf
|
||||
#define sqlite3_open sqlite3_api->open
|
||||
#define sqlite3_open16 sqlite3_api->open16
|
||||
#define sqlite3_prepare sqlite3_api->prepare
|
||||
#define sqlite3_prepare16 sqlite3_api->prepare16
|
||||
#define sqlite3_prepare_v2 sqlite3_api->prepare_v2
|
||||
#define sqlite3_prepare16_v2 sqlite3_api->prepare16_v2
|
||||
#define sqlite3_profile sqlite3_api->profile
|
||||
#define sqlite3_progress_handler sqlite3_api->progress_handler
|
||||
#define sqlite3_realloc sqlite3_api->realloc
|
||||
#define sqlite3_reset sqlite3_api->reset
|
||||
#define sqlite3_result_blob sqlite3_api->result_blob
|
||||
#define sqlite3_result_double sqlite3_api->result_double
|
||||
#define sqlite3_result_error sqlite3_api->result_error
|
||||
#define sqlite3_result_error16 sqlite3_api->result_error16
|
||||
#define sqlite3_result_int sqlite3_api->result_int
|
||||
#define sqlite3_result_int64 sqlite3_api->result_int64
|
||||
#define sqlite3_result_null sqlite3_api->result_null
|
||||
#define sqlite3_result_text sqlite3_api->result_text
|
||||
#define sqlite3_result_text16 sqlite3_api->result_text16
|
||||
#define sqlite3_result_text16be sqlite3_api->result_text16be
|
||||
#define sqlite3_result_text16le sqlite3_api->result_text16le
|
||||
#define sqlite3_result_value sqlite3_api->result_value
|
||||
#define sqlite3_rollback_hook sqlite3_api->rollback_hook
|
||||
#define sqlite3_set_authorizer sqlite3_api->set_authorizer
|
||||
#define sqlite3_set_auxdata sqlite3_api->set_auxdata
|
||||
#define sqlite3_snprintf sqlite3_api->snprintf
|
||||
#define sqlite3_step sqlite3_api->step
|
||||
#define sqlite3_table_column_metadata sqlite3_api->table_column_metadata
|
||||
#define sqlite3_thread_cleanup sqlite3_api->thread_cleanup
|
||||
#define sqlite3_total_changes sqlite3_api->total_changes
|
||||
#define sqlite3_trace sqlite3_api->trace
|
||||
#ifndef SQLITE_OMIT_DEPRECATED
|
||||
#define sqlite3_transfer_bindings sqlite3_api->transfer_bindings
|
||||
#endif
|
||||
#define sqlite3_update_hook sqlite3_api->update_hook
|
||||
#define sqlite3_user_data sqlite3_api->user_data
|
||||
#define sqlite3_value_blob sqlite3_api->value_blob
|
||||
#define sqlite3_value_bytes sqlite3_api->value_bytes
|
||||
#define sqlite3_value_bytes16 sqlite3_api->value_bytes16
|
||||
#define sqlite3_value_double sqlite3_api->value_double
|
||||
#define sqlite3_value_int sqlite3_api->value_int
|
||||
#define sqlite3_value_int64 sqlite3_api->value_int64
|
||||
#define sqlite3_value_numeric_type sqlite3_api->value_numeric_type
|
||||
#define sqlite3_value_text sqlite3_api->value_text
|
||||
#define sqlite3_value_text16 sqlite3_api->value_text16
|
||||
#define sqlite3_value_text16be sqlite3_api->value_text16be
|
||||
#define sqlite3_value_text16le sqlite3_api->value_text16le
|
||||
#define sqlite3_value_type sqlite3_api->value_type
|
||||
#define sqlite3_vmprintf sqlite3_api->vmprintf
|
||||
#define sqlite3_overload_function sqlite3_api->overload_function
|
||||
#define sqlite3_prepare_v2 sqlite3_api->prepare_v2
|
||||
#define sqlite3_prepare16_v2 sqlite3_api->prepare16_v2
|
||||
#define sqlite3_clear_bindings sqlite3_api->clear_bindings
|
||||
#define sqlite3_bind_zeroblob sqlite3_api->bind_zeroblob
|
||||
#define sqlite3_blob_bytes sqlite3_api->blob_bytes
|
||||
#define sqlite3_blob_close sqlite3_api->blob_close
|
||||
#define sqlite3_blob_open sqlite3_api->blob_open
|
||||
#define sqlite3_blob_read sqlite3_api->blob_read
|
||||
#define sqlite3_blob_write sqlite3_api->blob_write
|
||||
#define sqlite3_create_collation_v2 sqlite3_api->create_collation_v2
|
||||
#define sqlite3_file_control sqlite3_api->file_control
|
||||
#define sqlite3_memory_highwater sqlite3_api->memory_highwater
|
||||
#define sqlite3_memory_used sqlite3_api->memory_used
|
||||
#define sqlite3_mutex_alloc sqlite3_api->mutex_alloc
|
||||
#define sqlite3_mutex_enter sqlite3_api->mutex_enter
|
||||
#define sqlite3_mutex_free sqlite3_api->mutex_free
|
||||
#define sqlite3_mutex_leave sqlite3_api->mutex_leave
|
||||
#define sqlite3_mutex_try sqlite3_api->mutex_try
|
||||
#define sqlite3_open_v2 sqlite3_api->open_v2
|
||||
#define sqlite3_release_memory sqlite3_api->release_memory
|
||||
#define sqlite3_result_error_nomem sqlite3_api->result_error_nomem
|
||||
#define sqlite3_result_error_toobig sqlite3_api->result_error_toobig
|
||||
#define sqlite3_sleep sqlite3_api->sleep
|
||||
#define sqlite3_soft_heap_limit sqlite3_api->soft_heap_limit
|
||||
#define sqlite3_vfs_find sqlite3_api->vfs_find
|
||||
#define sqlite3_vfs_register sqlite3_api->vfs_register
|
||||
#define sqlite3_vfs_unregister sqlite3_api->vfs_unregister
|
||||
#define sqlite3_threadsafe sqlite3_api->xthreadsafe
|
||||
#define sqlite3_result_zeroblob sqlite3_api->result_zeroblob
|
||||
#define sqlite3_result_error_code sqlite3_api->result_error_code
|
||||
#define sqlite3_test_control sqlite3_api->test_control
|
||||
#define sqlite3_randomness sqlite3_api->randomness
|
||||
#define sqlite3_context_db_handle sqlite3_api->context_db_handle
|
||||
#define sqlite3_extended_result_codes sqlite3_api->extended_result_codes
|
||||
#define sqlite3_limit sqlite3_api->limit
|
||||
#define sqlite3_next_stmt sqlite3_api->next_stmt
|
||||
#define sqlite3_sql sqlite3_api->sql
|
||||
#define sqlite3_status sqlite3_api->status
|
||||
#define sqlite3_backup_finish sqlite3_api->backup_finish
|
||||
#define sqlite3_backup_init sqlite3_api->backup_init
|
||||
#define sqlite3_backup_pagecount sqlite3_api->backup_pagecount
|
||||
#define sqlite3_backup_remaining sqlite3_api->backup_remaining
|
||||
#define sqlite3_backup_step sqlite3_api->backup_step
|
||||
#define sqlite3_compileoption_get sqlite3_api->compileoption_get
|
||||
#define sqlite3_compileoption_used sqlite3_api->compileoption_used
|
||||
#define sqlite3_create_function_v2 sqlite3_api->create_function_v2
|
||||
#define sqlite3_db_config sqlite3_api->db_config
|
||||
#define sqlite3_db_mutex sqlite3_api->db_mutex
|
||||
#define sqlite3_db_status sqlite3_api->db_status
|
||||
#define sqlite3_extended_errcode sqlite3_api->extended_errcode
|
||||
#define sqlite3_log sqlite3_api->log
|
||||
#define sqlite3_soft_heap_limit64 sqlite3_api->soft_heap_limit64
|
||||
#define sqlite3_sourceid sqlite3_api->sourceid
|
||||
#define sqlite3_stmt_status sqlite3_api->stmt_status
|
||||
#define sqlite3_strnicmp sqlite3_api->strnicmp
|
||||
#define sqlite3_unlock_notify sqlite3_api->unlock_notify
|
||||
#define sqlite3_wal_autocheckpoint sqlite3_api->wal_autocheckpoint
|
||||
#define sqlite3_wal_checkpoint sqlite3_api->wal_checkpoint
|
||||
#define sqlite3_wal_hook sqlite3_api->wal_hook
|
||||
#define sqlite3_blob_reopen sqlite3_api->blob_reopen
|
||||
#define sqlite3_vtab_config sqlite3_api->vtab_config
|
||||
#define sqlite3_vtab_on_conflict sqlite3_api->vtab_on_conflict
|
||||
/* Version 3.7.16 and later */
|
||||
#define sqlite3_close_v2 sqlite3_api->close_v2
|
||||
#define sqlite3_db_filename sqlite3_api->db_filename
|
||||
#define sqlite3_db_readonly sqlite3_api->db_readonly
|
||||
#define sqlite3_db_release_memory sqlite3_api->db_release_memory
|
||||
#define sqlite3_errstr sqlite3_api->errstr
|
||||
#define sqlite3_stmt_busy sqlite3_api->stmt_busy
|
||||
#define sqlite3_stmt_readonly sqlite3_api->stmt_readonly
|
||||
#define sqlite3_stricmp sqlite3_api->stricmp
|
||||
#define sqlite3_uri_boolean sqlite3_api->uri_boolean
|
||||
#define sqlite3_uri_int64 sqlite3_api->uri_int64
|
||||
#define sqlite3_uri_parameter sqlite3_api->uri_parameter
|
||||
#define sqlite3_uri_vsnprintf sqlite3_api->vsnprintf
|
||||
#define sqlite3_wal_checkpoint_v2 sqlite3_api->wal_checkpoint_v2
|
||||
/* Version 3.8.7 and later */
|
||||
#define sqlite3_auto_extension sqlite3_api->auto_extension
|
||||
#define sqlite3_bind_blob64 sqlite3_api->bind_blob64
|
||||
#define sqlite3_bind_text64 sqlite3_api->bind_text64
|
||||
#define sqlite3_cancel_auto_extension sqlite3_api->cancel_auto_extension
|
||||
#define sqlite3_load_extension sqlite3_api->load_extension
|
||||
#define sqlite3_malloc64 sqlite3_api->malloc64
|
||||
#define sqlite3_msize sqlite3_api->msize
|
||||
#define sqlite3_realloc64 sqlite3_api->realloc64
|
||||
#define sqlite3_reset_auto_extension sqlite3_api->reset_auto_extension
|
||||
#define sqlite3_result_blob64 sqlite3_api->result_blob64
|
||||
#define sqlite3_result_text64 sqlite3_api->result_text64
|
||||
#define sqlite3_strglob sqlite3_api->strglob
|
||||
#endif /* SQLITE_CORE */
|
||||
|
||||
#ifndef SQLITE_CORE
|
||||
/* This case when the file really is being compiled as a loadable
|
||||
** extension */
|
||||
# define SQLITE_EXTENSION_INIT1 const sqlite3_api_routines *sqlite3_api=0;
|
||||
# define SQLITE_EXTENSION_INIT2(v) sqlite3_api=v;
|
||||
# define SQLITE_EXTENSION_INIT3 \
|
||||
extern const sqlite3_api_routines *sqlite3_api;
|
||||
#else
|
||||
/* This case when the file is being statically linked into the
|
||||
** application */
|
||||
# define SQLITE_EXTENSION_INIT1 /*no-op*/
|
||||
# define SQLITE_EXTENSION_INIT2(v) (void)v; /* unused parameter */
|
||||
# define SQLITE_EXTENSION_INIT3 /*no-op*/
|
||||
#endif
|
||||
|
||||
#endif /* _SQLITE3EXT_H_ */
|
@ -3,6 +3,14 @@
|
||||
|
||||
[](https://gitter.im/mamedev/mame?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
||||
|
||||
Build status for tiny build only, containing just core parts of project
|
||||
|
||||
| OS/Compiler | Status |
|
||||
| ------------- |:-------------:|
|
||||
|Linux GCC / OSX Clang| [](https://travis-ci.org/mamedev/mame) |
|
||||
|Windows MinGW | [](https://tea-ci.org/mamedev/mame) |
|
||||
|
||||
|
||||
What is MAME?
|
||||
=============
|
||||
|
||||
|
@ -4,8 +4,8 @@
|
||||
-->
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="org.mamedev.mame"
|
||||
android:versionCode="173"
|
||||
android:versionName="0.173"
|
||||
android:versionCode="174"
|
||||
android:versionName="0.174"
|
||||
android:installLocation="auto">
|
||||
|
||||
<!-- Android 4.0 -->
|
||||
|
@ -93,7 +93,7 @@
|
||||
{ "type": "float", "name": "scanline_height", "text": "Individual Scanline Scale", "default": 1.00, "max": 4.00, "min": 0.0, "step": 0.01, "format": "%1.2f", "screen": "crt" },
|
||||
{ "type": "float", "name": "scanline_variation", "text": "Scanline Variation", "default": 1.00, "max": 4.00, "min": 0.0, "step": 0.01, "format": "%1.2f", "screen": "crt" },
|
||||
{ "type": "float", "name": "scanline_bright_scale", "text": "Scanline Brightness Scale", "default": 2.00, "max": 4.00, "min": 0.0, "step": 0.01, "format": "%1.2f", "screen": "crt" },
|
||||
{ "type": "float", "name": "scanline_bright_offset", "text": "Scanline Brightness Offset", "default": 4.00, "max": 4.00, "min": 0.0, "step": 0.01, "format": "%1.2f", "screen": "crt" },
|
||||
{ "type": "float", "name": "scanline_bright_offset", "text": "Scanline Brightness Offset", "default": 1.50, "max": 4.00, "min": 0.0, "step": 0.01, "format": "%1.2f", "screen": "crt" },
|
||||
{ "type": "float", "name": "scanline_jitter_amount", "text": "Scanline Jitter Amount", "default": 0.00, "max": 4.00, "min": 0.0, "step": 0.01, "format": "%1.2f", "screen": "crt" },
|
||||
{ "type": "float", "name": "scanline_variation", "text": "Scanline Variation", "default": 1.00, "max": 4.00, "min": 0.0, "step": 0.01, "format": "%1.2f", "screen": "crt" },
|
||||
|
||||
|
@ -79,7 +79,7 @@
|
||||
"output": "internal"
|
||||
},
|
||||
{
|
||||
"effect": "misc/saturation",
|
||||
"effect": "pillarbox_left_horizontal/offset_sat",
|
||||
"name": "Saturation Pass",
|
||||
"disablewhen": [
|
||||
{ "type": "slider", "condition": "equal", "name": "saturation", "value": 100 }
|
||||
|
@ -79,7 +79,7 @@
|
||||
"output": "internal"
|
||||
},
|
||||
{
|
||||
"effect": "misc/saturation",
|
||||
"effect": "pillarbox_left_vertical/offset_sat",
|
||||
"name": "Saturation Pass",
|
||||
"disablewhen": [
|
||||
{ "type": "slider", "condition": "equal", "name": "saturation", "value": 100 }
|
||||
|
@ -79,7 +79,7 @@
|
||||
"output": "internal"
|
||||
},
|
||||
{
|
||||
"effect": "misc/saturation",
|
||||
"effect": "pillarbox_right_horizontal/offset_sat",
|
||||
"name": "Saturation Pass",
|
||||
"disablewhen": [
|
||||
{ "type": "slider", "condition": "equal", "name": "saturation", "value": 100 }
|
||||
|
@ -79,7 +79,7 @@
|
||||
"output": "internal"
|
||||
},
|
||||
{
|
||||
"effect": "misc/saturation",
|
||||
"effect": "pillarbox_right_vertical/offset_sat",
|
||||
"name": "Saturation Pass",
|
||||
"disablewhen": [
|
||||
{ "type": "slider", "condition": "equal", "name": "saturation", "value": 100 }
|
||||
|
34
bgfx/effects/pillarbox_left_horizontal/offset_sat.json
Normal file
34
bgfx/effects/pillarbox_left_horizontal/offset_sat.json
Normal file
@ -0,0 +1,34 @@
|
||||
// license:BSD-3-Clause
|
||||
// copyright-holders:Ryan Holtz
|
||||
//============================================================
|
||||
//
|
||||
// offset_sat.json: Applies saturation to an image.
|
||||
//
|
||||
// Additionally, takes only a portion of the image, as
|
||||
// this instance is intended for the left-hand pillarbox
|
||||
// when displaying 4:3 content on a 16:9 screen.
|
||||
//
|
||||
//============================================================
|
||||
{
|
||||
"blend": {
|
||||
"equation": "add",
|
||||
"srcColor": "srcalpha",
|
||||
"dstColor": "1-srcalpha",
|
||||
"srcAlpha": "srcalpha",
|
||||
"dstAlpha": "1-srcalpha"
|
||||
},
|
||||
"depth": {
|
||||
"function": "always"
|
||||
},
|
||||
"cull": { "mode": "none" },
|
||||
"write": {
|
||||
"rgb": true,
|
||||
"alpha": true
|
||||
},
|
||||
"vertex": "chains/pillarbox_left_horizontal/vs_offset_sat",
|
||||
"fragment": "chains/pillarbox_left_horizontal/fs_offset_sat",
|
||||
"uniforms": [
|
||||
{ "name": "s_tex", "type": "int", "values": [ 1.0 ] },
|
||||
{ "name": "u_saturation", "type": "vec4", "values": [ 1.0, 0.0, 0.0, 0.0 ] }
|
||||
]
|
||||
}
|
34
bgfx/effects/pillarbox_left_vertical/offset_sat.json
Normal file
34
bgfx/effects/pillarbox_left_vertical/offset_sat.json
Normal file
@ -0,0 +1,34 @@
|
||||
// license:BSD-3-Clause
|
||||
// copyright-holders:Ryan Holtz
|
||||
//============================================================
|
||||
//
|
||||
// offset_sat.json: Applies saturation to an image.
|
||||
//
|
||||
// Additionally, takes only a portion of the image, as
|
||||
// this instance is intended for the left-hand pillarbox
|
||||
// when displaying 3:4 content on a 16:9 screen.
|
||||
//
|
||||
//============================================================
|
||||
{
|
||||
"blend": {
|
||||
"equation": "add",
|
||||
"srcColor": "srcalpha",
|
||||
"dstColor": "1-srcalpha",
|
||||
"srcAlpha": "srcalpha",
|
||||
"dstAlpha": "1-srcalpha"
|
||||
},
|
||||
"depth": {
|
||||
"function": "always"
|
||||
},
|
||||
"cull": { "mode": "none" },
|
||||
"write": {
|
||||
"rgb": true,
|
||||
"alpha": true
|
||||
},
|
||||
"vertex": "chains/pillarbox_left_vertical/vs_offset_sat",
|
||||
"fragment": "chains/pillarbox_left_vertical/fs_offset_sat",
|
||||
"uniforms": [
|
||||
{ "name": "s_tex", "type": "int", "values": [ 1.0 ] },
|
||||
{ "name": "u_saturation", "type": "vec4", "values": [ 1.0, 0.0, 0.0, 0.0 ] }
|
||||
]
|
||||
}
|
34
bgfx/effects/pillarbox_right_horizontal/offset_sat.json
Normal file
34
bgfx/effects/pillarbox_right_horizontal/offset_sat.json
Normal file
@ -0,0 +1,34 @@
|
||||
// license:BSD-3-Clause
|
||||
// copyright-holders:Ryan Holtz
|
||||
//============================================================
|
||||
//
|
||||
// offset_sat.json: Applies saturation to an image.
|
||||
//
|
||||
// Additionally, takes only a portion of the image, as
|
||||
// this instance is intended for the right-hand pillarbox
|
||||
// when displaying 4:3 content on a 16:9 screen.
|
||||
//
|
||||
//============================================================
|
||||
{
|
||||
"blend": {
|
||||
"equation": "add",
|
||||
"srcColor": "srcalpha",
|
||||
"dstColor": "1-srcalpha",
|
||||
"srcAlpha": "srcalpha",
|
||||
"dstAlpha": "1-srcalpha"
|
||||
},
|
||||
"depth": {
|
||||
"function": "always"
|
||||
},
|
||||
"cull": { "mode": "none" },
|
||||
"write": {
|
||||
"rgb": true,
|
||||
"alpha": true
|
||||
},
|
||||
"vertex": "chains/pillarbox_right_horizontal/vs_offset_sat",
|
||||
"fragment": "chains/pillarbox_right_horizontal/fs_offset_sat",
|
||||
"uniforms": [
|
||||
{ "name": "s_tex", "type": "int", "values": [ 1.0 ] },
|
||||
{ "name": "u_saturation", "type": "vec4", "values": [ 1.0, 0.0, 0.0, 0.0 ] }
|
||||
]
|
||||
}
|
34
bgfx/effects/pillarbox_right_vertical/offset_sat.json
Normal file
34
bgfx/effects/pillarbox_right_vertical/offset_sat.json
Normal file
@ -0,0 +1,34 @@
|
||||
// license:BSD-3-Clause
|
||||
// copyright-holders:Ryan Holtz
|
||||
//============================================================
|
||||
//
|
||||
// offset_sat.json: Applies saturation to an image.
|
||||
//
|
||||
// Additionally, takes only a portion of the image, as
|
||||
// this instance is intended for the right-hand pillarbox
|
||||
// when displaying 3:4 content on a 16:9 screen.
|
||||
//
|
||||
//============================================================
|
||||
{
|
||||
"blend": {
|
||||
"equation": "add",
|
||||
"srcColor": "srcalpha",
|
||||
"dstColor": "1-srcalpha",
|
||||
"srcAlpha": "srcalpha",
|
||||
"dstAlpha": "1-srcalpha"
|
||||
},
|
||||
"depth": {
|
||||
"function": "always"
|
||||
},
|
||||
"cull": { "mode": "none" },
|
||||
"write": {
|
||||
"rgb": true,
|
||||
"alpha": true
|
||||
},
|
||||
"vertex": "chains/pillarbox_right_vertical/vs_offset_sat",
|
||||
"fragment": "chains/pillarbox_right_vertical/fs_offset_sat",
|
||||
"uniforms": [
|
||||
{ "name": "s_tex", "type": "int", "values": [ 1.0 ] },
|
||||
{ "name": "u_saturation", "type": "vec4", "values": [ 1.0, 0.0, 0.0, 0.0 ] }
|
||||
]
|
||||
}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user