Compare commits
137 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5dc4c42958 | |||
|
|
02b773b4ae | ||
|
|
f4665e155e | ||
|
|
dda695e95f | ||
|
|
4a8ed6a67a | ||
|
|
453a966890 | ||
|
|
0be2bebef0 | ||
|
|
c10a777285 | ||
|
|
938655a90b | ||
|
|
497c8f9d47 | ||
|
|
ee38035634 | ||
|
|
249a26e829 | ||
|
|
7d589eb444 | ||
|
|
b00cd02629 | ||
|
|
5460758eb0 | ||
|
|
3835c65eab | ||
|
|
ab7243ca59 | ||
|
|
b89da87b10 | ||
|
|
effd225a84 | ||
|
|
d2de0ef10d | ||
|
|
3c2de4bd59 | ||
|
|
5c737b040a | ||
|
|
7fe2a71c13 | ||
|
|
2fa5378a1a | ||
|
|
26a655a503 | ||
|
|
74cca2d7d3 | ||
|
|
a7df1b46a4 | ||
|
|
31738a5b37 | ||
|
|
a0857ae0b8 | ||
|
|
7e72756c52 | ||
|
|
a3a78eec20 | ||
|
|
57ca6c191e | ||
|
|
40e994bc88 | ||
|
|
3c8d024bdb | ||
|
|
2186a3fe21 | ||
|
|
5dcf698a91 | ||
|
|
304be42986 | ||
|
|
00b4d3abd1 | ||
|
|
9dd92a7d49 | ||
|
|
4df9f90385 | ||
|
|
8471ad1aea | ||
|
|
a0e46fce11 | ||
|
|
14cbc7b2dc | ||
|
|
c62aacd250 | ||
|
|
d159befb13 | ||
|
|
0bf296d46a | ||
|
|
5743cd5c91 | ||
|
|
76c67169ed | ||
|
|
aa4afc5b14 | ||
|
|
5b3bfb21fb | ||
|
|
6186e02a23 | ||
|
|
bdcb7cc12b | ||
|
|
d130dc5471 | ||
|
|
be35cf850b | ||
|
|
05dbbc1820 | ||
|
|
795af921cc | ||
|
|
fae1cabb51 | ||
|
|
cfd4df6988 | ||
|
|
c7a0707137 | ||
|
|
701a0e4ae5 | ||
|
|
eeba56c81b | ||
|
|
48842f0979 | ||
|
|
f3bb11ef99 | ||
|
|
36c308bf57 | ||
|
|
bd43d374dc | ||
|
|
3019ac3c2c | ||
|
|
5e4bcebc6f | ||
|
|
17124aa789 | ||
|
|
2ad9683f54 | ||
|
|
d1d28aacc9 | ||
|
|
15e2c23eea | ||
|
|
7629853586 | ||
|
|
e618271e11 | ||
|
|
d81f7e1c9d | ||
|
|
7aadf19f34 | ||
|
|
f7cf119db7 | ||
|
|
a96a2f3d78 | ||
|
|
90cd4bc238 | ||
|
|
ba338b145c | ||
|
|
87deb68c46 | ||
|
|
457f3b25bc | ||
|
|
98b5cc434d | ||
|
|
7290b1fffe | ||
|
|
26ef4c4f5e | ||
|
|
2d509d385b | ||
|
|
3b217e7e42 | ||
|
|
3c4098da84 | ||
|
|
997c7aefd2 | ||
|
|
2e346b54ac | ||
|
|
09c4e7a8c1 | ||
|
|
4f20c881ab | ||
|
|
f441f7f99d | ||
|
|
8ca802658c | ||
|
|
9004743fc4 | ||
|
|
0961039dd7 | ||
|
|
7c0550b8ad | ||
|
|
e0f0e180a3 | ||
|
|
656c6a0d68 | ||
|
|
16ab1fd6c0 | ||
|
|
2aef08d0a5 | ||
|
|
f87cd114d7 | ||
|
|
7bb5dd4982 | ||
|
|
5b50a56e56 | ||
|
|
8242f5ac06 | ||
|
|
692d4958e8 | ||
|
|
70afceec42 | ||
|
|
301db648da | ||
|
|
b589ea521d | ||
|
|
35ab252494 | ||
|
|
160184d2dd | ||
|
|
b9fc931752 | ||
|
|
72135d9a7f | ||
|
|
7305257b95 | ||
|
|
e347779446 | ||
|
|
4125aa515d | ||
|
|
ed23d140df | ||
|
|
8fb371b3fc | ||
|
|
78b44c851b | ||
|
|
b35c9e827c | ||
|
|
f8f229fa00 | ||
|
|
175139968a | ||
|
|
c44d568a8b | ||
|
|
a70a135192 | ||
|
|
4fddb87839 | ||
|
|
4305796277 | ||
|
|
953d9e9771 | ||
|
|
2f6419f19b | ||
|
|
9218082df1 | ||
|
|
d02fa17be2 | ||
|
|
98bb79893e | ||
|
|
7233a7c7de | ||
|
|
9f4407d8ef | ||
|
|
d9d0ebb4c0 | ||
|
|
558a4f4f3b | ||
|
|
d2e93dcba6 | ||
|
|
6db0aa2095 | ||
|
|
14ac45d285 |
6
.gitignore
vendored
Normal file
6
.gitignore
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
# Folders created at compilation
|
||||
bin/
|
||||
lib/
|
||||
|
||||
# Folders created at documentation generation
|
||||
doc/
|
||||
17
.travis.yml
Normal file
17
.travis.yml
Normal file
@@ -0,0 +1,17 @@
|
||||
language: cpp
|
||||
compiler:
|
||||
- gcc
|
||||
- clang
|
||||
|
||||
# Travis VMs are 64-bit but we compile both for 32 and 64 bit. To enable the
|
||||
# 32-bit builds to work, we need gcc-multilib.
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- gcc-multilib
|
||||
- g++-multilib
|
||||
|
||||
# Enable container-based builds.
|
||||
sudo: false
|
||||
|
||||
script: mkdir build && cd build && cmake .. && make -j2
|
||||
@@ -9,7 +9,7 @@ set(CMAKE_BUILD_TYPE "Release" CACHE STRING "")
|
||||
|
||||
project(squirrel C CXX)
|
||||
|
||||
include_directories(${CMAKE_SOURCE_DIR}/include)
|
||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
|
||||
|
||||
if(CMAKE_COMPILER_IS_GNUCXX)
|
||||
set(SQ_FLAGS -fno-exceptions -fno-strict-aliasing -Wall -Wextra -pedantic -Wcast-qual)
|
||||
@@ -33,25 +33,28 @@ if(CMAKE_COMPILER_IS_GNUCXX)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti -std=c++0x")
|
||||
elseif(MSVC)
|
||||
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
|
||||
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
|
||||
endif()
|
||||
|
||||
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
|
||||
add_definitions(-D_SQ64)
|
||||
endif()
|
||||
|
||||
if(NOT DEFINED INSTALL_BIN_DIR)
|
||||
set(INSTALL_BIN_DIR bin)
|
||||
endif()
|
||||
if(NOT DEFINED SQ_DISABLE_INSTALLER)
|
||||
if(NOT DEFINED INSTALL_BIN_DIR)
|
||||
set(INSTALL_BIN_DIR bin)
|
||||
endif()
|
||||
|
||||
if(NOT DEFINED INSTALL_LIB_DIR)
|
||||
set(INSTALL_LIB_DIR lib)
|
||||
if(NOT DEFINED INSTALL_LIB_DIR)
|
||||
set(INSTALL_LIB_DIR lib)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
add_subdirectory(squirrel)
|
||||
add_subdirectory(sqstdlib)
|
||||
add_subdirectory(sq)
|
||||
|
||||
if(NOT WIN32)
|
||||
if(NOT WIN32 AND NOT DEFINED DISABLE_DYNAMIC)
|
||||
set_target_properties(squirrel sqstdlib PROPERTIES SOVERSION 0 VERSION 0.0.0)
|
||||
endif()
|
||||
|
||||
|
||||
7
COMPILE
7
COMPILE
@@ -77,3 +77,10 @@ for 64 bits systems
|
||||
VISUAL C++ USERS
|
||||
.........................................................
|
||||
Open squirrel.dsw from the root project directory and build(dho!)
|
||||
|
||||
DOCUMENTATION GENERATION
|
||||
.........................................................
|
||||
To be able to compile the documentation, make sure that you have Python
|
||||
installed and the packages sphinx and sphinx_rtd_theme. Browse into doc/
|
||||
and use either the Makefile for GCC-based platforms or make.bat for
|
||||
Windows platforms.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
Copyright (c) 2003-2016 Alberto Demichelis
|
||||
Copyright (c) 2003-2017 Alberto Demichelis
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
||||
5
HISTORY
5
HISTORY
@@ -1,3 +1,8 @@
|
||||
***version 3.1.1 stable***
|
||||
-sq_gettypetag doesn't set last error(it's treated as SQBool function but keeps a SQRESULT for backward compatibility)
|
||||
-fixed _set method in userdata deelegates
|
||||
-fixed some warnings
|
||||
|
||||
***version 3.1 stable***
|
||||
-added slice range for tolower and toupper
|
||||
-added startswith() and endswith() in string lib
|
||||
|
||||
2
README
2
README
@@ -12,7 +12,7 @@ The following compilers have been confirmed to be working:
|
||||
7.1 v
|
||||
8.0
|
||||
9.0
|
||||
10.0
|
||||
10.0
|
||||
12.0 ---
|
||||
MinGW gcc 3.2 (mingw special 20020817-1)
|
||||
Cygnus gcc 3.2
|
||||
|
||||
28
appveyor.yml
Normal file
28
appveyor.yml
Normal file
@@ -0,0 +1,28 @@
|
||||
version: 0.0.{build}
|
||||
|
||||
platform:
|
||||
- x86
|
||||
- x64
|
||||
|
||||
configuration:
|
||||
- Debug
|
||||
- Release
|
||||
|
||||
clone_folder: c:\sq
|
||||
|
||||
before_build:
|
||||
- mkdir build
|
||||
- cd build
|
||||
- call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" %platform%
|
||||
- echo %platform%
|
||||
- if %platform%==X64 (cmake .. -G "Visual Studio 14 2015 Win64")
|
||||
- if %platform%==x86 (cmake .. -G "Visual Studio 14 2015")
|
||||
|
||||
build_script:
|
||||
- cmake --build . --config %configuration% -- /logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll"
|
||||
|
||||
artifacts:
|
||||
- path: build\*\%configuration%\*.exe
|
||||
- path: build\*\%configuration%\*.dll
|
||||
|
||||
test: off
|
||||
526
doc/make.bat
526
doc/make.bat
@@ -1,263 +1,263 @@
|
||||
@ECHO OFF
|
||||
|
||||
REM Command file for Sphinx documentation
|
||||
|
||||
if "%SPHINXBUILD%" == "" (
|
||||
set SPHINXBUILD=sphinx-build
|
||||
)
|
||||
set BUILDDIR=build
|
||||
set ALLSPHINXOPTS=-d %BUILDDIR%/doctrees %SPHINXOPTS% source
|
||||
set I18NSPHINXOPTS=%SPHINXOPTS% source
|
||||
if NOT "%PAPER%" == "" (
|
||||
set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS%
|
||||
set I18NSPHINXOPTS=-D latex_paper_size=%PAPER% %I18NSPHINXOPTS%
|
||||
)
|
||||
|
||||
if "%1" == "" goto help
|
||||
|
||||
if "%1" == "help" (
|
||||
:help
|
||||
echo.Please use `make ^<target^>` where ^<target^> is one of
|
||||
echo. html to make standalone HTML files
|
||||
echo. dirhtml to make HTML files named index.html in directories
|
||||
echo. singlehtml to make a single large HTML file
|
||||
echo. pickle to make pickle files
|
||||
echo. json to make JSON files
|
||||
echo. htmlhelp to make HTML files and a HTML help project
|
||||
echo. qthelp to make HTML files and a qthelp project
|
||||
echo. devhelp to make HTML files and a Devhelp project
|
||||
echo. epub to make an epub
|
||||
echo. latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter
|
||||
echo. text to make text files
|
||||
echo. man to make manual pages
|
||||
echo. texinfo to make Texinfo files
|
||||
echo. gettext to make PO message catalogs
|
||||
echo. changes to make an overview over all changed/added/deprecated items
|
||||
echo. xml to make Docutils-native XML files
|
||||
echo. pseudoxml to make pseudoxml-XML files for display purposes
|
||||
echo. linkcheck to check all external links for integrity
|
||||
echo. doctest to run all doctests embedded in the documentation if enabled
|
||||
echo. coverage to run coverage check of the documentation if enabled
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "clean" (
|
||||
for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%i
|
||||
del /q /s %BUILDDIR%\*
|
||||
goto end
|
||||
)
|
||||
|
||||
|
||||
REM Check if sphinx-build is available and fallback to Python version if any
|
||||
%SPHINXBUILD% 1>NUL 2>NUL
|
||||
if errorlevel 9009 goto sphinx_python
|
||||
goto sphinx_ok
|
||||
|
||||
:sphinx_python
|
||||
|
||||
set SPHINXBUILD=python -m sphinx.__init__
|
||||
%SPHINXBUILD% 2> nul
|
||||
if errorlevel 9009 (
|
||||
echo.
|
||||
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
|
||||
echo.installed, then set the SPHINXBUILD environment variable to point
|
||||
echo.to the full path of the 'sphinx-build' executable. Alternatively you
|
||||
echo.may add the Sphinx directory to PATH.
|
||||
echo.
|
||||
echo.If you don't have Sphinx installed, grab it from
|
||||
echo.http://sphinx-doc.org/
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
:sphinx_ok
|
||||
|
||||
|
||||
if "%1" == "html" (
|
||||
%SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.Build finished. The HTML pages are in %BUILDDIR%/html.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "dirhtml" (
|
||||
%SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "singlehtml" (
|
||||
%SPHINXBUILD% -b singlehtml %ALLSPHINXOPTS% %BUILDDIR%/singlehtml
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.Build finished. The HTML pages are in %BUILDDIR%/singlehtml.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "pickle" (
|
||||
%SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickle
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.Build finished; now you can process the pickle files.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "json" (
|
||||
%SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/json
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.Build finished; now you can process the JSON files.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "htmlhelp" (
|
||||
%SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.Build finished; now you can run HTML Help Workshop with the ^
|
||||
.hhp project file in %BUILDDIR%/htmlhelp.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "qthelp" (
|
||||
%SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelp
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.Build finished; now you can run "qcollectiongenerator" with the ^
|
||||
.qhcp project file in %BUILDDIR%/qthelp, like this:
|
||||
echo.^> qcollectiongenerator %BUILDDIR%\qthelp\testy_sphinxy.qhcp
|
||||
echo.To view the help file:
|
||||
echo.^> assistant -collectionFile %BUILDDIR%\qthelp\testy_sphinxy.ghc
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "devhelp" (
|
||||
%SPHINXBUILD% -b devhelp %ALLSPHINXOPTS% %BUILDDIR%/devhelp
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.Build finished.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "epub" (
|
||||
%SPHINXBUILD% -b epub %ALLSPHINXOPTS% %BUILDDIR%/epub
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.Build finished. The epub file is in %BUILDDIR%/epub.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "latex" (
|
||||
%SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.Build finished; the LaTeX files are in %BUILDDIR%/latex.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "latexpdf" (
|
||||
%SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex
|
||||
cd %BUILDDIR%/latex
|
||||
make all-pdf
|
||||
cd %~dp0
|
||||
echo.
|
||||
echo.Build finished; the PDF files are in %BUILDDIR%/latex.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "latexpdfja" (
|
||||
%SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex
|
||||
cd %BUILDDIR%/latex
|
||||
make all-pdf-ja
|
||||
cd %~dp0
|
||||
echo.
|
||||
echo.Build finished; the PDF files are in %BUILDDIR%/latex.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "text" (
|
||||
%SPHINXBUILD% -b text %ALLSPHINXOPTS% %BUILDDIR%/text
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.Build finished. The text files are in %BUILDDIR%/text.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "man" (
|
||||
%SPHINXBUILD% -b man %ALLSPHINXOPTS% %BUILDDIR%/man
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.Build finished. The manual pages are in %BUILDDIR%/man.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "texinfo" (
|
||||
%SPHINXBUILD% -b texinfo %ALLSPHINXOPTS% %BUILDDIR%/texinfo
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.Build finished. The Texinfo files are in %BUILDDIR%/texinfo.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "gettext" (
|
||||
%SPHINXBUILD% -b gettext %I18NSPHINXOPTS% %BUILDDIR%/locale
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.Build finished. The message catalogs are in %BUILDDIR%/locale.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "changes" (
|
||||
%SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changes
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.The overview file is in %BUILDDIR%/changes.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "linkcheck" (
|
||||
%SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheck
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.Link check complete; look for any errors in the above output ^
|
||||
or in %BUILDDIR%/linkcheck/output.txt.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "doctest" (
|
||||
%SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctest
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.Testing of doctests in the sources finished, look at the ^
|
||||
results in %BUILDDIR%/doctest/output.txt.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "coverage" (
|
||||
%SPHINXBUILD% -b coverage %ALLSPHINXOPTS% %BUILDDIR%/coverage
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.Testing of coverage in the sources finished, look at the ^
|
||||
results in %BUILDDIR%/coverage/python.txt.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "xml" (
|
||||
%SPHINXBUILD% -b xml %ALLSPHINXOPTS% %BUILDDIR%/xml
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.Build finished. The XML files are in %BUILDDIR%/xml.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "pseudoxml" (
|
||||
%SPHINXBUILD% -b pseudoxml %ALLSPHINXOPTS% %BUILDDIR%/pseudoxml
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.Build finished. The pseudo-XML files are in %BUILDDIR%/pseudoxml.
|
||||
goto end
|
||||
)
|
||||
|
||||
:end
|
||||
@ECHO OFF
|
||||
|
||||
REM Command file for Sphinx documentation
|
||||
|
||||
if "%SPHINXBUILD%" == "" (
|
||||
set SPHINXBUILD=sphinx-build
|
||||
)
|
||||
set BUILDDIR=build
|
||||
set ALLSPHINXOPTS=-d %BUILDDIR%/doctrees %SPHINXOPTS% source
|
||||
set I18NSPHINXOPTS=%SPHINXOPTS% source
|
||||
if NOT "%PAPER%" == "" (
|
||||
set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS%
|
||||
set I18NSPHINXOPTS=-D latex_paper_size=%PAPER% %I18NSPHINXOPTS%
|
||||
)
|
||||
|
||||
if "%1" == "" goto help
|
||||
|
||||
if "%1" == "help" (
|
||||
:help
|
||||
echo.Please use `make ^<target^>` where ^<target^> is one of
|
||||
echo. html to make standalone HTML files
|
||||
echo. dirhtml to make HTML files named index.html in directories
|
||||
echo. singlehtml to make a single large HTML file
|
||||
echo. pickle to make pickle files
|
||||
echo. json to make JSON files
|
||||
echo. htmlhelp to make HTML files and a HTML help project
|
||||
echo. qthelp to make HTML files and a qthelp project
|
||||
echo. devhelp to make HTML files and a Devhelp project
|
||||
echo. epub to make an epub
|
||||
echo. latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter
|
||||
echo. text to make text files
|
||||
echo. man to make manual pages
|
||||
echo. texinfo to make Texinfo files
|
||||
echo. gettext to make PO message catalogs
|
||||
echo. changes to make an overview over all changed/added/deprecated items
|
||||
echo. xml to make Docutils-native XML files
|
||||
echo. pseudoxml to make pseudoxml-XML files for display purposes
|
||||
echo. linkcheck to check all external links for integrity
|
||||
echo. doctest to run all doctests embedded in the documentation if enabled
|
||||
echo. coverage to run coverage check of the documentation if enabled
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "clean" (
|
||||
for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%i
|
||||
del /q /s %BUILDDIR%\*
|
||||
goto end
|
||||
)
|
||||
|
||||
|
||||
REM Check if sphinx-build is available and fallback to Python version if any
|
||||
%SPHINXBUILD% 1>NUL 2>NUL
|
||||
if errorlevel 9009 goto sphinx_python
|
||||
goto sphinx_ok
|
||||
|
||||
:sphinx_python
|
||||
|
||||
set SPHINXBUILD=python -m sphinx.__init__
|
||||
%SPHINXBUILD% 2> nul
|
||||
if errorlevel 9009 (
|
||||
echo.
|
||||
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
|
||||
echo.installed, then set the SPHINXBUILD environment variable to point
|
||||
echo.to the full path of the 'sphinx-build' executable. Alternatively you
|
||||
echo.may add the Sphinx directory to PATH.
|
||||
echo.
|
||||
echo.If you don't have Sphinx installed, grab it from
|
||||
echo.http://sphinx-doc.org/
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
:sphinx_ok
|
||||
|
||||
|
||||
if "%1" == "html" (
|
||||
%SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.Build finished. The HTML pages are in %BUILDDIR%/html.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "dirhtml" (
|
||||
%SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "singlehtml" (
|
||||
%SPHINXBUILD% -b singlehtml %ALLSPHINXOPTS% %BUILDDIR%/singlehtml
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.Build finished. The HTML pages are in %BUILDDIR%/singlehtml.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "pickle" (
|
||||
%SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickle
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.Build finished; now you can process the pickle files.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "json" (
|
||||
%SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/json
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.Build finished; now you can process the JSON files.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "htmlhelp" (
|
||||
%SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.Build finished; now you can run HTML Help Workshop with the ^
|
||||
.hhp project file in %BUILDDIR%/htmlhelp.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "qthelp" (
|
||||
%SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelp
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.Build finished; now you can run "qcollectiongenerator" with the ^
|
||||
.qhcp project file in %BUILDDIR%/qthelp, like this:
|
||||
echo.^> qcollectiongenerator %BUILDDIR%\qthelp\testy_sphinxy.qhcp
|
||||
echo.To view the help file:
|
||||
echo.^> assistant -collectionFile %BUILDDIR%\qthelp\testy_sphinxy.ghc
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "devhelp" (
|
||||
%SPHINXBUILD% -b devhelp %ALLSPHINXOPTS% %BUILDDIR%/devhelp
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.Build finished.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "epub" (
|
||||
%SPHINXBUILD% -b epub %ALLSPHINXOPTS% %BUILDDIR%/epub
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.Build finished. The epub file is in %BUILDDIR%/epub.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "latex" (
|
||||
%SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.Build finished; the LaTeX files are in %BUILDDIR%/latex.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "latexpdf" (
|
||||
%SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex
|
||||
cd %BUILDDIR%/latex
|
||||
make all-pdf
|
||||
cd %~dp0
|
||||
echo.
|
||||
echo.Build finished; the PDF files are in %BUILDDIR%/latex.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "latexpdfja" (
|
||||
%SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex
|
||||
cd %BUILDDIR%/latex
|
||||
make all-pdf-ja
|
||||
cd %~dp0
|
||||
echo.
|
||||
echo.Build finished; the PDF files are in %BUILDDIR%/latex.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "text" (
|
||||
%SPHINXBUILD% -b text %ALLSPHINXOPTS% %BUILDDIR%/text
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.Build finished. The text files are in %BUILDDIR%/text.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "man" (
|
||||
%SPHINXBUILD% -b man %ALLSPHINXOPTS% %BUILDDIR%/man
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.Build finished. The manual pages are in %BUILDDIR%/man.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "texinfo" (
|
||||
%SPHINXBUILD% -b texinfo %ALLSPHINXOPTS% %BUILDDIR%/texinfo
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.Build finished. The Texinfo files are in %BUILDDIR%/texinfo.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "gettext" (
|
||||
%SPHINXBUILD% -b gettext %I18NSPHINXOPTS% %BUILDDIR%/locale
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.Build finished. The message catalogs are in %BUILDDIR%/locale.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "changes" (
|
||||
%SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changes
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.The overview file is in %BUILDDIR%/changes.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "linkcheck" (
|
||||
%SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheck
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.Link check complete; look for any errors in the above output ^
|
||||
or in %BUILDDIR%/linkcheck/output.txt.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "doctest" (
|
||||
%SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctest
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.Testing of doctests in the sources finished, look at the ^
|
||||
results in %BUILDDIR%/doctest/output.txt.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "coverage" (
|
||||
%SPHINXBUILD% -b coverage %ALLSPHINXOPTS% %BUILDDIR%/coverage
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.Testing of coverage in the sources finished, look at the ^
|
||||
results in %BUILDDIR%/coverage/python.txt.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "xml" (
|
||||
%SPHINXBUILD% -b xml %ALLSPHINXOPTS% %BUILDDIR%/xml
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.Build finished. The XML files are in %BUILDDIR%/xml.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "pseudoxml" (
|
||||
%SPHINXBUILD% -b pseudoxml %ALLSPHINXOPTS% %BUILDDIR%/pseudoxml
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.Build finished. The pseudo-XML files are in %BUILDDIR%/pseudoxml.
|
||||
goto end
|
||||
)
|
||||
|
||||
:end
|
||||
|
||||
@@ -29,4 +29,4 @@ serialize (read) a closure and pushes it on top of the stack, the source is user
|
||||
:returns: a SQRESULT
|
||||
:remarks: closures with free variables cannot be serialized
|
||||
|
||||
serializes(writes) the closure on top of the stack, the desination is user defined through a write callback.
|
||||
serializes(writes) the closure on top of the stack, the destination is user defined through a write callback.
|
||||
|
||||
@@ -13,11 +13,10 @@ Calls
|
||||
:param SQBool retval: if true the function will push the return value in the stack
|
||||
:param SQBool raiseerror: if true, if a runtime error occurs during the execution of the call, the vm will invoke the error handler.
|
||||
:returns: a SQRESULT
|
||||
:remarks: the function pops all the parameters and leave the closure in the stack; if retval is true the return value of the closure is pushed. If the execution of the function is suspended through sq_suspendvm(), the closure and the arguments will not be automatically popped from the stack.
|
||||
|
||||
calls a closure or a native closure.
|
||||
|
||||
calls a closure or a native closure. The function pops all the parameters and leave the closure in the stack; if retval is true the return value of the closure is pushed. If the execution of the function is suspended through sq_suspendvm(), the closure and the arguments will not be automatically popped from the stack.
|
||||
|
||||
When using to create an instance, push a dummy parameter to be filled with the newly-created instance for the constructor's 'this' parameter.
|
||||
|
||||
|
||||
|
||||
@@ -88,9 +87,28 @@ reset the last error in the virtual machine to null
|
||||
resumes the generator at the top position of the stack.
|
||||
|
||||
|
||||
.. _sq_tailcall:
|
||||
|
||||
.. c:function:: SQRESULT sq_tailcall(HSQUIRRELVM v, SQInteger nparams)
|
||||
|
||||
:param HSQUIRRELVM v: the target VM
|
||||
:param SQInteger params: number of parameters of the function
|
||||
|
||||
Calls a closure and removes the caller function from the call stack.
|
||||
This function must be invoke from a native closure and
|
||||
he return value of sq_tailcall must be returned by the caller function(see example).
|
||||
|
||||
*.eg*
|
||||
|
||||
::
|
||||
|
||||
SQInteger tailcall_something_example(HSQUIRRELVM v)
|
||||
{
|
||||
//push closure and parameters here
|
||||
...
|
||||
return sq_tailcall(v,2);
|
||||
}
|
||||
|
||||
.. _sq_throwerror:
|
||||
|
||||
.. c:function:: SQRESULT sq_throwerror(HSQUIRRELVM v, const SQChar * err)
|
||||
@@ -102,9 +120,6 @@ resumes the generator at the top position of the stack.
|
||||
sets the last error in the virtual machine and returns the value that has to be returned by a native closure in order to trigger an exception in the virtual machine.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
.. _sq_throwobject:
|
||||
|
||||
.. c:function:: SQRESULT sq_throwobject(HSQUIRRELVM v)
|
||||
|
||||
@@ -76,4 +76,4 @@ enable/disable the error callback notification of handled exceptions.
|
||||
:param SQCOMPILERERROR f: A pointer to the error handler function
|
||||
:remarks: if the parameter f is NULL no function will be called when a compiler error occurs. The compiler error handler is shared between friend VMs.
|
||||
|
||||
sets the compiler error handler function
|
||||
sets the compiler error handler function
|
||||
|
||||
@@ -69,4 +69,4 @@ sets the native debug hook. When a native hook is set it overrides any previousl
|
||||
:param SQStackInfos * si: pointer to the SQStackInfos structure that will store the stack informations
|
||||
:returns: a SQRESULT.
|
||||
|
||||
retrieve the calls stack informations of a ceratain level in the calls stack.
|
||||
retrieve the calls stack informations of a ceratain level in the calls stack.
|
||||
|
||||
@@ -9,9 +9,9 @@ Garbage Collector
|
||||
.. c:function:: SQInteger sq_collectgarbage(HSQUIRRELVM v)
|
||||
|
||||
:param HSQUIRRELVM v: the target VM
|
||||
:remarks: this api only works with gabage collector builds (NO_GARBAGE_COLLECTOR is not defined)
|
||||
:remarks: this api only works with garbage collector builds (NO_GARBAGE_COLLECTOR is not defined)
|
||||
|
||||
runs the garbage collector and returns the number of reference cycles found(and deleted)
|
||||
runs the garbage collector and returns the number of reference cycles found (and deleted)
|
||||
|
||||
|
||||
|
||||
@@ -22,6 +22,6 @@ runs the garbage collector and returns the number of reference cycles found(and
|
||||
.. c:function:: SQRESULT sq_resurrectunreachable(HSQUIRRELVM v)
|
||||
|
||||
:param HSQUIRRELVM v: the target VM
|
||||
:remarks: this api only works with gabage collector builds (NO_GARBAGE_COLLECTOR is not defined)
|
||||
:remarks: this api only works with garbage collector builds (NO_GARBAGE_COLLECTOR is not defined)
|
||||
|
||||
runs the garbage collector and pushes an array in the stack containing all unreachable object found. If no unreachable object is found, null is pushed instead. This function is meant to help debugging reference cycles.
|
||||
runs the garbage collector and pushes an array in the stack containing all unreachable object found. If no unreachable object is found, null is pushed instead. This function is meant to help debug reference cycles.
|
||||
|
||||
@@ -13,7 +13,7 @@ Object creation and handling
|
||||
:returns: a SQRESULT
|
||||
:remarks: the cloned closure holds the environment object as weak reference
|
||||
|
||||
pops an object from the stack(must be a table,instance or class) clones the closure at position idx in the stack and sets the popped object as environment of the cloned closure. Then pushes the new cloned closure on top of the stack.
|
||||
pops an object from the stack (must be a table, instance, or class); clones the closure at position idx in the stack and sets the popped object as environment of the cloned closure. Then pushes the new cloned closure on top of the stack.
|
||||
|
||||
|
||||
|
||||
@@ -54,8 +54,8 @@ gets the value of the bool at the idx position in the stack.
|
||||
.. c:function:: SQRESULT sq_getbyhandle(HSQUIRRELVM v, SQInteger idx, HSQMEMBERHANDLE* handle)
|
||||
|
||||
:param HSQUIRRELVM v: the target VM
|
||||
:param SQInteger idx: an index in the stack pointing to the class
|
||||
:param HSQMEMBERHANDLE* handle: a pointer the member handle
|
||||
:param SQInteger idx: an index in the stack pointing to the class or instance
|
||||
:param HSQMEMBERHANDLE* handle: a pointer to the member handle
|
||||
:returns: a SQRESULT
|
||||
|
||||
pushes the value of a class or instance member using a member handle (see sq_getmemberhandle)
|
||||
@@ -88,7 +88,7 @@ retrieves number of parameters and number of freevariables from a squirrel closu
|
||||
:param SQInteger idx: index of the target closure
|
||||
:returns: an SQRESULT
|
||||
|
||||
pushes the name of the closure at poistion idx in the stack. Note that the name can be a string or null if the closure is anonymous or a native closure with no name assigned to it.
|
||||
pushes the name of the closure at position idx in the stack. Note that the name can be a string or null if the closure is anonymous or a native closure with no name assigned to it.
|
||||
|
||||
|
||||
|
||||
@@ -177,9 +177,9 @@ gets the value of the integer at the idx position in the stack.
|
||||
:param SQInteger idx: an index in the stack pointing to the class
|
||||
:param HSQMEMBERHANDLE* handle: a pointer to the variable that will store the handle
|
||||
:returns: a SQRESULT
|
||||
:remarks: This method works only with classes and instances. A handle retrieved through a class can be later used to set or get values from one of the class instances and vice-versa. Handles retrieved from base classes are still valid in derived classes and respect inheritance rules.
|
||||
:remarks: This method works only with classes. A handle retrieved through a class can be later used to set or get values from one of the class instances. Handles retrieved from base classes are still valid in derived classes and respect inheritance rules.
|
||||
|
||||
pops a value from the stack and uses it as index to fetch the handle of a class member. The handle can be later used to set or get the member value using sq_getbyhandle(),sq_setbyhandle().
|
||||
pops a value from the stack and uses it as index to fetch the handle of a class member. The handle can be later used to set or get the member value using sq_getbyhandle(), sq_setbyhandle().
|
||||
|
||||
|
||||
|
||||
@@ -220,9 +220,9 @@ returns a pointer to a memory buffer that is at least as big as minsize.
|
||||
:param HSQUIRRELVM v: the target VM
|
||||
:param SQInteger idx: an index in the stack
|
||||
:returns: the size of the value at the position idx in the stack
|
||||
:remarks: this function only works with strings,arrays,tables,classes,instances and userdata if the value is not a valid type types the function will return -1.
|
||||
:remarks: this function only works with strings, arrays, tables, classes, instances, and userdata if the value is not a valid type, the function will return -1.
|
||||
|
||||
returns the size of a value at the idx position in the stack, if the value is a class or a class instance the size returned is the size of the userdata buffer(see sq_setclassudsize).
|
||||
returns the size of a value at the idx position in the stack. If the value is a class or a class instance the size returned is the size of the userdata buffer (see sq_setclassudsize).
|
||||
|
||||
|
||||
|
||||
@@ -243,6 +243,21 @@ gets a pointer to the string at the idx position in the stack.
|
||||
|
||||
|
||||
|
||||
.. _sq_getstringandsize:
|
||||
|
||||
.. c:function:: SQRESULT sq_getstringandsize(HSQUIRRELVM v, SQInteger idx, const SQChar ** c, SQInteger* size)
|
||||
|
||||
:param HSQUIRRELVM v: the target VM
|
||||
:param SQInteger idx: an index in the stack
|
||||
:param const SQChar ** c: a pointer to the pointer that will point to the string
|
||||
:param SQInteger * size: a pointer to a SQInteger which will receive the size of the string
|
||||
:returns: a SQRESULT
|
||||
|
||||
gets a pointer to the string at the idx position in the stack; additionally retrieves its size.
|
||||
|
||||
|
||||
|
||||
|
||||
.. _sq_getthread:
|
||||
|
||||
.. c:function:: SQRESULT sq_getthread(HSQUIRRELVM v, SQInteger idx, HSQUIRRELVM* v)
|
||||
@@ -252,7 +267,7 @@ gets a pointer to the string at the idx position in the stack.
|
||||
:param HSQUIRRELVM* v: A pointer to the variable that will store the thread pointer
|
||||
:returns: a SQRESULT
|
||||
|
||||
gets a a pointer to the thread the idx position in the stack.
|
||||
gets a pointer to the thread the idx position in the stack.
|
||||
|
||||
|
||||
|
||||
@@ -282,7 +297,7 @@ returns the type of the value at the position idx in the stack
|
||||
:returns: a SQRESULT
|
||||
:remarks: the function works also with instances. if the taget object is an instance, the typetag of it's base class is fetched.
|
||||
|
||||
gets the typetag of the object(userdata or class) at position idx in the stack.
|
||||
gets the typetag of the object (userdata or class) at position idx in the stack.
|
||||
|
||||
|
||||
|
||||
@@ -340,7 +355,7 @@ creates a new array and pushes it in the stack
|
||||
:param SQBool hasbase: if the parameter is true the function expects a base class on top of the stack.
|
||||
:returns: a SQRESULT
|
||||
|
||||
creates a new class object. If the parameter 'hasbase' is different than 0, the function pops a class from the stack and inherits the new created class from it.
|
||||
creates a new class object. If the parameter 'hasbase' is different than 0, the function pops a class from the stack and inherits the new created class from it. The new class is pushed in the stack.
|
||||
|
||||
|
||||
|
||||
@@ -379,7 +394,7 @@ creates a new table and pushes it in the stack
|
||||
:param HSQUIRRELVM v: the target VM
|
||||
:param SQInteger initialcapacity: number of key/value pairs to preallocate
|
||||
|
||||
creates a new table and pushes it in the stack. This function allows to specify the initial capacity of the table to prevent unnecessary rehashing when the number of slots required is known at creation-time.
|
||||
creates a new table and pushes it in the stack. This function allows you to specify the initial capacity of the table to prevent unnecessary rehashing when the number of slots required is known at creation-time.
|
||||
|
||||
|
||||
|
||||
@@ -431,7 +446,7 @@ pushes a float into the stack
|
||||
:param HSQUIRRELVM v: the target VM
|
||||
:param SQInteger n: the integer that has to be pushed
|
||||
|
||||
pushes a integer into the stack
|
||||
pushes an integer into the stack
|
||||
|
||||
|
||||
|
||||
@@ -455,7 +470,7 @@ pushes a null value into the stack
|
||||
|
||||
:param HSQUIRRELVM v: the target VM
|
||||
:param const SQChar * s: pointer to the string that has to be pushed
|
||||
:param SQInteger len: lenght of the string pointed by s
|
||||
:param SQInteger len: length of the string pointed by s
|
||||
:remarks: if the parameter len is less than 0 the VM will calculate the length using strlen(s)
|
||||
|
||||
pushes a string in the stack
|
||||
@@ -501,7 +516,7 @@ pops a value from the stack and sets it to a class or instance member using a me
|
||||
:param SQInteger udsize: size in bytes reserved for user data
|
||||
:returns: a SQRESULT
|
||||
|
||||
Sets the user data size of a class. If a class 'user data size' is greater than 0. When an instance of the class is created additional space will is reserved at the end of the memory chunk where the instance is stored. The userpointer of the instance will also be automatically set to this memory area. This allows to minimize allocations in applications that have to carry data along with the class instance.
|
||||
Sets the user data size of a class. If a class 'user data size' is greater than 0. When an instance of the class is created additional space will be reserved at the end of the memory chunk where the instance is stored. The userpointer of the instance will also be automatically set to this memory area. This allows you to minimize allocations in applications that have to carry data along with the class instance.
|
||||
|
||||
|
||||
|
||||
@@ -515,7 +530,7 @@ Sets the user data size of a class. If a class 'user data size' is greater than
|
||||
:param SQInteger idx: index of the target closure
|
||||
:returns: an SQRESULT
|
||||
|
||||
pops a table from the stack and sets it as root of the closre at position idx in the stack
|
||||
pops a table from the stack and sets it as root of the closure at position idx in the stack
|
||||
|
||||
|
||||
|
||||
@@ -545,7 +560,7 @@ sets the userpointer of the class instance at position idx in the stack.
|
||||
:param const SQChar * name: the name that has to be set
|
||||
:returns: an SQRESULT
|
||||
|
||||
sets the name of the native closure at the position idx in the stack. the name of a native closure is purely for debug pourposes. The name is retieved trough the function sq_stackinfos() while the closure is in the call stack.
|
||||
sets the name of the native closure at the position idx in the stack. The name of a native closure is purely for debug purposes. The name is retrieved trough the function sq_stackinfos() while the closure is in the call stack.
|
||||
|
||||
|
||||
|
||||
@@ -556,11 +571,11 @@ sets the name of the native closure at the position idx in the stack. the name o
|
||||
.. c:function:: SQRESULT sq_setparamscheck(HSQUIRRELVM v, SQInteger nparamscheck, const SQChar * typemask)
|
||||
|
||||
:param HSQUIRRELVM v: the target VM
|
||||
:param SQInteger nparamscheck: defines the parameters number check policy(0 disable the param checking). if nparamscheck is greater than 0 the VM ensures that the number of parameters is exactly the number specified in nparamscheck(eg. if nparamscheck == 3 the function can only be called with 3 parameters). if nparamscheck is less than 0 the VM ensures that the closure is called with at least the absolute value of the number specified in nparamcheck(eg. nparamscheck == -3 will check that the function is called with at least 3 parameters). the hidden paramater 'this' is included in this number free variables aren't. If SQ_MATCHTYPEMASKSTRING is passed instead of the number of parameters, the function will automatically extrapolate the number of parameters to check from the typemask(eg. if the typemask is ".sn" is like passing 3).
|
||||
:param const SQChar * typemask: defines a mask to validate the parametes types passed to the function. if the parameter is NULL no typechecking is applyed(default).
|
||||
:remarks: The typemask consists in a zero teminated string that represent the expected parameter type. The types are expressed as follows: 'o' null, 'i' integer, 'f' float, 'n' integer or float, 's' string, 't' table, 'a' array, 'u' userdata, 'c' closure and nativeclosure, 'g' generator, 'p' userpointer, 'v' thread, 'x' instance(class instance), 'y' class, 'b' bool. and '.' any type. The symbol '|' can be used as 'or' to accept multiple types on the same parameter. There isn't any limit on the number of 'or' that can be used. Spaces are ignored so can be inserted between types to increase readbility. For instance to check a function that espect a table as 'this' a string as first parameter and a number or a userpointer as second parameter, the string would be "tsn|p" (table,string,number or userpointer). If the parameters mask is contains less parameters than 'nparamscheck' the remaining parameters will not be typechecked.
|
||||
:param SQInteger nparamscheck: defines the parameters number check policy (0 disables the param checking). If nparamscheck is greater than 0, the VM ensures that the number of parameters is exactly the number specified in nparamscheck (eg. if nparamscheck == 3 the function can only be called with 3 parameters). If nparamscheck is less than 0 the VM ensures that the closure is called with at least the absolute value of the number specified in nparamcheck (eg. nparamscheck == -3 will check that the function is called with at least 3 parameters). The hidden parameter 'this' is included in this number; free variables aren't. If SQ_MATCHTYPEMASKSTRING is passed instead of the number of parameters, the function will automatically infer the number of parameters to check from the typemask (eg. if the typemask is ".sn", it is like passing 3).
|
||||
:param const SQChar * typemask: defines a mask to validate the parametes types passed to the function. If the parameter is NULL, no typechecking is applied (default).
|
||||
:remarks: The typemask consists in a zero terminated string that represent the expected parameter type. The types are expressed as follows: 'o' null, 'i' integer, 'f' float, 'n' integer or float, 's' string, 't' table, 'a' array, 'u' userdata, 'c' closure and nativeclosure, 'g' generator, 'p' userpointer, 'v' thread, 'x' instance(class instance), 'y' class, 'b' bool. and '.' any type. The symbol '|' can be used as 'or' to accept multiple types on the same parameter. There isn't any limit on the number of 'or' that can be used. Spaces are ignored so can be inserted between types to increase readability. For instance to check a function that expect a table as 'this' a string as first parameter and a number or a userpointer as second parameter, the string would be "tsn|p" (table,string,number or userpointer). If the parameters mask is contains fewer parameters than 'nparamscheck', the remaining parameters will not be typechecked.
|
||||
|
||||
Sets the parameters validation scheme for the native closure at the top position in the stack. Allows to validate the number of paramters accepted by the function and optionally their types. If the function call do not comply with the parameter schema set by sq_setparamscheck, an exception is thrown.
|
||||
Sets the parameter validation scheme for the native closure at the top position in the stack. Allows you to validate the number of parameters accepted by the function and optionally their types. If the function call does not comply with the parameter schema set by sq_setparamscheck, an exception is thrown.
|
||||
|
||||
*.eg*
|
||||
|
||||
@@ -572,7 +587,7 @@ Sets the parameters validation scheme for the native closure at the top position
|
||||
SQUserPointer p;
|
||||
const SQChar *s;
|
||||
SQInteger i;
|
||||
//no type checking, if the call comply to the mask
|
||||
//no type checking, if the call complies with the mask
|
||||
//surely the functions will succeed.
|
||||
sq_getuserdata(v,1,&p,NULL);
|
||||
sq_getstring(v,2,&s);
|
||||
@@ -603,7 +618,7 @@ Sets the parameters validation scheme for the native closure at the top position
|
||||
:param SQRELEASEHOOK hook: a function pointer to the hook(see sample below)
|
||||
:remarks: the function hook is called by the VM before the userdata memory is deleted.
|
||||
|
||||
sets the release hook of the userdata, class instance or class at position idx in the stack.
|
||||
sets the release hook of the userdata, class instance, or class at position idx in the stack.
|
||||
|
||||
*.eg*
|
||||
|
||||
@@ -632,7 +647,7 @@ sets the release hook of the userdata, class instance or class at position idx i
|
||||
:param SQUserPointer typetag: an arbitrary SQUserPointer
|
||||
:returns: a SQRESULT
|
||||
|
||||
sets the typetag of the object(userdata or class) at position idx in the stack.
|
||||
sets the typetag of the object (userdata or class) at position idx in the stack.
|
||||
|
||||
|
||||
|
||||
@@ -645,7 +660,7 @@ sets the typetag of the object(userdata or class) at position idx in the stack.
|
||||
:param HSQUIRRELVM v: the target VM
|
||||
:param SQInteger idx: an index in the stack
|
||||
:param SQBool * b: A pointer to the bool that will store the value
|
||||
:remarks: if the object is not a bool the function converts the value too bool according to squirrel's rules. For instance the number 1 will result in true, and the number 0 in false.
|
||||
:remarks: if the object is not a bool the function converts the value to bool according to squirrel's rules. For instance the number 1 will result in true, and the number 0 in false.
|
||||
|
||||
gets the value at position idx in the stack as bool.
|
||||
|
||||
@@ -674,7 +689,7 @@ converts the object at position idx in the stack to string and pushes the result
|
||||
:param SQInteger idx: an index in the stack
|
||||
:returns: a SQRESULT
|
||||
|
||||
pushes the type name of the value at the position idx in the stack, it also invokes the _typeof metamethod for tables and class instances that implement it; in that case the pushed object could be something other than a string (is up to the _typeof implementation).
|
||||
pushes the type name of the value at the position idx in the stack. It also invokes the _typeof metamethod for tables and class instances that implement it; in that case the pushed object could be something other than a string (is up to the _typeof implementation).
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ pops a value from the stack and pushes it in the back of the array at the positi
|
||||
|
||||
:param HSQUIRRELVM v: the target VM
|
||||
:param SQInteger idx: index of the target array in the stack
|
||||
:param SQInteger destpos: the postion in the array where the item has to be inserted
|
||||
:param SQInteger destpos: the position in the array where the item has to be inserted
|
||||
:returns: a SQRESULT
|
||||
:remarks: Only works on arrays.
|
||||
|
||||
@@ -74,7 +74,7 @@ removes an item from an array
|
||||
:param SQInteger idx: index of the target array in the stack
|
||||
:param SQInteger newsize: requested size of the array
|
||||
:returns: a SQRESULT
|
||||
:remarks: Only works on arrays.if newsize if greater than the current size the new array slots will be filled with nulls.
|
||||
:remarks: Only works on arrays. If newsize if greater than the current size the new array slots will be filled with nulls.
|
||||
|
||||
resizes the array at the position idx in the stack.
|
||||
|
||||
@@ -91,7 +91,7 @@ resizes the array at the position idx in the stack.
|
||||
:returns: a SQRESULT
|
||||
:remarks: Only works on arrays.
|
||||
|
||||
reverse an array in place.
|
||||
reverses an array in place.
|
||||
|
||||
|
||||
|
||||
@@ -106,7 +106,7 @@ reverse an array in place.
|
||||
:returns: a SQRESULT
|
||||
:remarks: Only works on tables and arrays.
|
||||
|
||||
clears all the element of the table/array at position idx in the stack.
|
||||
clears all the elements of the table/array at position idx in the stack.
|
||||
|
||||
|
||||
|
||||
@@ -120,7 +120,7 @@ clears all the element of the table/array at position idx in the stack.
|
||||
:param SQInteger idx: index of the target object in the stack
|
||||
:returns: a SQRESULT
|
||||
|
||||
Clones the table, array or class instance at the position idx, clones it and pushes the new object in the stack.
|
||||
pushes a clone of the table, array, or class instance at the position idx.
|
||||
|
||||
|
||||
|
||||
@@ -135,7 +135,7 @@ Clones the table, array or class instance at the position idx, clones it and pus
|
||||
:returns: a SQRESULT
|
||||
:remarks: invoke the _newslot metamethod in the table delegate. it only works on tables. [this function is deperecated since version 2.0.5 use sq_newslot() instead]
|
||||
|
||||
pops a key and a value from the stack and performs a set operation on the table or class that is at position idx in the stack, if the slot does not exits it will be created.
|
||||
pops a key and a value from the stack and performs a set operation on the table or class that is at position idx in the stack; if the slot does not exist, it will be created.
|
||||
|
||||
|
||||
|
||||
@@ -151,7 +151,7 @@ pops a key and a value from the stack and performs a set operation on the table
|
||||
:returns: a SQRESULT
|
||||
:remarks: invoke the _delslot metamethod in the table delegate. it only works on tables.
|
||||
|
||||
pops a key from the stack and delete the slot indexed by it from the table at position idx in the stack, if the slot does not exits nothing happens.
|
||||
pops a key from the stack and delete the slot indexed by it from the table at position idx in the stack; if the slot does not exist, nothing happens.
|
||||
|
||||
|
||||
|
||||
@@ -164,9 +164,9 @@ pops a key from the stack and delete the slot indexed by it from the table at po
|
||||
:param HSQUIRRELVM v: the target VM
|
||||
:param SQInteger idx: index of the target object in the stack
|
||||
:returns: a SQRESULT
|
||||
:remarks: this call will invokes the delegation system like a normal dereference it only works on tables, arrays and userdata. if the function fails nothing will be pushed in the stack.
|
||||
:remarks: this call will invokes the delegation system like a normal dereference it only works on tables, arrays, classes, instances and userdata; if the function fails, nothing will be pushed in the stack.
|
||||
|
||||
pops a key from the stack and performs a get operation on the object at the position idx in the stack, and pushes the result in the stack.
|
||||
pops a key from the stack and performs a get operation on the object at the position idx in the stack; and pushes the result in the stack.
|
||||
|
||||
|
||||
|
||||
@@ -180,7 +180,7 @@ pops a key from the stack and performs a get operation on the object at the posi
|
||||
:param SQInteger idx: index of the target class in the stack
|
||||
:returns: a SQRESULT
|
||||
|
||||
Gets the attribute of a class mameber. The function pops a key from the stack and pushes the attribute of the class member indexed by they key from class at position idx in the stack. If key is null the function gets the class level attribute.
|
||||
Gets the attribute of a class member. The function pops a key from the stack and pushes the attribute of the class member indexed by they key from a class at position idx in the stack. If key is null the function gets the class level attribute.
|
||||
|
||||
|
||||
|
||||
@@ -267,7 +267,7 @@ pushes the object pointed by the weak reference at position idx in the stack.
|
||||
:returns: SQTrue if the instance at position -2 in the stack is an instance of the class object at position -1 in the stack.
|
||||
:remarks: The function doesn't pop any object from the stack.
|
||||
|
||||
Determintes if an object is an instance of a certain class. Expects an istance and a class in the stack.
|
||||
Determines if an object is an instance of a certain class. Expects an instance and a class in the stack.
|
||||
|
||||
|
||||
|
||||
@@ -283,7 +283,7 @@ Determintes if an object is an instance of a certain class. Expects an istance a
|
||||
:returns: a SQRESULT
|
||||
:remarks: Invokes the _newmember metamethod in the class. it only works on classes.
|
||||
|
||||
pops a key, a value and an object(that will be set as attribute of the member) from the stack and performs a new slot operation on the class that is at position idx in the stack, if the slot does not exits it will be created.
|
||||
pops a key, a value and an object (which will be set as attribute of the member) from the stack and performs a new slot operation on the class that is at position idx in the stack; if the slot does not exist, it will be created.
|
||||
|
||||
|
||||
|
||||
@@ -299,7 +299,7 @@ pops a key, a value and an object(that will be set as attribute of the member) f
|
||||
:returns: a SQRESULT
|
||||
:remarks: Invokes the _newslot metamethod in the table delegate. it only works on tables and classes.
|
||||
|
||||
pops a key and a value from the stack and performs a set operation on the table or class that is at position idx in the stack, if the slot does not exits it will be created.
|
||||
pops a key and a value from the stack and performs a set operation on the table or class that is at position idx in the stack, if the slot does not exist it will be created.
|
||||
|
||||
|
||||
|
||||
@@ -313,7 +313,7 @@ pops a key and a value from the stack and performs a set operation on the table
|
||||
:param SQInteger idx: index of the target object in the stack
|
||||
:returns: a SQRESULT
|
||||
|
||||
Pushes in the stack the next key and value of an array, table or class slot. To start the iteration this function expects a null value on top of the stack; at every call the function will substitute the null value with an iterator and push key and value of the container slot. Every iteration the application has to pop the previous key and value but leave the iterator(that is used as reference point for the next iteration). The function will fail when all slots have been iterated(see Tables and arrays manipulation).
|
||||
Pushes in the stack the next key and value of an array, table, or class slot. To start the iteration this function expects a null value on top of the stack; at every call the function will substitute the null value with an iterator and push key and value of the container slot. Every iteration the application has to pop the previous key and value but leave the iterator(that is used as reference point for the next iteration). The function will fail when all slots have been iterated(see Tables and arrays manipulation).
|
||||
|
||||
|
||||
|
||||
@@ -328,7 +328,7 @@ Pushes in the stack the next key and value of an array, table or class slot. To
|
||||
:param SQBool pushval: if this param is true the function will push the value of the deleted slot.
|
||||
:returns: a SQRESULT
|
||||
|
||||
Deletes a slot from a table without employing the _delslot metamethod. pops a key from the stack and delete the slot indexed by it from the table at position idx in the stack, if the slot does not exits nothing happens.
|
||||
Deletes a slot from a table without employing the _delslot metamethod. Pops a key from the stack and delete the slot indexed by it from the table at position idx in the stack; if the slot does not exist nothing happens.
|
||||
|
||||
|
||||
|
||||
@@ -359,7 +359,7 @@ pops a key from the stack and performs a get operation on the object at position
|
||||
:returns: a SQRESULT
|
||||
:remarks: it only works on classes.
|
||||
|
||||
pops a key, a value and an object(that will be set as attribute of the member) from the stack and performs a new slot operation on the class that is at position idx in the stack, if the slot does not exits it will be created.
|
||||
pops a key, a value and an object(that will be set as attribute of the member) from the stack and performs a new slot operation on the class that is at position idx in the stack; if the slot does not exist it will be created.
|
||||
|
||||
|
||||
|
||||
@@ -403,7 +403,7 @@ pops a key and a value from the stack and performs a set operation on the object
|
||||
:param SQInteger idx: index of the target class in the stack.
|
||||
:returns: a SQRESULT
|
||||
|
||||
Sets the attribute of a class mameber. The function pops a key and a value from the stack and sets the attribute (indexed by they key) on the class at position idx in the stack. If key is null the function sets the class level attribute. If the function succeed, the old attribute value is pushed in the stack.
|
||||
Sets the attribute of a class member. The function pops a key and a value from the stack and sets the attribute (indexed by the key) on the class at position idx in the stack. If key is null the function sets the class level attribute. If the function succeed, the old attribute value is pushed in the stack.
|
||||
|
||||
|
||||
|
||||
@@ -416,9 +416,9 @@ Sets the attribute of a class mameber. The function pops a key and a value from
|
||||
:param HSQUIRRELVM v: the target VM
|
||||
:param SQInteger idx: index of the target object in the stack
|
||||
:returns: a SQRESULT
|
||||
:remarks: to remove the delgate from an object is necessary to use null as delegate instead of a table.
|
||||
:remarks: to remove the delegate from an object, set a null value.
|
||||
|
||||
pops a table from the stack and sets it as delegate of the object at the position idx in the stack.
|
||||
pops a table from the stack and sets it as the delegate of the object at the position idx in the stack.
|
||||
|
||||
|
||||
|
||||
@@ -433,7 +433,7 @@ pops a table from the stack and sets it as delegate of the object at the positio
|
||||
:param SQInteger nval: 0 based index of the free variable(relative to the closure).
|
||||
:returns: a SQRESULT
|
||||
|
||||
pops a value from the stack and sets it as free variable of the closure at the position idx in the stack.
|
||||
pops a value from the stack and sets it as a free variable of the closure at the position idx in the stack.
|
||||
|
||||
|
||||
|
||||
@@ -446,6 +446,6 @@ pops a value from the stack and sets it as free variable of the closure at the p
|
||||
:param HSQUIRRELVM v: the target VM
|
||||
:param SQInteger idx: index to the target object in the stack
|
||||
:returns: a SQRESULT
|
||||
:remarks: if the object at idx position is an integer,float,bool or null the object itself is pushed instead of a weak ref.
|
||||
:remarks: if the object at idx position is one of (integer, float, bool, null), the object itself is pushed instead of a weak ref.
|
||||
|
||||
pushes a weak reference to the object at position idx in the stack.
|
||||
pushes a weak reference to the object at position idx in the stack.
|
||||
|
||||
@@ -24,7 +24,7 @@ adds a reference to an object handler.
|
||||
:param HSQOBJECT* o: pointer to an object handler
|
||||
:param SQUserPointer* typetag: a pointer to the variable that will store the tag
|
||||
:returns: a SQRESULT
|
||||
:remarks: the function works also with instances. if the taget object is an instance, the typetag of it's base class is fetched.
|
||||
:remarks: the function works also with instances. if the target object is an instance, the typetag of it's base class is fetched.
|
||||
|
||||
gets the typetag of a raw object reference(userdata or class).
|
||||
|
||||
@@ -145,7 +145,7 @@ push an object referenced by an object handler into the stack.
|
||||
:param HSQUIRRELVM v: the target VM
|
||||
:param HSQOBJECT* po: pointer to an object handler
|
||||
:returns: SQTrue if the object handler released has lost all is references(the ones added with sq_addref). SQFalse otherwise.
|
||||
:remarks: the function will reset the object handler to null when it losts all references.
|
||||
:remarks: the function will reset the object handler to null when it loses all references.
|
||||
|
||||
remove a reference from an object handler.
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ Stack Operations
|
||||
:returns: == 0 if obj1==obj2
|
||||
:returns: < 0 if obj1<obj2
|
||||
|
||||
compares 2 object from the stack and compares them.
|
||||
compares 2 object from the top of the stack. obj2 should be pushed before obj1.
|
||||
|
||||
|
||||
|
||||
@@ -91,7 +91,7 @@ removes an element from an arbitrary position in the stack
|
||||
:param SQInteger nsize: required stack size
|
||||
:returns: a SQRESULT
|
||||
|
||||
ensure that the stack space left is at least of a specified size.If the stack is smaller it will automatically grow. if there's a memtamethod currently running the function will fail and the stack will not be resized, this situatuation has to be considered a "stack overflow".
|
||||
ensure that the stack space left is at least of a specified size.If the stack is smaller it will automatically grow. If there's a metamethod currently running the function will fail and the stack will not be resized, this situation has to be considered a "stack overflow".
|
||||
|
||||
|
||||
|
||||
@@ -104,4 +104,4 @@ ensure that the stack space left is at least of a specified size.If the stack is
|
||||
:param HSQUIRRELVM v: the target VM
|
||||
:param SQInteger v: the new top index
|
||||
|
||||
resize the stack, if new top is bigger then the current top the function will push nulls.
|
||||
resize the stack. If new top is bigger then the current top the function will push nulls.
|
||||
|
||||
@@ -63,7 +63,7 @@ returns the current print function of the given Virtual machine. (see sq_setprin
|
||||
:param HSQUIRRELVM v: the target VM
|
||||
:returns: the current VMs shared foreign pointer
|
||||
|
||||
Returns the shared foreign pointer of a group of friend VMs .
|
||||
Returns the shared foreign pointer of a group of friend VMs
|
||||
|
||||
|
||||
|
||||
@@ -76,7 +76,7 @@ Returns the shared foreign pointer of a group of friend VMs .
|
||||
:param HSQUIRRELVM v: the target VM
|
||||
:returns: the current VMs release hook.
|
||||
|
||||
Returns the shared release hook of a group of friend VMs .
|
||||
Returns the shared release hook of a group of friend VMs
|
||||
|
||||
|
||||
|
||||
@@ -88,7 +88,7 @@ Returns the shared release hook of a group of friend VMs .
|
||||
|
||||
:returns: version number of the vm(as in SQUIRREL_VERSION_NUMBER).
|
||||
|
||||
returns the version number of the vm.
|
||||
returns the version number of the vm
|
||||
|
||||
|
||||
|
||||
@@ -101,7 +101,7 @@ returns the version number of the vm.
|
||||
:param HSQUIRRELVM v: the target VM
|
||||
:returns: the current VMs release hook.
|
||||
|
||||
Returns the release hook of a VM instance.
|
||||
Returns the release hook of a VM instance
|
||||
|
||||
|
||||
|
||||
@@ -128,7 +128,7 @@ returns the execution state of a virtual machine
|
||||
:param HSQUIRRELVM src: the source VM
|
||||
:param SQInteger idx: the index in the source stack of the value that has to be moved
|
||||
|
||||
pushes the object at the position 'idx' of the source vm stack in the destination vm stack.
|
||||
pushes the object at the position 'idx' of the source vm stack in the destination vm stack
|
||||
|
||||
|
||||
|
||||
@@ -297,7 +297,7 @@ Sets the release hook of a certain VM group. The release hook is invoked when th
|
||||
:param HSQUIRRELVM v: the target VM
|
||||
:param SQRELESEHOOK hook: The hook that has to be set
|
||||
|
||||
Sets the release hook of a certain VM instance. The release hook is invoked when the vm is destroyed. The userpointer passed to the function is the vm foreignpointer(see sq_setforeignpointer())
|
||||
Sets the release hook of a certain VM instance. The release hook is invoked when the vm is destroyed. The userpointer passed to the function is the vm foreignpointer (see sq_setforeignpointer())
|
||||
|
||||
|
||||
|
||||
@@ -338,4 +338,4 @@ Suspends the execution of the specified vm.
|
||||
:param SQBool throwerror: if true, the vm will thow an exception as soon as is resumed. the exception payload must be set beforehand invoking sq_thowerror().
|
||||
:returns: an HRESULT.
|
||||
|
||||
Wake up the execution a previously suspended virtual machine.
|
||||
wake up the execution a previously suspended virtual machine
|
||||
|
||||
@@ -13,19 +13,19 @@ Unicode
|
||||
.. index:: single: Unicode
|
||||
|
||||
By default Squirrel strings are plain 8-bits ASCII characters; however if the symbol
|
||||
'SQUNICODE' is defined the VM, compiler and API will use 16-bits characters (UCS2).
|
||||
'SQUNICODE' is defined the VM, compiler and API will use 16-bit characters (UCS2).
|
||||
|
||||
.. _squirrel_64bits:
|
||||
|
||||
---------------------------------
|
||||
Squirrel on 64 bits architectures
|
||||
---------------------------------
|
||||
--------------------------------
|
||||
Squirrel on 64-bit architectures
|
||||
--------------------------------
|
||||
|
||||
.. index::
|
||||
single: Squirrel on 64 bits architectures
|
||||
single: Squirrel on 64-bit architectures
|
||||
single: 64 bits
|
||||
|
||||
Squirrel can be compiled on 64 bits architectures by defining '_SQ64' in the C++
|
||||
Squirrel can be compiled on 64-bit architectures by defining '_SQ64' in the C++
|
||||
preprocessor. This flag should be defined in any project that includes 'squirrel.h'.
|
||||
|
||||
.. _userdata_alignment:
|
||||
@@ -37,13 +37,13 @@ Userdata Alignment
|
||||
.. index:: single: Userdata Alignment
|
||||
|
||||
Both class instances and userdatas can have a buffer associated to them.
|
||||
Squirrel specifies the alignment(in bytes) through the peroprocessor defining 'SQ_ALIGNMENT'.
|
||||
By default SQ_ALIGNMENT is defined as 4 for 32 bits builds and 8 for 64bits builds and builds that use 64bits floats.
|
||||
Squirrel specifies the alignment(in bytes) through the preprocessor defining 'SQ_ALIGNMENT'.
|
||||
By default SQ_ALIGNMENT is defined as 4 for 32-bit builds and 8 for 64-bit builds and builds that use 64-bit floats.
|
||||
It is possible to override the value of SQ_ALIGNMENT respecting the following rules.
|
||||
SQ_ALIGNMENT shall be less than or equal to SQ_MALLOC alignments, and it shall be power of 2.
|
||||
|
||||
.. note:: This only applies for userdata allocated by the VM, specified via sq_setclassudsize() or belonging to a userdata object.
|
||||
userpointers specified by the user are not affected by alignemnt rules.
|
||||
userpointers specified by the user are not affected by alignment rules.
|
||||
|
||||
.. _standalone_vm:
|
||||
|
||||
@@ -53,7 +53,7 @@ Stand-alone VM without compiler
|
||||
|
||||
.. index:: single: Stand-alone VM without compiler
|
||||
|
||||
Squirrel's VM can be compiled without it's compiler by defining 'NO_COMPILER' in the C++ preprocessor.
|
||||
Squirrel's VM can be compiled without its compiler by defining 'NO_COMPILER' in the C++ preprocessor.
|
||||
When 'NO_COMPILER' is defined all function related to the compiler (eg. sq_compile) will fail. Other functions
|
||||
that conditionally load precompiled bytecode or compile a file (eg. sqstd_dofile) will only work with
|
||||
precompiled bytecode.
|
||||
|
||||
@@ -16,7 +16,7 @@ parameter is > 0. ::
|
||||
sq_pushinteger(v,1);
|
||||
sq_pushfloat(v,2.0);
|
||||
sq_pushstring(v,"three",-1);
|
||||
sq_call(v,4,SQFalse);
|
||||
sq_call(v,4,SQFalse,SQFalse);
|
||||
sq_pop(v,2); //pops the roottable and the function
|
||||
|
||||
this is equivalent to the following Squirrel code::
|
||||
|
||||
@@ -8,7 +8,7 @@ You can compile a Squirrel script with the function *sq_compile*.::
|
||||
|
||||
typedef SQInteger (*SQLEXREADFUNC)(SQUserPointer userdata);
|
||||
|
||||
SQRESULT sq_compile(HSQUIRRELVM v,SQREADFUNC read,SQUserPointer p,
|
||||
SQRESULT sq_compile(HSQUIRRELVM v,SQLEXREADFUNC read,SQUserPointer p,
|
||||
const SQChar *sourcename,SQBool raiseerror);
|
||||
|
||||
In order to compile a script is necessary for the host application to implement a reader
|
||||
|
||||
@@ -23,7 +23,7 @@ When the function is called, the stackbase is the first parameter of the functio
|
||||
top is the last. In order to return a value the function has to push it in the stack and
|
||||
return 1.
|
||||
|
||||
Function parameters are in the stack from postion 1 ('this') to *n*.
|
||||
Function parameters are in the stack from position 1 ('this') to *n*.
|
||||
*sq_gettop()* can be used to determinate the number of parameters.
|
||||
|
||||
If the function has free variables, those will be in the stack after the explicit parameters
|
||||
@@ -99,7 +99,8 @@ Here an example of how to register a function::
|
||||
{
|
||||
sq_pushroottable(v);
|
||||
sq_pushstring(v,fname,-1);
|
||||
sq_newclosure(v,f,0,0); //create a new function
|
||||
sq_newclosure(v,f,0); //create a new function
|
||||
sq_newslot(v,-3,SQFalse);
|
||||
sq_pop(v,1); //pops the root table
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -11,11 +11,11 @@ The object can be also re-pushed in the VM stack using sq_pushobject().::
|
||||
|
||||
HSQOBJECT obj;
|
||||
|
||||
sq_resetobject(v,&obj) //initialize the handle
|
||||
sq_resetobject(&obj); //initialize the handle
|
||||
sq_getstackobj(v,-2,&obj); //retrieve an object handle from the pos -2
|
||||
sq_addref(v,&obj); //adds a reference to the object
|
||||
|
||||
... //do stuff
|
||||
|
||||
sq_pushobject(v,&obj); //push the object in the stack
|
||||
sq_pushobject(v,obj); //push the object in the stack
|
||||
sq_release(v,&obj); //relese the object
|
||||
|
||||
@@ -47,7 +47,7 @@ To get a value from an array or table::
|
||||
|
||||
SQRESULT sq_get(HSQUIRRELVM v,SQInteger idx);
|
||||
|
||||
To get or set a value from a table without employ delegation::
|
||||
To get or set a value from a table without employing delegation::
|
||||
|
||||
SQRESULT sq_rawget(HSQUIRRELVM v,SQInteger idx);
|
||||
SQRESULT sq_rawset(HSQUIRRELVM v,SQInteger idx);
|
||||
|
||||
@@ -5,7 +5,7 @@ The registry table
|
||||
==================
|
||||
|
||||
The registry table is an hidden table shared between vm and all his thread(friend vms).
|
||||
This table is accessible only through the C API and is ment to be an utility structure
|
||||
This table is accessible only through the C API and is meant to be an utility structure
|
||||
for native C library implementation.
|
||||
For instance the sqstdlib(squirrel standard library)uses it to store configuration and shared objects
|
||||
delegates.
|
||||
|
||||
@@ -65,7 +65,7 @@ To force the stack to a certain size you can call *sq_settop* ::
|
||||
|
||||
void sq_settop(HSQUIRRELVM v,SQInteger newtop);
|
||||
|
||||
If the newtop is bigger than the previous one, the new posistions in the stack will be
|
||||
If the newtop is bigger than the previous one, the new positions in the stack will be
|
||||
filled with null values.
|
||||
|
||||
The following function pushes a C value into the stack::
|
||||
@@ -92,6 +92,7 @@ the result can be one of the following values: ::
|
||||
The following functions convert a squirrel value in the stack to a C value::
|
||||
|
||||
SQRESULT sq_getstring(HSQUIRRELVM v,SQInteger idx,const SQChar **c);
|
||||
SQRESULT sq_getstringandsize(HSQUIRRELVM v,SQInteger idx,const SQChar **c,SQInteger size);
|
||||
SQRESULT sq_getinteger(HSQUIRRELVM v,SQInteger idx,SQInteger *i);
|
||||
SQRESULT sq_getfloat(HSQUIRRELVM v,SQInteger idx,SQFloat *f);
|
||||
SQRESULT sq_getuserpointer(HSQUIRRELVM v,SQInteger idx,SQUserPointer *p);
|
||||
|
||||
@@ -26,4 +26,4 @@ All declarations needed for embedding the language in an application are in the
|
||||
embedding/userdata_and_userpointers.rst
|
||||
embedding/the_registry_table.rst
|
||||
embedding/references_from_c.rst
|
||||
embedding/debug_interface.rst
|
||||
embedding/debug_interface.rst
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
Squirrel 3.1 Reference Manual
|
||||
#################################
|
||||
|
||||
Copyrigth (c) 2003-2016 Alberto Demichelis
|
||||
Copyright (c) 2003-2016 Alberto Demichelis
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -31,4 +31,4 @@ THE SOFTWARE.
|
||||
introduction.rst
|
||||
language.rst
|
||||
embedding_squirrel.rst
|
||||
api_reference.rst
|
||||
api_reference.rst
|
||||
|
||||
@@ -7,10 +7,10 @@ Introduction
|
||||
.. index::
|
||||
single: introduction
|
||||
|
||||
Squirrel is a high level imperative-OO programming language, designed to be a powerful
|
||||
scripting tool that fits in the size, memory bandwidth, and real-time requirements of
|
||||
Squirrel is a high-level, imperative-OO programming language, designed to be a powerful
|
||||
scripting tool that fits within the size, memory bandwidth, and real-time requirements of
|
||||
applications like games.
|
||||
Although Squirrel offers a wide range of features like dynamic typing, delegation, higher
|
||||
Squirrel offers a wide range of features like dynamic typing, delegation, higher
|
||||
order functions, generators, tail recursion, exception handling, automatic memory
|
||||
management, both compiler and virtual machine fit together in about 6k lines of C++
|
||||
code.
|
||||
management while fitting both compiler and virtual machine into about 6k lines of C++
|
||||
code.
|
||||
|
||||
@@ -20,4 +20,4 @@
|
||||
language/weak_references.rst
|
||||
language/delegation.rst
|
||||
language/metamethods.rst
|
||||
language/builtin_functions.rst
|
||||
language/builtin_functions.rst
|
||||
|
||||
@@ -16,8 +16,7 @@ Global Symbols
|
||||
|
||||
.. js:function:: array(size,[fill])
|
||||
|
||||
create and returns array of a specified size.if the optional parameter fill is specified its
|
||||
value will be used to fill the new array's slots. If the fill paramter is omitted null is used instead.
|
||||
creates and returns array of a specified size. If the optional parameter fill is specified its value will be used to fill the new array's slots. If the fill parameter is omitted, null is used instead.
|
||||
|
||||
.. js:function:: seterrorhandler(func)
|
||||
|
||||
@@ -36,7 +35,7 @@ sets the debug hook
|
||||
|
||||
.. js:function:: enabledebuginfo(enable)
|
||||
|
||||
enable/disable the debug line information generation at compile time. enable != null enables . enable == null disables.
|
||||
enable/disable the debug line information generation at compile time. enable != null enables. enable == null disables.
|
||||
|
||||
.. js:function:: getroottable()
|
||||
|
||||
@@ -52,15 +51,15 @@ returns the const table of the VM.
|
||||
|
||||
.. js:function:: setconsttable(table)
|
||||
|
||||
sets the const table of the VM. And returns the previous const table.
|
||||
sets the const table of the VM; returns the previous const table.
|
||||
|
||||
.. js:function:: assert(exp)
|
||||
.. js:function:: assert(exp, [message])
|
||||
|
||||
throws an exception if exp is null
|
||||
throws an exception if exp is null or false. Throws "assertion failed" string by default, or message if specified.
|
||||
|
||||
.. js:function:: print(x)
|
||||
|
||||
prints x in the standard output
|
||||
prints x to the standard output
|
||||
|
||||
.. js:function:: error(x)
|
||||
|
||||
@@ -76,15 +75,15 @@ compiles a string containing a squirrel script into a function and returns it::
|
||||
|
||||
.. js:function:: collectgarbage()
|
||||
|
||||
runs the garbage collector and returns the number of reference cycles found(and deleted) This function only works on garbage collector builds.
|
||||
Runs the garbage collector and returns the number of reference cycles found (and deleted). This function only works on garbage collector builds.
|
||||
|
||||
.. js:function:: resurrectunreachable()
|
||||
|
||||
runs the garbage collector and returns an array containing all unreachable object found. If no unreachable object is found, null is returned instead. This function is meant to help debugging reference cycles. This function only works on garbage collector builds.
|
||||
Runs the garbage collector and returns an array containing all unreachable object found. If no unreachable object is found, null is returned instead. This function is meant to help debugging reference cycles. This function only works on garbage collector builds.
|
||||
|
||||
.. js:function:: type(obj)
|
||||
|
||||
return the 'raw' type of an object without invoking the metatmethod '_typeof'.
|
||||
return the 'raw' type of an object without invoking the metamethod '_typeof'.
|
||||
|
||||
.. js:function:: getstackinfos(level)
|
||||
|
||||
@@ -105,7 +104,7 @@ returns the stack informations of a given call stack level. returns a table form
|
||||
}
|
||||
}
|
||||
|
||||
level = 0 is the current function, level = 1 is the caller and so on. If the stack level doesn't exist the function returns null.
|
||||
level = 0 is getstackinfos() itself! level = 1 is the current function, level = 2 is the caller of the current function, and so on. If the stack level doesn't exist the function returns null.
|
||||
|
||||
.. js:function:: newthread(threadfunc)
|
||||
|
||||
@@ -113,7 +112,7 @@ creates a new cooperative thread object(coroutine) and returns it
|
||||
|
||||
.. js:data:: _versionnumber_
|
||||
|
||||
integer values describing the version of VM and compiler. eg. for Squirrel 3.0.1 this value will be 301
|
||||
integer values describing the version of VM and compiler. e.g. for Squirrel 3.0.1 this value will be 301
|
||||
|
||||
.. js:data:: _version_
|
||||
|
||||
@@ -121,15 +120,15 @@ string values describing the version of VM and compiler.
|
||||
|
||||
.. js:data:: _charsize_
|
||||
|
||||
size in bytes of the internal VM rapresentation for characters(1 for ASCII builds 2 for UNICODE builds).
|
||||
size in bytes of the internal VM representation for characters(1 for ASCII builds 2 for UNICODE builds).
|
||||
|
||||
.. js:data:: _intsize_
|
||||
|
||||
size in bytes of the internal VM rapresentation for integers(4 for 32bits builds 8 for 64bits builds).
|
||||
size in bytes of the internal VM representation for integers(4 for 32bits builds 8 for 64bits builds).
|
||||
|
||||
.. js:data:: _floatsize_
|
||||
|
||||
size in bytes of the internal VM rapresentation for floats(4 for single precision builds 8 for double precision builds).
|
||||
size in bytes of the internal VM representation for floats(4 for single precision builds 8 for double precision builds).
|
||||
|
||||
-----------------
|
||||
Default delegates
|
||||
@@ -153,17 +152,17 @@ converts the number to string and returns it
|
||||
|
||||
.. js:function:: integer.tointeger()
|
||||
|
||||
returns the value of the integer(dummy function)
|
||||
dummy function; returns the value of the integer.
|
||||
|
||||
|
||||
.. js:function:: integer.tochar()
|
||||
|
||||
returns a string containing a single character rapresented by the integer.
|
||||
returns a string containing a single character represented by the integer.
|
||||
|
||||
|
||||
.. js:function:: integer.weakref()
|
||||
|
||||
dummy function, returns the integer itself.
|
||||
dummy function; returns the integer itself.
|
||||
|
||||
^^^^^
|
||||
Float
|
||||
@@ -186,12 +185,12 @@ converts the number to string and returns it
|
||||
|
||||
.. js:function:: float.tochar()
|
||||
|
||||
returns a string containing a single character rapresented by the integer part of the float.
|
||||
returns a string containing a single character represented by the integer part of the float.
|
||||
|
||||
|
||||
.. js:function:: float.weakref()
|
||||
|
||||
dummy function, returns the float itself.
|
||||
dummy function; returns the float itself.
|
||||
|
||||
^^^^
|
||||
Bool
|
||||
@@ -209,12 +208,12 @@ returns 1 for true 0 for false
|
||||
|
||||
.. js:function:: bool.tostring()
|
||||
|
||||
returns "true" for true "false" for false
|
||||
returns "true" for true and "false" for false
|
||||
|
||||
|
||||
.. js:function:: bool.weakref()
|
||||
|
||||
dummy function, returns the bool itself.
|
||||
dummy function; returns the bool itself.
|
||||
|
||||
^^^^^^
|
||||
String
|
||||
@@ -227,7 +226,7 @@ returns the string length
|
||||
|
||||
.. js:function:: string.tointeger([base])
|
||||
|
||||
converts the string to integer and returns it.An optional parameter base can be specified, if a base is not specified it defaults to base 10
|
||||
Converts the string to integer and returns it. An optional parameter base can be specified--if a base is not specified, it defaults to base 10.
|
||||
|
||||
|
||||
.. js:function:: string.tofloat()
|
||||
@@ -237,7 +236,7 @@ converts the string to float and returns it
|
||||
|
||||
.. js:function:: string.tostring()
|
||||
|
||||
returns the string(dummy function)
|
||||
returns the string (really, a dummy function)
|
||||
|
||||
|
||||
.. js:function:: string.slice(start,[end])
|
||||
@@ -247,7 +246,7 @@ returns a section of the string as new string. Copies from start to the end (not
|
||||
|
||||
.. js:function:: string.find(substr,[startidx])
|
||||
|
||||
search a sub string(substr) starting from the index startidx and returns the index of its first occurrence. If startidx is omitted the search operation starts from the beginning of the string. The function returns null if substr is not found.
|
||||
Searches a sub string (substr) starting from the index startidx and returns the index of its first occurrence. If startidx is omitted the search operation starts from the beginning of the string. The function returns null if substr is not found.
|
||||
|
||||
|
||||
.. js:function:: string.tolower()
|
||||
@@ -280,17 +279,17 @@ tries to get a value from the slot 'key' without employing delegation
|
||||
|
||||
.. js:function:: table.rawset(key,val)
|
||||
|
||||
sets the slot 'key' with the value 'val' without employing delegation. If the slot does not exists , it will be created.
|
||||
Sets the slot 'key' with the value 'val' without employing delegation. If the slot does not exists, it will be created. Returns table itself.
|
||||
|
||||
|
||||
.. js:function:: table.rawdelete()
|
||||
|
||||
deletes the slot key without emplying delegetion and retunrs his value. if the slo does not exists returns always null.
|
||||
Deletes the slot key without employing delegation and returns its value. If the slot does not exists, returns null.
|
||||
|
||||
|
||||
.. js:function:: table.rawin(key)
|
||||
|
||||
returns true if the slot 'key' exists. the function has the same eddect as the operator 'in' but does not employ delegation.
|
||||
returns true if the slot 'key' exists. the function has the same effect as the operator 'in' but does not employ delegation.
|
||||
|
||||
|
||||
.. js:function:: table.weakref()
|
||||
@@ -300,23 +299,28 @@ returns a weak reference to the object.
|
||||
|
||||
.. js:function:: table.tostring()
|
||||
|
||||
tries to invoke the _tostring metamethod, if failed. returns "(table : pointer)".
|
||||
Tries to invoke the _tostring metamethod. If that fails, it returns "(table : pointer)".
|
||||
|
||||
|
||||
.. js:function:: table.clear()
|
||||
|
||||
removes all the slot from the table
|
||||
removes all the slots from the table. Returns table itself.
|
||||
|
||||
|
||||
.. js:function:: table.setdelegate(table)
|
||||
|
||||
sets the delegate of the table, to remove a delegate 'null' must be passed to the function. The function returns the table itself (eg. a.setdelegate(b) in this case 'a' is the return value).
|
||||
Sets the delegate of the table. To remove a delegate, 'null' must be passed to the function. The function returns the table itself (e.g. a.setdelegate(b) -- in this case 'a' is the return value).
|
||||
|
||||
|
||||
.. js:function:: table.getdelegate()
|
||||
|
||||
returns the table's delegate or null if no delegate was set.
|
||||
|
||||
|
||||
.. js:function:: table.filter(func(key,val))
|
||||
|
||||
Creates a new table with all values that pass the test implemented by the provided function. In detail, it creates a new table, invokes the specified function for each key-value pair in the original table; if the function returns 'true', then the value is added to the newly created table at the same key.
|
||||
|
||||
^^^^^^
|
||||
Array
|
||||
^^^^^^
|
||||
@@ -328,17 +332,17 @@ returns the length of the array
|
||||
|
||||
.. js:function:: array.append(val)
|
||||
|
||||
appends the value 'val' at the end of the array
|
||||
appends the value 'val' at the end of the array. Returns array itself.
|
||||
|
||||
|
||||
.. js:function:: array.push(val)
|
||||
|
||||
appends the value 'val' at the end of the array
|
||||
appends the value 'val' at the end of the array. Returns array itself.
|
||||
|
||||
|
||||
.. js:function:: array.extend(array)
|
||||
|
||||
Extends the array by appending all the items in the given array.
|
||||
Extends the array by appending all the items in the given array. Returns array itself.
|
||||
|
||||
|
||||
.. js:function:: array.pop()
|
||||
@@ -353,22 +357,22 @@ returns the value of the array with the higher index
|
||||
|
||||
.. js:function:: array.insert(idx,val)
|
||||
|
||||
inserst the value 'val' at the position 'idx' in the array
|
||||
inserts the value 'val' at the position 'idx' in the array. Returns array itself.
|
||||
|
||||
|
||||
.. js:function:: array.remove(idx)
|
||||
|
||||
removes the value at the position 'idx' in the array
|
||||
removes the value at the position 'idx' in the array and returns its value.
|
||||
|
||||
|
||||
.. js:function:: array.resize(size,[fill])
|
||||
|
||||
resizes the array, if the optional parameter fill is specified its value will be used to fill the new array's slots(if the size specified is bigger than the previous size) . If the fill paramter is omitted null is used instead.
|
||||
Resizes the array. If the optional parameter 'fill' is specified, its value will be used to fill the new array's slots when the size specified is bigger than the previous size. If the fill parameter is omitted, null is used instead. Returns array itself.
|
||||
|
||||
|
||||
.. js:function:: array.sort([compare_func])
|
||||
|
||||
sorts the array. a custom compare function can be optionally passed.The function prototype as to be the following.::
|
||||
Sorts the array in-place. A custom compare function can be optionally passed. The function prototype as to be the following.::
|
||||
|
||||
function custom_compare(a,b)
|
||||
{
|
||||
@@ -381,16 +385,16 @@ a more compact version of a custom compare can be written using a lambda express
|
||||
|
||||
arr.sort(@(a,b) a <=> b);
|
||||
|
||||
|
||||
Returns array itself.
|
||||
|
||||
.. js:function:: array.reverse()
|
||||
|
||||
reverse the elements of the array in place
|
||||
reverse the elements of the array in place. Returns array itself.
|
||||
|
||||
|
||||
.. js:function:: array.slice(start,[end])
|
||||
|
||||
returns a section of the array as new array. Copies from start to the end (not included). If start is negative the index is calculated as length + start, if end is negative the index is calculated as length + end. If end is omitted end is equal to the array length.
|
||||
Returns a section of the array as new array. Copies from start to the end (not included). If start is negative the index is calculated as length + start, if end is negative the index is calculated as length + end. If end is omitted end is equal to the array length.
|
||||
|
||||
|
||||
.. js:function:: array.weakref()
|
||||
@@ -410,7 +414,7 @@ removes all the items from the array
|
||||
|
||||
.. js:function:: array.map(func(a))
|
||||
|
||||
creates a new array of the same size. for each element in the original array invokes the function 'func' and assigns the return value of the function to the corresponding element of the newly created array.
|
||||
Creates a new array of the same size. For each element in the original array invokes the function 'func' and assigns the return value of the function to the corresponding element of the newly created array.
|
||||
|
||||
|
||||
.. js:function:: array.apply(func(a))
|
||||
@@ -420,7 +424,7 @@ for each element in the array invokes the function 'func' and replace the origin
|
||||
|
||||
.. js:function:: array.reduce(func(prevval,curval))
|
||||
|
||||
Reduces an array to a single value. For each element in the array invokes the function 'func' passing the initial value (or value from the previous callback call) and the value of the current element. the return value of the function is then used as 'prevval' for the next element. Given an array of length 0, returns null. Given an array of length 1, returns the first element. Given an array with 2 or more elements calls the function with the first two elements as the parameters, gets that result, then calls the function with that result and the third element, gets that result, calls the function with that result and the fourth parameter and so on until all element have been processed. Finally returns the return value of the last invocation of func.
|
||||
Reduces an array to a single value. For each element in the array invokes the function 'func' passing the initial value (or value from the previous callback call) and the value of the current element. the return value of the function is then used as 'prevval' for the next element. Given an array of length 0, returns null. Given an array of length 1, returns the first element. Given an array with 2 or more elements calls the function with the first two elements as the parameters, gets that result, then calls the function with that result and the third element, gets that result, calls the function with that result and the fourth parameter and so on until all element have been processed. Finally, returns the return value of the last invocation of func.
|
||||
|
||||
|
||||
.. js:function:: array.filter(func(index,val))
|
||||
@@ -436,52 +440,52 @@ Performs a linear search for the value in the array. Returns the index of the va
|
||||
Function
|
||||
^^^^^^^^
|
||||
|
||||
.. js:function:: array.call(_this,args...)
|
||||
.. js:function:: function.call(_this,args...)
|
||||
|
||||
calls the function with the specified environment object('this') and parameters
|
||||
|
||||
|
||||
.. js:function:: array.pcall(_this,args...)
|
||||
.. js:function:: function.pcall(_this,args...)
|
||||
|
||||
calls the function with the specified environment object('this') and parameters, this function will not invoke the error callback in case of failure(pcall stays for 'protected call')
|
||||
|
||||
|
||||
.. js:function:: array.acall(array_args)
|
||||
.. js:function:: function.acall(array_args)
|
||||
|
||||
calls the function with the specified environment object('this') and parameters. The function accepts an array containing the parameters that will be passed to the called function.Where array_args has to contain the required 'this' object at the [0] position.
|
||||
|
||||
|
||||
.. js:function:: array.pacall(array_args)
|
||||
.. js:function:: function.pacall(array_args)
|
||||
|
||||
calls the function with the specified environment object('this') and parameters. The function accepts an array containing the parameters that will be passed to the called function.Where array_args has to contain the required 'this' object at the [0] position. This function will not invoke the error callback in case of failure(pacall stays for 'protected array call')
|
||||
|
||||
|
||||
.. js:function:: array.weakref()
|
||||
.. js:function:: function.weakref()
|
||||
|
||||
returns a weak reference to the object.
|
||||
|
||||
|
||||
.. js:function:: array.tostring()
|
||||
.. js:function:: function.tostring()
|
||||
|
||||
returns the string "(closure : pointer)".
|
||||
|
||||
|
||||
.. js:function:: array.setroot(table)
|
||||
.. js:function:: function.setroot(table)
|
||||
|
||||
sets the root table of a closure
|
||||
|
||||
|
||||
.. js:function:: array.getroot()
|
||||
.. js:function:: function.getroot()
|
||||
|
||||
returns the root table of the closure
|
||||
|
||||
|
||||
.. js:function:: array.bindenv(env)
|
||||
.. js:function:: function.bindenv(env)
|
||||
|
||||
clones the function(aka closure) and bind the enviroment object to it(table,class or instance). the this parameter of the newly create function will always be set to env. Note that the created function holds a weak reference to its environment object so cannot be used to control its lifetime.
|
||||
clones the function(aka closure) and bind the environment object to it(table,class or instance). the this parameter of the newly create function will always be set to env. Note that the created function holds a weak reference to its environment object so cannot be used to control its lifetime.
|
||||
|
||||
|
||||
.. js:function:: array.getinfos()
|
||||
.. js:function:: function.getinfos()
|
||||
|
||||
returns a table containing informations about the function, like parameters, name and source name; ::
|
||||
|
||||
@@ -511,7 +515,7 @@ Class
|
||||
|
||||
.. js:function:: class.instance()
|
||||
|
||||
returns a new instance of the class. this function does not invoke the instance constructor. The constructor must be explicitly called( eg. class_inst.constructor(class_inst) ).
|
||||
returns a new instance of the class. this function does not invoke the instance constructor. The constructor must be explicitly called (eg. class_inst.constructor(class_inst) ).
|
||||
|
||||
|
||||
.. js:function:: class.getattributes(membername)
|
||||
@@ -526,7 +530,7 @@ sets the attribute of the specified member and returns the previous attribute va
|
||||
|
||||
.. js:function:: class.rawin(key)
|
||||
|
||||
returns true if the slot 'key' exists. the function has the same eddect as the operator 'in' but does not employ delegation.
|
||||
returns true if the slot 'key' exists. the function has the same effect as the operator 'in' but does not employ delegation.
|
||||
|
||||
|
||||
.. js:function:: class.weakref()
|
||||
@@ -546,7 +550,7 @@ tries to get a value from the slot 'key' without employing delegation
|
||||
|
||||
.. js:function:: class.rawset(key,val)
|
||||
|
||||
sets the slot 'key' with the value 'val' without employing delegation. If the slot does not exists , it will be created.
|
||||
sets the slot 'key' with the value 'val' without employing delegation. If the slot does not exists, it will be created.
|
||||
|
||||
|
||||
.. js:function:: class.newmember(key,val,[attrs],[bstatic])
|
||||
@@ -556,7 +560,7 @@ sets/adds the slot 'key' with the value 'val' and attributes 'attrs' and if pres
|
||||
|
||||
.. js:function:: class.rawnewmember(key,val,[attrs],[bstatic])
|
||||
|
||||
sets/adds the slot 'key' with the value 'val' and attributes 'attrs'.If bstatic is true the slot will be added as static. If the slot does not exists , it will be created. It doesn't invoke any metamethod.
|
||||
sets/adds the slot 'key' with the value 'val' and attributes 'attrs'. If bstatic is true the slot will be added as static. If the slot does not exist, it will be created. It doesn't invoke any metamethod.
|
||||
|
||||
^^^^^^^^^^^^^^
|
||||
Class Instance
|
||||
@@ -571,7 +575,7 @@ returns the class that created the instance.
|
||||
|
||||
:param key: ze key
|
||||
|
||||
returns true if the slot 'key' exists. the function has the same eddect as the operator 'in' but does not employ delegation.
|
||||
returns true if the slot 'key' exists. the function has the same effect as the operator 'in' but does not employ delegation.
|
||||
|
||||
|
||||
.. js:function:: instance.weakref()
|
||||
@@ -581,7 +585,7 @@ returns a weak reference to the object.
|
||||
|
||||
.. js:function:: instance.tostring()
|
||||
|
||||
tries to invoke the _tostring metamethod, if failed. returns "(insatnce : pointer)".
|
||||
tries to invoke the _tostring metamethod, if failed. returns "(instance : pointer)".
|
||||
|
||||
|
||||
.. js:function:: instance.rawget(key)
|
||||
@@ -591,7 +595,7 @@ tries to get a value from the slot 'key' without employing delegation
|
||||
|
||||
.. js:function:: instance.rawset(key,val)
|
||||
|
||||
sets the slot 'key' with the value 'val' without employing delegation. If the slot does not exists , it will be created.
|
||||
sets the slot 'key' with the value 'val' without employing delegation. If the slot does not exists, it will be created.
|
||||
|
||||
^^^^^^^^^^^^^^
|
||||
Generator
|
||||
@@ -656,7 +660,7 @@ Weak Reference
|
||||
|
||||
.. js:function:: weakreference.ref()
|
||||
|
||||
returns the object that the weak reference is pointing at, null if the object that was point at was destroyed.
|
||||
returns the object that the weak reference is pointing at; null if the object that was point at was destroyed.
|
||||
|
||||
|
||||
.. js:function:: weakreference.weakref()
|
||||
|
||||
@@ -46,7 +46,7 @@ For instance: ::
|
||||
|
||||
}
|
||||
|
||||
the previous code examples is a syntactic sugar for: ::
|
||||
the previous code example is a syntactic sugar for: ::
|
||||
|
||||
Foo <- class {
|
||||
//constructor
|
||||
@@ -67,7 +67,7 @@ the previous code examples is a syntactic sugar for: ::
|
||||
|
||||
}
|
||||
|
||||
in order to emulate namespaces, is also possible to declare something like this::
|
||||
in order to emulate namespaces, it is also possible to declare something like this::
|
||||
|
||||
//just 2 regular nested tables
|
||||
FakeNamespace <- {
|
||||
@@ -214,7 +214,7 @@ class declaration. The values are copied verbatim, *no cloning is performed* eve
|
||||
|
||||
.. note:: FOR C# and Java programmers:
|
||||
|
||||
Squirrel doesn't clone member's default values nor executes the member declaration for each instace(as C# or java).
|
||||
Squirrel doesn't clone member's default values nor executes the member declaration for each instance(as C# or java).
|
||||
|
||||
So consider this example: ::
|
||||
|
||||
@@ -226,8 +226,8 @@ class declaration. The values are copied verbatim, *no cloning is performed* eve
|
||||
local a = Foo();
|
||||
local b = Foo();
|
||||
|
||||
In the snippet above both instances will refer to the same array and same table.To archieve what a C# or Java programmer would
|
||||
exepect, the following approach should be taken. ::
|
||||
In the snippet above both instances will refer to the same array and same table.To achieve what a C# or Java programmer would
|
||||
expect, the following approach should be taken. ::
|
||||
|
||||
class Foo {
|
||||
myarray = null
|
||||
@@ -327,7 +327,7 @@ Here an example: ::
|
||||
}
|
||||
}
|
||||
|
||||
Same rule apply to the constructor. The constructor is a regular function (apart from being automatically invoked on contruction).::
|
||||
Same rule apply to the constructor. The constructor is a regular function (apart from being automatically invoked on construction).::
|
||||
|
||||
class BaseClass {
|
||||
constructor()
|
||||
|
||||
@@ -2,16 +2,16 @@
|
||||
|
||||
|
||||
========================
|
||||
Constants & Enumarations
|
||||
Constants & Enumerations
|
||||
========================
|
||||
|
||||
.. index::
|
||||
single: Constants & Enumarations
|
||||
single: Constants & Enumerations
|
||||
|
||||
|
||||
|
||||
Squirrel allows to bind constant values to an identifier that will be evaluated compile-time.
|
||||
This is archieved though constants and enumarations.
|
||||
This is achieved though constants and Enumerations.
|
||||
|
||||
---------------
|
||||
Constants
|
||||
@@ -20,7 +20,7 @@ Constants
|
||||
.. index::
|
||||
single: Constants
|
||||
|
||||
Constants bind a specific value to an indentifier. Constants are similar to
|
||||
Constants bind a specific value to an identifier. Constants are similar to
|
||||
global values, except that they are evaluated compile time and their value cannot be changed.
|
||||
|
||||
constants values can only be integers, floats or string literals. No expression are allowed.
|
||||
@@ -28,7 +28,7 @@ are declared with the following syntax.::
|
||||
|
||||
const foobar = 100;
|
||||
const floatbar = 1.2;
|
||||
const stringbar = "I'm a contant string";
|
||||
const stringbar = "I'm a constant string";
|
||||
|
||||
constants are always globally scoped, from the moment they are declared, any following code
|
||||
can reference them.
|
||||
@@ -37,17 +37,17 @@ Constants will shadow any global slot with the same name( the global slot will r
|
||||
local x = foobar * 2;
|
||||
|
||||
---------------
|
||||
Enumrations
|
||||
Enumerations
|
||||
---------------
|
||||
|
||||
.. index::
|
||||
single: Enumrations
|
||||
single: Enumerations
|
||||
|
||||
As Constants, Enumerations bind a specific value to a name. Enumerations are also evaluated compile time
|
||||
As Constants, Enumerations bind a specific value to a name. Enumerations are also evaluated at compile time
|
||||
and their value cannot be changed.
|
||||
|
||||
An enum declaration introduces a new enumeration into the program.
|
||||
Enumerations values can only be integers, floats or string literals. No expression are allowed.::
|
||||
Enumeration values can only be integers, floats or string literals. No expression are allowed.::
|
||||
|
||||
enum Stuff {
|
||||
first, //this will be 0
|
||||
@@ -73,7 +73,7 @@ Enumerations will shadow any global slot with the same name( the global slot wil
|
||||
Implementation notes
|
||||
--------------------
|
||||
|
||||
Enumerations and Contants are a compile-time feature. Only integers, string and floats can be declared as const/enum;
|
||||
Enumerations and Constants are a compile-time feature. Only integers, string and floats can be declared as const/enum;
|
||||
No expressions are allowed(because they would have to be evaluated compile time).
|
||||
When a const or an enum is declared, it is added compile time to the ``consttable``. This table is stored in the VM shared state
|
||||
and is shared by the VM and all its threads.
|
||||
|
||||
@@ -4,10 +4,11 @@
|
||||
Values and Data types
|
||||
=====================
|
||||
|
||||
Squirrel is a dynamically typed language so variables do not have a type, although they
|
||||
refer to a value that does have a type.
|
||||
Squirrel basic types are integer, float, string, null, table, array, function, generator,
|
||||
class, instance, bool, thread and userdata.
|
||||
While Squirrel is a dynamically typed language and variables do not
|
||||
have a type, different operations may interpret the variable as
|
||||
containing a type. Squirrel's basic types are integer, float, string,
|
||||
null, table, array, function, generator, class, instance, bool, thread
|
||||
and userdata.
|
||||
|
||||
.. _userdata-index:
|
||||
|
||||
@@ -15,7 +16,7 @@ class, instance, bool, thread and userdata.
|
||||
Integer
|
||||
--------
|
||||
|
||||
An Integer represents a 32 bits (or better) signed number.::
|
||||
An Integer represents a 32 bit (or better) signed number.::
|
||||
|
||||
local a = 123 //decimal
|
||||
local b = 0x0012 //hexadecimal
|
||||
@@ -26,7 +27,7 @@ An Integer represents a 32 bits (or better) signed number.::
|
||||
Float
|
||||
--------
|
||||
|
||||
A float represents a 32 bits (or better) floating point number.::
|
||||
A float represents a 32 bit (or better) floating point number.::
|
||||
|
||||
local a=1.0
|
||||
local b=0.234
|
||||
@@ -35,24 +36,27 @@ A float represents a 32 bits (or better) floating point number.::
|
||||
String
|
||||
--------
|
||||
|
||||
Strings are an immutable sequence of characters to modify a string is necessary create a new one.
|
||||
Strings are an immutable sequence of characters. In order to modify a
|
||||
string is it necessary create a new one.
|
||||
|
||||
Squirrel's strings, behave like C or C++, are delimited by quotation marks(``"``) and can contain
|
||||
escape sequences(``\t``, ``\a``, ``\b``, ``\n``, ``\r``, ``\v``, ``\f``, ``\\``, ``\"``, ``\'``, ``\0``,
|
||||
``\x<hh>``, ``\u<hhhh>`` and ``\U<hhhhhhhh>``).
|
||||
Squirrel's strings are similar to strings in C or C++. They are
|
||||
delimited by quotation marks(``"``) and can contain escape
|
||||
sequences (``\t``, ``\a``, ``\b``, ``\n``, ``\r``, ``\v``, ``\f``,
|
||||
``\\``, ``\"``, ``\'``, ``\0``, ``\x<hh>``, ``\u<hhhh>`` and
|
||||
``\U<hhhhhhhh>``).
|
||||
|
||||
Verbatim string literals begin with ``@"`` and end with the matching quote.
|
||||
Verbatim string literals also can extend over a line break. If they do, they
|
||||
include any white space characters between the quotes: ::
|
||||
Verbatim string literals do not interpret escape sequences. They begin
|
||||
with ``@"`` and end with the matching quote. Verbatim string literals
|
||||
also can extend over a line break. If they do, they include any white
|
||||
space characters between the quotes: ::
|
||||
|
||||
local a = "I'm a wonderful string\n"
|
||||
// has a newline at the end of the string
|
||||
local x = @"I'm a verbatim string\n"
|
||||
// the \n is copied in the string same as \\n in a regular string "I'm a verbatim string\n"
|
||||
// the \n is literal, similar to "\\n" in a regular string.
|
||||
|
||||
The only exception to the "no escape sequence" rule for verbatim
|
||||
string literals is that you can put a double quotation mark inside a
|
||||
verbatim string by doubling it: ::
|
||||
However, a doubled quotation mark within a verbatim string is replaced
|
||||
by a single quotation mark: ::
|
||||
|
||||
local multiline = @"
|
||||
this is a multiline string
|
||||
@@ -73,7 +77,7 @@ reference. The type Null has exactly one value, called null.::
|
||||
Bool
|
||||
--------
|
||||
|
||||
the bool data type can have only two. They are the literals ``true``
|
||||
Bool is a double-valued (Boolean) data type. Its literals are ``true``
|
||||
and ``false``. A bool value expresses the validity of a condition
|
||||
(tells whether the condition is true or false).::
|
||||
|
||||
@@ -83,7 +87,8 @@ and ``false``. A bool value expresses the validity of a condition
|
||||
Table
|
||||
--------
|
||||
|
||||
Tables are associative containers implemented as pairs of key/value (called a slot).::
|
||||
Tables are associative containers implemented as a set of key/value pairs
|
||||
called slots.::
|
||||
|
||||
local t={}
|
||||
local test=
|
||||
@@ -96,7 +101,7 @@ Tables are associative containers implemented as pairs of key/value (called a sl
|
||||
Array
|
||||
--------
|
||||
|
||||
Arrays are simple sequence of objects, their size is dynamic and their index starts always from 0.::
|
||||
Arrays are simple sequence of objects. Their size is dynamic and their index always starts from 0.::
|
||||
|
||||
local a = ["I'm","an","array"]
|
||||
local b = [null]
|
||||
@@ -106,53 +111,52 @@ Arrays are simple sequence of objects, their size is dynamic and their index sta
|
||||
Function
|
||||
--------
|
||||
|
||||
Functions are similar to those in other C-like languages and to most programming
|
||||
languages in general, however there are a few key differences (see below).
|
||||
Functions are similar to those in other C-like languages with a few key differences (see below).
|
||||
|
||||
--------
|
||||
Class
|
||||
--------
|
||||
|
||||
Classes are associative containers implemented as pairs of key/value. Classes are created through
|
||||
a 'class expression' or a 'class statement'. class members can be inherited from another class object
|
||||
at creation time. After creation members can be added until a instance of the class is created.
|
||||
Classes are associative containers implemented as sets of key/value
|
||||
pairs. Classes are created through a 'class expression' or a 'class
|
||||
statement'. class members can be inherited from another class object
|
||||
at creation time. After creation, members can be added until an
|
||||
instance of the class is created.
|
||||
|
||||
--------------
|
||||
Class Instance
|
||||
--------------
|
||||
|
||||
Class instances are created by calling a *class object*. Instances, as tables, are
|
||||
implemented as pair of key/value. Instances members cannot be dyncamically added or removed however
|
||||
the value of the members can be changed.
|
||||
|
||||
|
||||
Class instances are created by calling a *class object*. Instances, as
|
||||
tables, are implemented as sets of key/value pairs. Instance members
|
||||
cannot be dynamically added or removed; however the value of the
|
||||
members can be changed.
|
||||
|
||||
---------
|
||||
Generator
|
||||
---------
|
||||
|
||||
Generators are functions that can be suspended with the statement 'yield' and resumed
|
||||
later (see :ref:`Generators <generators>`).
|
||||
Generators are functions that can be suspended with the statement
|
||||
'yield' and resumed later (see :ref:`Generators <generators>`).
|
||||
|
||||
---------
|
||||
Userdata
|
||||
---------
|
||||
|
||||
Userdata objects are blobs of memory(or pointers) defined by the host application but
|
||||
stored into Squirrel variables (See :ref:`Userdata and UserPointers <embedding_userdata_and_userpointers>`).
|
||||
|
||||
Userdata objects are blobs of memory or pointers defined by the host
|
||||
application but stored within Squirrel variables (See :ref:`Userdata
|
||||
and UserPointers <embedding_userdata_and_userpointers>`).
|
||||
|
||||
---------
|
||||
Thread
|
||||
---------
|
||||
|
||||
Threads are objects that represents a cooperative thread of execution, also known as coroutines.
|
||||
Threads are objects representing a cooperative thread of execution,
|
||||
also known as coroutines.
|
||||
|
||||
--------------
|
||||
Weak Reference
|
||||
--------------
|
||||
|
||||
Weak References are objects that point to another(non scalar) object but do not own a strong reference to it.
|
||||
Weak References are objects that point to another (non-scalar) object but do not own a strong reference to it.
|
||||
(See :ref:`Weak References <weak_references>`).
|
||||
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ with tables we can also use the '.' syntax::
|
||||
_table.foo
|
||||
|
||||
Squirrel first checks if an identifier is a local variable (function arguments are local
|
||||
variables) if not looks up the environment object (this) and finally looksup
|
||||
variables) if not looks up the environment object (this) and finally looks up
|
||||
to the closure root.
|
||||
|
||||
For instance:::
|
||||
|
||||
@@ -221,10 +221,10 @@ Bitwise Operators
|
||||
exp:= 'exp' op 'exp'
|
||||
exp := '~' exp
|
||||
|
||||
Squirrel supports the standard c-like bit wise operators ``&, |, ^, ~, <<, >>`` plus the unsigned
|
||||
right shift operator ``<<<``. The unsigned right shift works exactly like the normal right shift operator(``<<``)
|
||||
Squirrel supports the standard C-like bitwise operators ``&, |, ^, ~, <<, >>`` plus the unsigned
|
||||
right shift operator ``>>>``. The unsigned right shift works exactly like the normal right shift operator(``>>``)
|
||||
except for treating the left operand as an unsigned integer, so is not affected by the sign. Those operators
|
||||
only work on integers values, passing of any other operand type to these operators will
|
||||
only work on integer values; passing of any other operand type to these operators will
|
||||
cause an exception.
|
||||
|
||||
^^^^^^^^^^^^^^^^^^^^^
|
||||
@@ -243,7 +243,7 @@ Operators precedence
|
||||
+---------------------------------------+-----------+
|
||||
| ``<<, >>, >>>`` | |
|
||||
+---------------------------------------+-----------+
|
||||
| ``<, <=, >, >=`` | |
|
||||
| ``<, <=, >, >=, instanceof`` | |
|
||||
+---------------------------------------+-----------+
|
||||
| ``==, !=, <=>`` | |
|
||||
+---------------------------------------+-----------+
|
||||
@@ -253,9 +253,9 @@ Operators precedence
|
||||
+---------------------------------------+-----------+
|
||||
| ``&&, in`` | |
|
||||
+---------------------------------------+-----------+
|
||||
| ``+=, =, -=`` | ... |
|
||||
| ``+=, =, -=, /=, *=, %=`` | ... |
|
||||
+---------------------------------------+-----------+
|
||||
| ``,(comma operator)`` | lowest |
|
||||
| ``, (comma operator)`` | lowest |
|
||||
+---------------------------------------+-----------+
|
||||
|
||||
.. _table_contructor:
|
||||
@@ -293,7 +293,7 @@ A new slot with exp1 as key and exp2 as value is created::
|
||||
[1]="I'm the value"
|
||||
}
|
||||
|
||||
both syntaxes can be mixed::
|
||||
Both syntaxes can be mixed::
|
||||
|
||||
local table=
|
||||
{
|
||||
@@ -369,6 +369,6 @@ Creates a new array.::
|
||||
|
||||
a <- [] //creates an empty array
|
||||
|
||||
arrays can be initialized with values during the construction::
|
||||
Arrays can be initialized with values during the construction::
|
||||
|
||||
a <- [1,"string!",[],{}] //creates an array with 4 elements
|
||||
a <- [1,"string!",[],{}] //creates an array with 4 elements
|
||||
|
||||
@@ -140,19 +140,31 @@ Function calls
|
||||
The expression is evaluated in this order: derefexp after the explist (arguments) and at
|
||||
the end the call.
|
||||
|
||||
Every function call in Squirrel passes the environment object *this* as hidden parameter
|
||||
to the called function. The 'this' parameter is the object where the function was indexed
|
||||
from.
|
||||
A function call in Squirrel passes the current environment object *this* as a hidden parameter.
|
||||
But when the function was immediately indexed from an object, *this* shall be the object
|
||||
which was indexed, instead.
|
||||
|
||||
If we call a function with this syntax::
|
||||
If we call a function with the syntax::
|
||||
|
||||
table.foo(a)
|
||||
mytable.foo(x,y)
|
||||
|
||||
the environment object passed to foo will be 'table'::
|
||||
the environment object passed to 'foo' as *this* will be 'mytable' (since 'foo' was immediately indexed from 'mytable')
|
||||
|
||||
foo(x,y) // equivalent to this.foo(x,y)
|
||||
Whereas with the syntax::
|
||||
|
||||
The environment object will be *this* (the same of the caller function).
|
||||
foo(x,y) // implicitly equivalent to this.foo(x,y)
|
||||
|
||||
the environment object will be the current *this* (that is, propagated from the caller's *this*).
|
||||
|
||||
It may help to remember the rules in the following way:
|
||||
|
||||
foo(x,y) ---> this.foo(x,y)
|
||||
table.foo(x,y) ---> call foo with (table,x,y)
|
||||
|
||||
It may also help to consider why it works this way: it's designed to assist with object-oriented style.
|
||||
When calling 'foo(x,y)' it's assumed you're calling another member of the object (or of the file) and
|
||||
so should operate on the same object.
|
||||
When calling 'mytable.foo(x,y)' it's written plainly that you're calling a member of a different object.
|
||||
|
||||
---------------------------------------------
|
||||
Binding an environment to a function
|
||||
@@ -184,7 +196,7 @@ Lambda Expressions
|
||||
|
||||
exp := '@' '(' paramlist ')' exp
|
||||
|
||||
Lambda expressions are a synctactic sugar to quickly define a function that consists of a single expression.
|
||||
Lambda expressions are a syntactic sugar to quickly define a function that consists of a single expression.
|
||||
This feature comes handy when functional programming patterns are applied, like map/reduce or passing a compare method to
|
||||
array.sort().
|
||||
|
||||
|
||||
@@ -13,11 +13,11 @@ Identifiers
|
||||
|
||||
.. index:: single: identifiers
|
||||
|
||||
Identifiers start with a alphabetic character or '_' followed by any number of alphabetic
|
||||
characters, '_' or digits ([0-9]). Squirrel is a case sensitive language, this means that the
|
||||
lowercase and uppercase representation of the same alphabetic character are considered
|
||||
different characters. For instance "foo", "Foo" and "fOo" will be treated as 3 distinct
|
||||
identifiers.
|
||||
Identifiers start with an alphabetic character or the symbol '_' followed by any number
|
||||
of alphabetic characters, '_' or digits ([0-9]). Squirrel is a case sensitive language
|
||||
meaning that the lowercase and uppercase representation of the same alphabetic
|
||||
character are considered different characters. For instance, "foo", "Foo" and "fOo" are
|
||||
treated as 3 distinct identifiers.
|
||||
|
||||
-----------
|
||||
Keywords
|
||||
@@ -25,7 +25,7 @@ Keywords
|
||||
|
||||
.. index:: single: keywords
|
||||
|
||||
The following words are reserved words by the language and cannot be used as identifiers:
|
||||
The following words are reserved and cannot be used as identifiers:
|
||||
|
||||
+------------+------------+-----------+------------+------------+-------------+
|
||||
| base | break | case | catch | class | clone |
|
||||
@@ -69,7 +69,7 @@ Other tokens
|
||||
single: delimiters
|
||||
single: other tokens
|
||||
|
||||
Other used tokens are:
|
||||
Other significant tokens are:
|
||||
|
||||
+----------+----------+----------+----------+----------+----------+
|
||||
| ``{`` | ``}`` | ``[`` | ``]`` | ``.`` | ``:`` |
|
||||
@@ -86,7 +86,7 @@ Literals
|
||||
single: string literals
|
||||
single: numeric literals
|
||||
|
||||
Squirrel accepts integer numbers, floating point numbers and strings literals.
|
||||
Squirrel accepts integer numbers, floating point numbers and string literals.
|
||||
|
||||
+-------------------------------+------------------------------------------+
|
||||
| ``34`` | Integer number(base 10) |
|
||||
@@ -131,7 +131,7 @@ A comment is text that the compiler ignores but that is useful for programmers.
|
||||
Comments are normally used to embed annotations in the code. The compiler
|
||||
treats them as white space.
|
||||
|
||||
The ``/*`` (slash, asterisk) characters, followed by any
|
||||
A comment can be ``/*`` (slash, asterisk) characters, followed by any
|
||||
sequence of characters (including new lines),
|
||||
followed by the ``*/`` characters. This syntax is the same as ANSI C.::
|
||||
|
||||
@@ -141,9 +141,9 @@ followed by the ``*/`` characters. This syntax is the same as ANSI C.::
|
||||
this lines will be ignored by the compiler
|
||||
*/
|
||||
|
||||
The ``//`` (two slashes) characters, followed by any sequence of characters.
|
||||
A new line not immediately preceded by a backslash terminates this form of comment.
|
||||
It is commonly called a *"single-line comment."*::
|
||||
A comment can also be ``//`` (two slashes) characters, followed by any sequence of
|
||||
characters. A new line not immediately preceded by a backslash terminates this form of
|
||||
comment. It is commonly called a *"single-line comment."*::
|
||||
|
||||
//this is a single line comment. this line will be ignored by the compiler
|
||||
|
||||
@@ -152,5 +152,3 @@ The character ``#`` is an alternative syntax for single line comment.::
|
||||
# this is also a single line comment.
|
||||
|
||||
This to facilitate the use of squirrel in UNIX-style shell scripts.
|
||||
|
||||
|
||||
|
||||
@@ -6,11 +6,11 @@ Metamethods
|
||||
|
||||
Metamethods are a mechanism that allows the customization of certain aspects of the
|
||||
language semantics. Those methods are normal functions placed in a table
|
||||
parent(delegate) or class declaration; Is possible to change many aspect of a table/class instance behavior by just defining
|
||||
a metamethod. Class objects(not instances) supports only 2 metamethods ``_newmember, _inherited`` .
|
||||
parent(delegate) or class declaration; It is possible to change many aspects of a table/class instance behavior by just defining
|
||||
a metamethod. Class objects (not instances) support only 2 metamethods ``_newmember, _inherited`` .
|
||||
|
||||
For example when we use relational operators other than '==' on 2 tables, the VM will
|
||||
check if the table has a method in his parent called '_cmp' if so it will call it to determine
|
||||
check if the table has a method in his parent called '_cmp'; if so it will call it to determine
|
||||
the relation between the tables.::
|
||||
|
||||
local comparable={
|
||||
@@ -63,8 +63,8 @@ _set
|
||||
_set(idx,val)
|
||||
|
||||
invoked when the index idx is not present in the object or in its delegate chain.
|
||||
``_set`` must 'throw null' to notify that a key wasn't found but the there were not runtime errors(clean failure).
|
||||
This allows the program to defferentieate between a runtime error and a 'index not found'.
|
||||
``_set`` must 'throw null' to notify that a key wasn't found but the there were not runtime errors (clean failure).
|
||||
This allows the program to differentiate between a runtime error and a 'index not found'.
|
||||
|
||||
^^^^^
|
||||
_get
|
||||
@@ -72,11 +72,11 @@ _get
|
||||
|
||||
::
|
||||
|
||||
_get(idx,val)
|
||||
_get(idx)
|
||||
|
||||
invoked when the index idx is not present in the object or in its delegate chain.
|
||||
_get must 'throw null' to notify that a key wasn't found but the there were not runtime errors(clean failure).
|
||||
This allows the program to defferentieate between a runtime error and a 'index not found'.
|
||||
_get must 'throw null' to notify that a key wasn't found but the there were not runtime errors (clean failure).
|
||||
This allows the program to differentiate between a runtime error and a 'index not found'.
|
||||
|
||||
^^^^^^^^^
|
||||
_newslot
|
||||
@@ -165,16 +165,16 @@ _unm
|
||||
the unary minus operator
|
||||
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
_tyoeof
|
||||
_typeof
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
::
|
||||
|
||||
_tyoeof()
|
||||
_typeof()
|
||||
|
||||
invoked by the typeof operator on tables ,userdata and class instances
|
||||
invoked by the typeof operator on tables, userdata, and class instances.
|
||||
|
||||
returns the type of ``this`` as string
|
||||
Returns the type of ``this`` as string
|
||||
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
_cmp
|
||||
@@ -206,7 +206,7 @@ _call
|
||||
|
||||
_call(other)
|
||||
|
||||
invoked when a table, userdata or class instance is called
|
||||
invoked when a table, userdata, or class instance is called
|
||||
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
_cloned
|
||||
@@ -226,9 +226,9 @@ _nexti
|
||||
|
||||
_nexti(previdx)
|
||||
|
||||
invoked when a userdata or class instance is iterated by a foreach loop
|
||||
invoked when a userdata or class instance is iterated by a foreach loop.
|
||||
|
||||
if previdx==null it means that it is the first iteration.
|
||||
If previdx==null it means that it is the first iteration.
|
||||
The function has to return the index of the 'next' value.
|
||||
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
@@ -237,12 +237,12 @@ _tostring
|
||||
|
||||
::
|
||||
|
||||
_tostring(previdx)
|
||||
_tostring()
|
||||
|
||||
invoked when during string conacatenation or when the ``print`` function prints a table, instance or userdata.
|
||||
The method is also invoked by the sq_tostring() api
|
||||
Invoked when during string concatenation or when the ``print`` function prints a table, instance, or userdata.
|
||||
The method is also invoked by the sq_tostring() API.
|
||||
|
||||
must return a string representation of the object.
|
||||
Must return a string representation of the object.
|
||||
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
_inherited
|
||||
@@ -252,10 +252,10 @@ _inherited
|
||||
|
||||
_inherited(attributes)
|
||||
|
||||
invoked when a class object inherits from the class implementing ``_inherited``
|
||||
the ``this`` contains the new class.
|
||||
invoked when a class object inherits from the class implementing ``_inherited``.
|
||||
The ``this`` contains the new class.
|
||||
|
||||
return value is ignored.
|
||||
Return value is ignored.
|
||||
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
_newmember
|
||||
@@ -265,6 +265,6 @@ _newmember
|
||||
|
||||
_newmember(index,value,attributes,isstatic)
|
||||
|
||||
invoked for each member declared in a class body(at declaration time).
|
||||
invoked for each member declared in a class body (at declaration time).
|
||||
|
||||
if the function is implemented, members will not be added to the class.
|
||||
If the function is implemented, members will not be added to the class.
|
||||
|
||||
@@ -52,7 +52,7 @@ true and false
|
||||
single: true
|
||||
single: false
|
||||
|
||||
Squirrel has a boolean type(bool) however like C++ it considers null, 0(integer) and 0.0(float)
|
||||
Squirrel has a boolean type (bool) however like C++ it considers null, 0(integer) and 0.0(float)
|
||||
as *false*, any other value is considered *true*.
|
||||
|
||||
^^^^^^^^^^^^^^^^^
|
||||
@@ -326,7 +326,7 @@ try/catch
|
||||
stat:= 'try' stat 'catch' '(' id ')' stat
|
||||
|
||||
The try statement encloses a block of code in which an exceptional condition can occur,
|
||||
such as a runtime error or a throw statement. The catch clause provides the exceptionhandling
|
||||
such as a runtime error or a throw statement. The catch clause provides the exception-handling
|
||||
code. When a catch clause catches an exception, its id is bound to that
|
||||
exception.
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ through this type; even the environment, where "global" variables are stored, is
|
||||
Construction
|
||||
------------------
|
||||
|
||||
Tables are created through the table constructor (see :ref:`Table constructor <table_contructor>`)
|
||||
Tables are created through the table constructor (see :ref:`Table constructor <table_constructor>`)
|
||||
|
||||
------------------
|
||||
Slot creation
|
||||
|
||||
@@ -22,17 +22,17 @@ Using threads
|
||||
------------------
|
||||
|
||||
.. index::
|
||||
single: Usign Threads
|
||||
single: Using Threads
|
||||
|
||||
Threads are created through the built-in function 'newthread(func)'; this function
|
||||
gets as parameter a squirrel function and bind it to the new thread objecs(will be the thread body).
|
||||
gets as parameter a squirrel function and bind it to the new thread objects (will be the thread body).
|
||||
The returned thread object is initially in 'idle' state. the thread can be started with the function
|
||||
'threadobj.call()'; the parameters passed to 'call' are passed to the thread function.
|
||||
|
||||
A thread can be be suspended calling the function suspend(), when this happens the function
|
||||
that wokeup(or started) the thread returns (If a parametrer is passed to suspend() it will
|
||||
that wokeup(or started) the thread returns (If a parameter is passed to suspend() it will
|
||||
be the return value of the wakeup function , if no parameter is passed the return value will be null).
|
||||
A suspended thread can be resumed calling the funtion 'threadobj.wakeup', when this happens
|
||||
A suspended thread can be resumed calling the function 'threadobj.wakeup', when this happens
|
||||
the function that suspended the thread will return(if a parameter is passed to wakeup it will
|
||||
be the return value of the suspend function, if no parameter is passed the return value will be null).
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ Weak References
|
||||
The weak references allows the programmers to create references to objects without
|
||||
influencing the lifetime of the object itself.
|
||||
In squirrel Weak references are first-class objects created through the built-in method obj.weakref().
|
||||
All types except null implement the weakref() method; however in bools,integers and float the method
|
||||
All types except null implement the weakref() method; however in bools, integers, and floats the method
|
||||
simply returns the object itself(this because this types are always passed by value).
|
||||
When a weak references is assigned to a container (table slot,array,class or
|
||||
instance) is treated differently than other objects; When a container slot that hold a weak
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
Squirrel Standard Library 3.1
|
||||
#################################
|
||||
|
||||
Copyrigth (c) 2003-2016 Alberto Demichelis
|
||||
Copyright (c) 2003-2016 Alberto Demichelis
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
||||
@@ -28,4 +28,4 @@ C API
|
||||
|
||||
prints the call stack and stack contents. the function
|
||||
uses the print function set through(:ref:`sq_setprintfunc <sq_setprintfunc>`) to output
|
||||
the stack dump.
|
||||
the stack dump.
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
The Blob library
|
||||
==================
|
||||
The blob library implements binary data manipulations routines. The library is
|
||||
based on `blob objects` that rapresent a buffer of arbitrary
|
||||
based on `blob objects` that represent a buffer of arbitrary
|
||||
binary data.
|
||||
|
||||
---------------
|
||||
@@ -60,26 +60,26 @@ A blob can also be accessed byte by byte through the `[]` operator.
|
||||
|
||||
.. js:function:: blob.len()
|
||||
|
||||
returns the lenght of the stream
|
||||
returns the length of the stream
|
||||
|
||||
.. js:function:: blob.readblob(size)
|
||||
|
||||
:param int size: number of bytes to read
|
||||
|
||||
read n bytes from the stream and retuns them as blob
|
||||
read n bytes from the stream and returns them as blob
|
||||
|
||||
.. js:function:: blob.readn(type)
|
||||
|
||||
:param int type: type of the number to read
|
||||
|
||||
reads a number from the stream according to the type pameter.
|
||||
reads a number from the stream according to the type parameter.
|
||||
|
||||
`type` can have the following values:
|
||||
|
||||
+--------------+--------------------------------------------------------------------------------+----------------------+
|
||||
| parameter | return description | return type |
|
||||
+==============+================================================================================+======================+
|
||||
| 'l' | processor dependent, 32bits on 32bits processors, 64bits on 64bits prcessors | integer |
|
||||
| 'l' | processor dependent, 32bits on 32bits processors, 64bits on 64bits processors | integer |
|
||||
+--------------+--------------------------------------------------------------------------------+----------------------+
|
||||
| 'i' | 32bits number | integer |
|
||||
+--------------+--------------------------------------------------------------------------------+----------------------+
|
||||
@@ -98,7 +98,7 @@ A blob can also be accessed byte by byte through the `[]` operator.
|
||||
|
||||
.. js:function:: blob.resize(size)
|
||||
|
||||
:param int size: the new size of the blobl in bytes
|
||||
:param int size: the new size of the blob in bytes
|
||||
|
||||
resizes the blob to the specified `size`
|
||||
|
||||
@@ -142,7 +142,7 @@ A blob can also be accessed byte by byte through the `[]` operator.
|
||||
:param number n: the value to be written
|
||||
:param int type: type of the number to write
|
||||
|
||||
writes a number in the stream formatted according to the `type` pameter
|
||||
writes a number in the stream formatted according to the `type` parameter
|
||||
|
||||
`type` can have the following values:
|
||||
|
||||
@@ -210,4 +210,4 @@ C API
|
||||
:param SQInteger size: the size of the blob payload that has to be created
|
||||
:returns: a pointer to the newly created blob payload
|
||||
|
||||
creates a blob with the given payload size and pushes it in the stack.
|
||||
creates a blob with the given payload size and pushes it in the stack.
|
||||
|
||||
@@ -21,20 +21,20 @@ Global Symbols
|
||||
returns the value returned by the script or null if no value is returned.
|
||||
if the optional parameter 'raiseerror' is true, the compiler error handler is invoked
|
||||
in case of a syntax error. If raiseerror is omitted or set to false, the compiler
|
||||
error handler is not ivoked.
|
||||
When squirrel is compiled in unicode mode the function can handle different character ecodings,
|
||||
error handler is not invoked.
|
||||
When squirrel is compiled in Unicode mode the function can handle different character encodings,
|
||||
UTF8 with and without prefix and UCS-2 prefixed(both big endian an little endian).
|
||||
If the source stream is not prefixed UTF8 ecoding is used as default.
|
||||
If the source stream is not prefixed UTF8 encoding is used as default.
|
||||
|
||||
.. js:function:: loadfile(path, [raiseerror])
|
||||
|
||||
compiles a squirrel script or loads a precompiled one an returns it as as function.
|
||||
if the optional parameter 'raiseerror' is true, the compiler error handler is invoked
|
||||
in case of a syntax error. If raiseerror is omitted or set to false, the compiler
|
||||
error handler is not ivoked.
|
||||
When squirrel is compiled in unicode mode the function can handle different character ecodings,
|
||||
error handler is not invoked.
|
||||
When squirrel is compiled in Unicode mode the function can handle different character encodings,
|
||||
UTF8 with and without prefix and UCS-2 prefixed(both big endian an little endian).
|
||||
If the source stream is not prefixed UTF8 ecoding is used as default.
|
||||
If the source stream is not prefixed UTF8 encoding is used as default.
|
||||
|
||||
.. js:function:: writeclosuretofile(destpath, closure)
|
||||
|
||||
@@ -63,7 +63,7 @@ The file class
|
||||
|
||||
.. js:class:: file(path, patten)
|
||||
|
||||
It's contructor imitates the behaviour of the C runtime function fopen for eg. ::
|
||||
It's constructor imitates the behaviour of the C runtime function fopen for eg. ::
|
||||
|
||||
local myfile = file("test.xxx","wb+");
|
||||
|
||||
@@ -79,30 +79,30 @@ The file class
|
||||
|
||||
.. js:function:: file.flush()
|
||||
|
||||
flushes the stream.return a value != null if succeded, otherwise returns null
|
||||
flushes the stream.return a value != null if succeeded, otherwise returns null
|
||||
|
||||
.. js:function:: file.len()
|
||||
|
||||
returns the lenght of the stream
|
||||
returns the length of the stream
|
||||
|
||||
.. js:function:: file.readblob(size)
|
||||
|
||||
:param int size: number of bytes to read
|
||||
|
||||
read n bytes from the stream and retuns them as blob
|
||||
read n bytes from the stream and returns them as blob
|
||||
|
||||
.. js:function:: file.readn(type)
|
||||
|
||||
:param int type: type of the number to read
|
||||
|
||||
reads a number from the stream according to the type pameter.
|
||||
reads a number from the stream according to the type parameter.
|
||||
|
||||
`type` can have the following values:
|
||||
|
||||
+--------------+--------------------------------------------------------------------------------+----------------------+
|
||||
| parameter | return description | return type |
|
||||
+==============+================================================================================+======================+
|
||||
| 'l' | processor dependent, 32bits on 32bits processors, 64bits on 64bits prcessors | integer |
|
||||
| 'l' | processor dependent, 32bits on 32bits processors, 64bits on 64bits processors | integer |
|
||||
+--------------+--------------------------------------------------------------------------------+----------------------+
|
||||
| 'i' | 32bits number | integer |
|
||||
+--------------+--------------------------------------------------------------------------------+----------------------+
|
||||
@@ -121,7 +121,7 @@ The file class
|
||||
|
||||
.. js:function:: file.resize(size)
|
||||
|
||||
:param int size: the new size of the blobl in bytes
|
||||
:param int size: the new size of the blob in bytes
|
||||
|
||||
resizes the blob to the specified `size`
|
||||
|
||||
@@ -157,7 +157,7 @@ The file class
|
||||
:param number n: the value to be written
|
||||
:param int type: type of the number to write
|
||||
|
||||
writes a number in the stream formatted according to the `type` pameter
|
||||
writes a number in the stream formatted according to the `type` pamraeter
|
||||
|
||||
`type` can have the following values:
|
||||
|
||||
@@ -230,9 +230,9 @@ Script loading and serialization
|
||||
:returns: an SQRESULT
|
||||
|
||||
Compiles a squirrel script or loads a precompiled one an pushes it as closure in the stack.
|
||||
When squirrel is compiled in unicode mode the function can handle different character ecodings,
|
||||
When squirrel is compiled in Unicode mode the function can handle different character encodings,
|
||||
UTF8 with and without prefix and UCS-2 prefixed(both big endian an little endian).
|
||||
If the source stream is not prefixed UTF8 ecoding is used as default.
|
||||
If the source stream is not prefixed UTF8 encoding is used as default.
|
||||
|
||||
.. c:function:: SQRESULT sqstd_dofile(HSQUIRRELVM v, const SQChar* filename, SQBool retval, SQBool printerror)
|
||||
|
||||
@@ -241,13 +241,13 @@ Script loading and serialization
|
||||
:param SQBool retval: if true the function will push the return value of the executed script in the stack.
|
||||
:param SQBool printerror: if true the compiler error handler will be called if a error occurs
|
||||
:returns: an SQRESULT
|
||||
:remarks: the function aspects a table on top of the stack that will be used as 'this' for the execution of the script. The 'this' parameter is left untouched in the stack.
|
||||
:remarks: the function expects a table on top of the stack that will be used as 'this' for the execution of the script. The 'this' parameter is left untouched in the stack.
|
||||
|
||||
Compiles a squirrel script or loads a precompiled one and executes it.
|
||||
Optionally pushes the return value of the executed script in the stack.
|
||||
When squirrel is compiled in unicode mode the function can handle different character ecodings,
|
||||
When squirrel is compiled in unicode mode the function can handle different character encodings,
|
||||
UTF8 with and without prefix and UCS-2 prefixed(both big endian an little endian).
|
||||
If the source stream is not prefixed UTF8 ecoding is used as default. ::
|
||||
If the source stream is not prefixed, UTF8 encoding is used as default. ::
|
||||
|
||||
sq_pushroottable(v); //push the root table(were the globals of the script will are stored)
|
||||
sqstd_dofile(v, _SC("test.nut"), SQFalse, SQTrue);// also prints syntax errors if any
|
||||
@@ -259,6 +259,6 @@ Script loading and serialization
|
||||
:returns: an SQRESULT
|
||||
|
||||
serializes the closure at the top position in the stack as bytecode in
|
||||
the file specified by the paremeter filename. If a file with the
|
||||
the file specified by the parameter filename. If a file with the
|
||||
same name already exists, it will be overwritten.
|
||||
|
||||
|
||||
@@ -17,8 +17,8 @@ Global Symbols
|
||||
.. js:function:: endswith(str, cmp)
|
||||
|
||||
returns `true` if the end of the string `str` matches a the string `cmp` otherwise returns `false`
|
||||
|
||||
.. js:function:: ecape(str)
|
||||
|
||||
.. js:function:: escape(str)
|
||||
|
||||
Returns a string with backslashes before characters that need to be escaped(`\",\a,\b,\t,\n,\v,\f,\r,\\,\",\',\0,\xnn`).
|
||||
|
||||
@@ -28,10 +28,18 @@ Global Symbols
|
||||
The format string follows the same rules as the `printf` family of
|
||||
standard C functions( the "*" is not supported). ::
|
||||
|
||||
eg.
|
||||
e.g.
|
||||
sq> print(format("%s %d 0x%02X\n","this is a test :",123,10));
|
||||
this is a test : 123 0x0A
|
||||
|
||||
.. js:function:: printf(formatstr, ...)
|
||||
|
||||
Just like calling `print(format(formatstr` as in the example above, but is more convenient AND more efficient. ::
|
||||
|
||||
e.g.
|
||||
sq> printf("%s %d 0x%02X\n","this is a test :",123,10);
|
||||
this is a test : 123 0x0A
|
||||
|
||||
.. js:function:: lstrip(str)
|
||||
|
||||
Strips white-space-only characters that might appear at the beginning of the given string
|
||||
@@ -42,7 +50,7 @@ Global Symbols
|
||||
Strips white-space-only characters that might appear at the end of the given string
|
||||
and returns the new stripped string.
|
||||
|
||||
.. js:function:: split(str, separtators)
|
||||
.. js:function:: split(str, separators)
|
||||
|
||||
returns an array of strings split at each point where a separator character occurs in `str`.
|
||||
The separator is not returned as part of any array element.
|
||||
@@ -57,8 +65,8 @@ Global Symbols
|
||||
|
||||
.. js:function:: startswith(str, cmp)
|
||||
|
||||
returns `true` if the beginning of the string `str` matches a the string `cmp` otherwise returns `false`
|
||||
|
||||
returns `true` if the beginning of the string `str` matches the string `cmp`; otherwise returns `false`
|
||||
|
||||
.. js:function:: strip(str)
|
||||
|
||||
Strips white-space-only characters that might appear at the beginning or end of the given string and returns the new stripped string.
|
||||
@@ -69,8 +77,8 @@ The regexp class
|
||||
|
||||
.. js:class:: regexp(pattern)
|
||||
|
||||
The regexp object rapresent a precompiled regular experssion pattern. The object is created
|
||||
trough `regexp(patern)`.
|
||||
The regexp object represents a precompiled regular expression pattern. The object is created
|
||||
through `regexp(pattern)`.
|
||||
|
||||
|
||||
+---------------------+--------------------------------------+
|
||||
@@ -140,19 +148,19 @@ The regexp class
|
||||
+---------------------+--------------------------------------+
|
||||
| `\\d` | digits |
|
||||
+---------------------+--------------------------------------+
|
||||
| `\\D` | non nondigits |
|
||||
| `\\D` | non digits |
|
||||
+---------------------+--------------------------------------+
|
||||
| `\\x` | exadecimal digits |
|
||||
| `\\x` | hexadecimal digits |
|
||||
+---------------------+--------------------------------------+
|
||||
| `\\X` | non exadecimal digits |
|
||||
| `\\X` | non hexadecimal digits |
|
||||
+---------------------+--------------------------------------+
|
||||
| `\\c` | control characters |
|
||||
+---------------------+--------------------------------------+
|
||||
| `\\C` | non control characters |
|
||||
+---------------------+--------------------------------------+
|
||||
| `\\p` | punctation |
|
||||
| `\\p` | punctuation |
|
||||
+---------------------+--------------------------------------+
|
||||
| `\\P` | non punctation |
|
||||
| `\\P` | non punctuation |
|
||||
+---------------------+--------------------------------------+
|
||||
| `\\b` | word boundary |
|
||||
+---------------------+--------------------------------------+
|
||||
@@ -162,13 +170,13 @@ The regexp class
|
||||
|
||||
.. js:function:: regexp.capture(str [, start])
|
||||
|
||||
returns an array of tables containing two indexs("begin" and "end")of
|
||||
returns an array of tables containing two indexes ("begin" and "end") of
|
||||
the first match of the regular expression in the string `str`.
|
||||
An array entry is created for each captured sub expressions. If no match occurs returns null.
|
||||
The search starts from the index `start`
|
||||
of the string, if `start` is omitted the search starts from the beginning of the string.
|
||||
of the string; if `start` is omitted the search starts from the beginning of the string.
|
||||
|
||||
the first element of the returned array(index 0) always contains the complete match.
|
||||
The first element of the returned array(index 0) always contains the complete match.
|
||||
|
||||
::
|
||||
|
||||
@@ -195,9 +203,9 @@ The regexp class
|
||||
|
||||
.. js:function:: regexp.search(str [, start])
|
||||
|
||||
returns a table containing two indexs("begin" and "end") of the first match of the regular expression in
|
||||
returns a table containing two indexes ("begin" and "end") of the first match of the regular expression in
|
||||
the string `str`, otherwise if no match occurs returns null. The search starts from the index `start`
|
||||
of the string, if `start` is omitted the search starts from the beginning of the string.
|
||||
of the string; if `start` is omitted the search starts from the beginning of the string.
|
||||
|
||||
::
|
||||
|
||||
@@ -275,7 +283,7 @@ Regular Expessions
|
||||
:param SQChar** out_end: a pointer to a string pointer that will be set with the end of the match
|
||||
:returns: SQTrue if successful otherwise SQFalse
|
||||
|
||||
searches the first match of the expressin in the string specified in the parameter text.
|
||||
searches the first match of the expression in the string specified in the parameter text.
|
||||
if the match is found returns SQTrue and the sets out_begin to the beginning of the
|
||||
match and out_end at the end of the match; otherwise returns SQFalse.
|
||||
|
||||
@@ -288,9 +296,9 @@ Regular Expessions
|
||||
:param SQChar** out_end: a pointer to a string pointer that will be set with the end of the match
|
||||
:returns: SQTrue if successful otherwise SQFalse
|
||||
|
||||
searches the first match of the expressin in the string delimited
|
||||
searches the first match of the expression in the string delimited
|
||||
by the parameter text_begin and text_end.
|
||||
if the match is found returns SQTrue and the sets out_begin to the beginning of the
|
||||
if the match is found returns SQTrue and sets out_begin to the beginning of the
|
||||
match and out_end at the end of the match; otherwise returns SQFalse.
|
||||
|
||||
.. c:function:: SQInteger sqstd_rex_getsubexpcount(SQRex * exp)
|
||||
@@ -305,7 +313,7 @@ Regular Expessions
|
||||
:param SQRex* exp: a compiled expression
|
||||
:param SQInteger n: the index of the submatch(0 is the complete match)
|
||||
:param SQRexMatch* a: pointer to structure that will store the result
|
||||
:returns: the function returns SQTrue if n is valid index otherwise SQFalse.
|
||||
:returns: the function returns SQTrue if n is a valid index; otherwise SQFalse.
|
||||
|
||||
retrieve the begin and and pointer to the length of the sub expression indexed
|
||||
by n. The result is passed trhough the struct SQRexMatch.
|
||||
by n. The result is passed through the struct SQRexMatch.
|
||||
|
||||
@@ -21,7 +21,7 @@ Global Symbols
|
||||
|
||||
.. js:function:: date([time [, format]])
|
||||
|
||||
returns a table containing a date/time splitted in the slots:
|
||||
returns a table containing a date/time split into the slots:
|
||||
|
||||
+-------------+----------------------------------------+
|
||||
| sec | Seconds after minute (0 - 59). |
|
||||
@@ -79,4 +79,4 @@ C API
|
||||
:returns: an SQRESULT
|
||||
:remarks: The function aspects a table on top of the stack where to register the global library functions.
|
||||
|
||||
initialize and register the system library in the given VM.
|
||||
initialize and register the system library in the given VM.
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#define SQSTD_STREAM_TYPE_TAG 0x80000000
|
||||
|
||||
struct SQStream {
|
||||
virtual ~SQStream() {}
|
||||
virtual SQInteger Read(void *buffer, SQInteger size) = 0;
|
||||
virtual SQInteger Write(void *buffer, SQInteger size) = 0;
|
||||
virtual SQInteger Flush() = 0;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (c) 2003-2016 Alberto Demichelis
|
||||
Copyright (c) 2003-2017 Alberto Demichelis
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -22,6 +22,10 @@ THE SOFTWARE.
|
||||
#ifndef _SQUIRREL_H_
|
||||
#define _SQUIRREL_H_
|
||||
|
||||
#ifdef _SQ_CONFIG_INCLUDE
|
||||
#include _SQ_CONFIG_INCLUDE
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
@@ -62,7 +66,7 @@ struct SQOuter;
|
||||
#include "sqconfig.h"
|
||||
|
||||
#define SQUIRREL_VERSION _SC("Squirrel 3.1 stable")
|
||||
#define SQUIRREL_COPYRIGHT _SC("Copyright (C) 2003-2016 Alberto Demichelis")
|
||||
#define SQUIRREL_COPYRIGHT _SC("Copyright (C) 2003-2017 Alberto Demichelis")
|
||||
#define SQUIRREL_AUTHOR _SC("Alberto Demichelis")
|
||||
#define SQUIRREL_VERSION_NUMBER 310
|
||||
|
||||
@@ -258,6 +262,7 @@ SQUIRREL_API SQRESULT sq_getbase(HSQUIRRELVM v,SQInteger idx);
|
||||
SQUIRREL_API SQBool sq_instanceof(HSQUIRRELVM v);
|
||||
SQUIRREL_API SQRESULT sq_tostring(HSQUIRRELVM v,SQInteger idx);
|
||||
SQUIRREL_API void sq_tobool(HSQUIRRELVM v, SQInteger idx, SQBool *b);
|
||||
SQUIRREL_API SQRESULT sq_getstringandsize(HSQUIRRELVM v,SQInteger idx,const SQChar **c,SQInteger *size);
|
||||
SQUIRREL_API SQRESULT sq_getstring(HSQUIRRELVM v,SQInteger idx,const SQChar **c);
|
||||
SQUIRREL_API SQRESULT sq_getinteger(HSQUIRRELVM v,SQInteger idx,SQInteger *i);
|
||||
SQUIRREL_API SQRESULT sq_getfloat(HSQUIRRELVM v,SQInteger idx,SQFloat *f);
|
||||
@@ -327,6 +332,7 @@ SQUIRREL_API SQRESULT sq_throwerror(HSQUIRRELVM v,const SQChar *err);
|
||||
SQUIRREL_API SQRESULT sq_throwobject(HSQUIRRELVM v);
|
||||
SQUIRREL_API void sq_reseterror(HSQUIRRELVM v);
|
||||
SQUIRREL_API void sq_getlasterror(HSQUIRRELVM v);
|
||||
SQUIRREL_API SQRESULT sq_tailcall(HSQUIRRELVM v, SQInteger nparams);
|
||||
|
||||
/*raw object handling*/
|
||||
SQUIRREL_API SQRESULT sq_getstackobj(HSQUIRRELVM v,SQInteger idx,HSQOBJECT *po);
|
||||
@@ -393,7 +399,7 @@ SQUIRREL_API void sq_setnativedebughook(HSQUIRRELVM v,SQDEBUGHOOK hook);
|
||||
#define SQ_SUCCEEDED(res) (res>=0)
|
||||
|
||||
#ifdef __GNUC__
|
||||
# define SQ_UNUSED_ARG(x) __attribute__((unused)) x
|
||||
# define SQ_UNUSED_ARG(x) x __attribute__((__unused__))
|
||||
#else
|
||||
# define SQ_UNUSED_ARG(x) x
|
||||
#endif
|
||||
|
||||
@@ -12,8 +12,10 @@ if(vargv.len()!=0) {
|
||||
n = 1;
|
||||
}
|
||||
|
||||
local x = []; x.resize(n);
|
||||
local y = []; y.resize(n);
|
||||
local x = [];
|
||||
x.resize(n);
|
||||
local y = [];
|
||||
y.resize(n);
|
||||
|
||||
for (i = 0; i < n; i+=1) {
|
||||
x[i] = i + 1;
|
||||
|
||||
@@ -1,17 +1,28 @@
|
||||
add_executable(sq sq.c)
|
||||
set_target_properties(sq PROPERTIES LINKER_LANGUAGE C)
|
||||
target_link_libraries(sq squirrel sqstdlib)
|
||||
install(TARGETS sq RUNTIME DESTINATION ${INSTALL_BIN_DIR})
|
||||
if(NOT DEFINED DISABLE_DYNAMIC)
|
||||
if(CMAKE_COMPILER_IS_GNUCXX)
|
||||
set_source_files_properties(sq.c PROPERTIES COMPILE_FLAGS -std=c99)
|
||||
endif()
|
||||
add_executable(sq sq.c)
|
||||
set_target_properties(sq PROPERTIES LINKER_LANGUAGE C)
|
||||
target_link_libraries(sq squirrel sqstdlib)
|
||||
if(NOT DEFINED SQ_DISABLE_INSTALLER)
|
||||
install(TARGETS sq RUNTIME DESTINATION ${INSTALL_BIN_DIR})
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(NOT DEFINED DISABLE_STATIC)
|
||||
add_executable(sq_static sq.c)
|
||||
set_target_properties(sq_static PROPERTIES LINKER_LANGUAGE C)
|
||||
target_link_libraries(sq_static squirrel_static sqstdlib_static)
|
||||
install(TARGETS sq_static RUNTIME DESTINATION ${INSTALL_BIN_DIR})
|
||||
if(NOT DEFINED SQ_DISABLE_INSTALLER)
|
||||
install(TARGETS sq_static RUNTIME DESTINATION ${INSTALL_BIN_DIR})
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(DEFINED LONG_OUTPUT_NAMES)
|
||||
set_target_properties(sq PROPERTIES OUTPUT_NAME squirrel3)
|
||||
if(NOT DEFINED DISABLE_DYNAMIC)
|
||||
set_target_properties(sq PROPERTIES OUTPUT_NAME squirrel3)
|
||||
endif()
|
||||
|
||||
if(NOT DEFINED DISABLE_STATIC)
|
||||
set_target_properties(sq_static PROPERTIES OUTPUT_NAME squirrel3_static)
|
||||
|
||||
17
sq/sq.c
17
sq/sq.c
@@ -9,13 +9,13 @@
|
||||
#include <crtdbg.h>
|
||||
#include <conio.h>
|
||||
#endif
|
||||
#include <squirrel.h>
|
||||
#include <sqstdblob.h>
|
||||
#include <sqstdsystem.h>
|
||||
#include <sqstdio.h>
|
||||
#include <sqstdmath.h>
|
||||
#include <sqstdstring.h>
|
||||
#include <sqstdaux.h>
|
||||
#include <squirrel/squirrel.h>
|
||||
#include <squirrel/sqstdblob.h>
|
||||
#include <squirrel/sqstdsystem.h>
|
||||
#include <squirrel/sqstdio.h>
|
||||
#include <squirrel/sqstdmath.h>
|
||||
#include <squirrel/sqstdstring.h>
|
||||
#include <squirrel/sqstdaux.h>
|
||||
|
||||
#ifdef SQUNICODE
|
||||
#define scfprintf fwprintf
|
||||
@@ -52,7 +52,6 @@ void printfunc(HSQUIRRELVM SQ_UNUSED_ARG(v),const SQChar *s,...)
|
||||
va_start(vl, s);
|
||||
scvprintf(stdout, s, vl);
|
||||
va_end(vl);
|
||||
(void)v; /* UNUSED */
|
||||
}
|
||||
|
||||
void errorfunc(HSQUIRRELVM SQ_UNUSED_ARG(v),const SQChar *s,...)
|
||||
@@ -205,7 +204,7 @@ int getargs(HSQUIRRELVM v,int argc, char* argv[],SQInteger *retval)
|
||||
|
||||
}
|
||||
}
|
||||
//if this point is reached an error occured
|
||||
//if this point is reached an error occurred
|
||||
{
|
||||
const SQChar *err;
|
||||
sq_getlasterror(v);
|
||||
|
||||
@@ -7,19 +7,27 @@ set(SQSTDLIB_SRC sqstdaux.cpp
|
||||
sqstdstring.cpp
|
||||
sqstdsystem.cpp)
|
||||
|
||||
add_library(sqstdlib SHARED ${SQSTDLIB_SRC})
|
||||
target_link_libraries(sqstdlib squirrel)
|
||||
install(TARGETS sqstdlib RUNTIME DESTINATION ${INSTALL_BIN_DIR}
|
||||
LIBRARY DESTINATION ${INSTALL_LIB_DIR}
|
||||
ARCHIVE DESTINATION ${INSTALL_LIB_DIR})
|
||||
if(NOT DEFINED DISABLE_DYNAMIC)
|
||||
add_library(sqstdlib SHARED ${SQSTDLIB_SRC})
|
||||
target_link_libraries(sqstdlib squirrel)
|
||||
if(NOT DEFINED SQ_DISABLE_INSTALLER)
|
||||
install(TARGETS sqstdlib RUNTIME DESTINATION ${INSTALL_BIN_DIR}
|
||||
LIBRARY DESTINATION ${INSTALL_LIB_DIR}
|
||||
ARCHIVE DESTINATION ${INSTALL_LIB_DIR})
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(NOT DEFINED DISABLE_STATIC)
|
||||
add_library(sqstdlib_static STATIC ${SQSTDLIB_SRC})
|
||||
install(TARGETS sqstdlib_static ARCHIVE DESTINATION ${INSTALL_LIB_DIR})
|
||||
if(NOT DEFINED SQ_DISABLE_INSTALLER)
|
||||
install(TARGETS sqstdlib_static ARCHIVE DESTINATION ${INSTALL_LIB_DIR})
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(DEFINED LONG_OUTPUT_NAMES)
|
||||
set_target_properties(sqstdlib PROPERTIES OUTPUT_NAME sqstdlib3)
|
||||
if(NOT DEFINED DISABLE_DYNAMIC)
|
||||
set_target_properties(sqstdlib PROPERTIES OUTPUT_NAME sqstdlib3)
|
||||
endif()
|
||||
|
||||
if(NOT DEFINED DISABLE_STATIC)
|
||||
set_target_properties(sqstdlib_static PROPERTIES OUTPUT_NAME sqstdlib3_static)
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
SQUIRREL= ..
|
||||
|
||||
|
||||
OUT= $(SQUIRREL)/lib/libsqstdlib.a
|
||||
INCZ= -I$(SQUIRREL)/include -I. -Iinclude
|
||||
OUT?= $(SQUIRREL)/lib/libsqstdlib.a
|
||||
INCZ?= -I$(SQUIRREL)/include -I. -Iinclude
|
||||
DEFS= $(CC_EXTRA_FLAGS)
|
||||
LIB=
|
||||
|
||||
OBJS= \
|
||||
sqstdblob.o \
|
||||
@@ -26,16 +28,16 @@ SRCS= \
|
||||
|
||||
|
||||
sq32:
|
||||
gcc -O2 -fno-exceptions -fno-rtti -Wall -fno-strict-aliasing -c $(SRCS) $(INCZ)
|
||||
gcc -O2 -fno-exceptions -fno-rtti -Wall -fno-strict-aliasing -c $(SRCS) $(INCZ) $(DEFS)
|
||||
ar rc $(OUT) *.o
|
||||
rm *.o
|
||||
|
||||
sqprof:
|
||||
gcc -O2 -pg -fno-exceptions -fno-rtti -pie -gstabs -g3 -Wall -fno-strict-aliasing -c $(SRCS) $(INCZ)
|
||||
gcc -O2 -pg -fno-exceptions -fno-rtti -pie -gstabs -g3 -Wall -fno-strict-aliasing -c $(SRCS) $(INCZ) $(DEFS)
|
||||
ar rc $(OUT) *.o
|
||||
rm *.o
|
||||
|
||||
sq64:
|
||||
gcc -O2 -m64 -fno-exceptions -D_SQ64 -fno-rtti -Wall -fno-strict-aliasing -c $(SRCS) $(INCZ)
|
||||
gcc -O2 -m64 -fno-exceptions -D_SQ64 -fno-rtti -Wall -fno-strict-aliasing -c $(SRCS) $(INCZ) $(DEFS)
|
||||
ar rc $(OUT) *.o
|
||||
rm *.o
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* see copyright notice in squirrel.h */
|
||||
#include <squirrel.h>
|
||||
#include <sqstdaux.h>
|
||||
#include <squirrel/squirrel.h>
|
||||
#include <squirrel/sqstdaux.h>
|
||||
#include <assert.h>
|
||||
|
||||
void sqstd_printcallstack(HSQUIRRELVM v)
|
||||
@@ -103,10 +103,10 @@ static SQInteger _sqstd_aux_printerror(HSQUIRRELVM v)
|
||||
const SQChar *sErr = 0;
|
||||
if(sq_gettop(v)>=1) {
|
||||
if(SQ_SUCCEEDED(sq_getstring(v,2,&sErr))) {
|
||||
pf(v,_SC("\nAN ERROR HAS OCCURED [%s]\n"),sErr);
|
||||
pf(v,_SC("\nAN ERROR HAS OCCURRED [%s]\n"),sErr);
|
||||
}
|
||||
else{
|
||||
pf(v,_SC("\nAN ERROR HAS OCCURED [unknown]\n"));
|
||||
pf(v,_SC("\nAN ERROR HAS OCCURRED [unknown]\n"));
|
||||
}
|
||||
sqstd_printcallstack(v);
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
/* see copyright notice in squirrel.h */
|
||||
#include <new>
|
||||
#include <squirrel.h>
|
||||
#include <sqstdio.h>
|
||||
#include <squirrel/squirrel.h>
|
||||
#include <squirrel/sqstdio.h>
|
||||
#include <string.h>
|
||||
#include <sqstdblob.h>
|
||||
#include <squirrel/sqstdblob.h>
|
||||
#include "sqstdstream.h"
|
||||
#include "sqstdblobimpl.h"
|
||||
|
||||
#define SQSTD_BLOB_TYPE_TAG (SQSTD_STREAM_TYPE_TAG | 0x00000002)
|
||||
#define SQSTD_BLOB_TYPE_TAG ((SQUnsignedInteger)(SQSTD_STREAM_TYPE_TAG | 0x00000002))
|
||||
|
||||
//Blob
|
||||
|
||||
@@ -82,6 +82,12 @@ static SQInteger _blob__get(HSQUIRRELVM v)
|
||||
{
|
||||
SETUP_BLOB(v);
|
||||
SQInteger idx;
|
||||
|
||||
if ((sq_gettype(v, 2) & SQOBJECT_NUMERIC) == 0)
|
||||
{
|
||||
sq_pushnull(v);
|
||||
return sq_throwobject(v);
|
||||
}
|
||||
sq_getinteger(v,2,&idx);
|
||||
if(idx < 0 || idx >= self->Len())
|
||||
return sq_throwerror(v,_SC("index out of range"));
|
||||
@@ -168,7 +174,7 @@ static const SQRegFunction _blob_methods[] = {
|
||||
_DECL_BLOB_FUNC(swap2,1,_SC("x")),
|
||||
_DECL_BLOB_FUNC(swap4,1,_SC("x")),
|
||||
_DECL_BLOB_FUNC(_set,3,_SC("xnn")),
|
||||
_DECL_BLOB_FUNC(_get,2,_SC("xn")),
|
||||
_DECL_BLOB_FUNC(_get,2,_SC("x.")),
|
||||
_DECL_BLOB_FUNC(_typeof,1,_SC("x")),
|
||||
_DECL_BLOB_FUNC(_nexti,2,_SC("x")),
|
||||
_DECL_BLOB_FUNC(_cloned,2,_SC("xx")),
|
||||
|
||||
@@ -88,7 +88,7 @@ struct SQBlob : public SQStream
|
||||
return 0;
|
||||
}
|
||||
bool IsValid() {
|
||||
return _buf?true:false;
|
||||
return _size == 0 || _buf?true:false;
|
||||
}
|
||||
bool EOS() {
|
||||
return _ptr == _size;
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
/* see copyright notice in squirrel.h */
|
||||
#include <new>
|
||||
#include <stdio.h>
|
||||
#include <squirrel.h>
|
||||
#include <sqstdio.h>
|
||||
#include <squirrel/squirrel.h>
|
||||
#include <squirrel/sqstdio.h>
|
||||
#include "sqstdstream.h"
|
||||
|
||||
#define SQSTD_FILE_TYPE_TAG (SQSTD_STREAM_TYPE_TAG | 0x00000001)
|
||||
#define SQSTD_FILE_TYPE_TAG ((SQUnsignedInteger)(SQSTD_STREAM_TYPE_TAG | 0x00000001))
|
||||
//basic API
|
||||
SQFILE sqstd_fopen(const SQChar *filename ,const SQChar *mode)
|
||||
{
|
||||
@@ -372,7 +372,7 @@ SQRESULT sqstd_loadfile(HSQUIRRELVM v,const SQChar *filename,SQBool printerror)
|
||||
}
|
||||
if(uc != 0xBF) {
|
||||
sqstd_fclose(file);
|
||||
return sq_throwerror(v,_SC("Unrecognozed ecoding"));
|
||||
return sq_throwerror(v,_SC("Unrecognized encoding"));
|
||||
}
|
||||
#ifdef SQUNICODE
|
||||
func = _io_file_lexfeed_UTF8;
|
||||
@@ -399,6 +399,10 @@ SQRESULT sqstd_loadfile(HSQUIRRELVM v,const SQChar *filename,SQBool printerror)
|
||||
|
||||
SQRESULT sqstd_dofile(HSQUIRRELVM v,const SQChar *filename,SQBool retval,SQBool printerror)
|
||||
{
|
||||
//at least one entry must exist in order for us to push it as the environment
|
||||
if(sq_gettop(v) == 0)
|
||||
return sq_throwerror(v,_SC("environment table expected"));
|
||||
|
||||
if(SQ_SUCCEEDED(sqstd_loadfile(v,filename,printerror))) {
|
||||
sq_push(v,-2);
|
||||
if(SQ_SUCCEEDED(sq_call(v,1,retval,SQTrue))) {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/* see copyright notice in squirrel.h */
|
||||
#include <squirrel.h>
|
||||
#include <squirrel/squirrel.h>
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
#include <sqstdmath.h>
|
||||
#include <squirrel/sqstdmath.h>
|
||||
|
||||
#define SINGLE_ARG_FUNC(_funcname) static SQInteger math_##_funcname(HSQUIRRELVM v){ \
|
||||
SQFloat f; \
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/* see copyright notice in squirrel.h */
|
||||
#include <squirrel.h>
|
||||
#include <squirrel/squirrel.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <setjmp.h>
|
||||
#include <sqstdstring.h>
|
||||
#include <squirrel/sqstdstring.h>
|
||||
|
||||
#ifdef _DEBUG
|
||||
#include <stdio.h>
|
||||
@@ -153,6 +153,9 @@ static SQInteger sqstd_rex_charnode(SQRex *exp,SQBool isclass)
|
||||
exp->_nodes[node].right = ce;
|
||||
return node;
|
||||
}
|
||||
case 0:
|
||||
sqstd_rex_error(exp,_SC("letter expected for argument of escape sequence"));
|
||||
break;
|
||||
case 'b':
|
||||
case 'B':
|
||||
if(!isclass) {
|
||||
@@ -575,9 +578,9 @@ SQRex *sqstd_rex_compile(const SQChar *pattern,const SQChar **error)
|
||||
scprintf(_SC("\n"));
|
||||
for(i = 0;i < nsize; i++) {
|
||||
if(exp->_nodes[i].type>MAX_CHAR)
|
||||
scprintf(_SC("[%02d] %10s "),i,g_nnames[exp->_nodes[i].type-MAX_CHAR]);
|
||||
scprintf(_SC("[%02d] %10s "), (SQInt32)i,g_nnames[exp->_nodes[i].type-MAX_CHAR]);
|
||||
else
|
||||
scprintf(_SC("[%02d] %10c "),i,exp->_nodes[i].type);
|
||||
scprintf(_SC("[%02d] %10c "), (SQInt32)i,exp->_nodes[i].type);
|
||||
scprintf(_SC("left %02d right %02d next %02d\n"), (SQInt32)exp->_nodes[i].left, (SQInt32)exp->_nodes[i].right, (SQInt32)exp->_nodes[i].next);
|
||||
}
|
||||
scprintf(_SC("\n"));
|
||||
|
||||
@@ -3,15 +3,15 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <squirrel.h>
|
||||
#include <sqstdio.h>
|
||||
#include <sqstdblob.h>
|
||||
#include <squirrel/squirrel.h>
|
||||
#include <squirrel/sqstdio.h>
|
||||
#include <squirrel/sqstdblob.h>
|
||||
#include "sqstdstream.h"
|
||||
#include "sqstdblobimpl.h"
|
||||
|
||||
#define SETUP_STREAM(v) \
|
||||
SQStream *self = NULL; \
|
||||
if(SQ_FAILED(sq_getinstanceup(v,1,(SQUserPointer*)&self,(SQUserPointer)SQSTD_STREAM_TYPE_TAG))) \
|
||||
if(SQ_FAILED(sq_getinstanceup(v,1,(SQUserPointer*)&self,(SQUserPointer)((SQUnsignedInteger)SQSTD_STREAM_TYPE_TAG)))) \
|
||||
return sq_throwerror(v,_SC("invalid type tag")); \
|
||||
if(!self || !self->IsValid()) \
|
||||
return sq_throwerror(v,_SC("the stream is invalid"));
|
||||
@@ -259,7 +259,7 @@ void init_streamclass(HSQUIRRELVM v)
|
||||
if(SQ_FAILED(sq_get(v,-2))) {
|
||||
sq_pushstring(v,_SC("std_stream"),-1);
|
||||
sq_newclass(v,SQFalse);
|
||||
sq_settypetag(v,-1,(SQUserPointer)SQSTD_STREAM_TYPE_TAG);
|
||||
sq_settypetag(v,-1,(SQUserPointer)((SQUnsignedInteger)SQSTD_STREAM_TYPE_TAG));
|
||||
SQInteger i = 0;
|
||||
while(_stream_methods[i].name != 0) {
|
||||
const SQRegFunction &f = _stream_methods[i];
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* see copyright notice in squirrel.h */
|
||||
#include <squirrel.h>
|
||||
#include <sqstdstring.h>
|
||||
#include <squirrel/squirrel.h>
|
||||
#include <squirrel/sqstdstring.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
@@ -69,7 +69,10 @@ SQRESULT sqstd_format(HSQUIRRELVM v,SQInteger nformatstringidx,SQInteger *outlen
|
||||
const SQChar *format;
|
||||
SQChar *dest;
|
||||
SQChar fmt[MAX_FORMAT_LEN];
|
||||
sq_getstring(v,nformatstringidx,&format);
|
||||
const SQRESULT res = sq_getstring(v,nformatstringidx,&format);
|
||||
if (SQ_FAILED(res)) {
|
||||
return res; // propagate the error
|
||||
}
|
||||
SQInteger format_size = sq_getsize(v,nformatstringidx);
|
||||
SQInteger allocated = (format_size+2)*sizeof(SQChar);
|
||||
dest = sq_getscratchpad(v,allocated);
|
||||
@@ -89,7 +92,7 @@ SQRESULT sqstd_format(HSQUIRRELVM v,SQInteger nformatstringidx,SQInteger *outlen
|
||||
else {
|
||||
n++;
|
||||
if( nparam > sq_gettop(v) )
|
||||
return sq_throwerror(v,_SC("not enough paramters for the given format string"));
|
||||
return sq_throwerror(v,_SC("not enough parameters for the given format string"));
|
||||
n = validate_format(v,fmt,format,n,w);
|
||||
if(n < 0) return -1;
|
||||
SQInteger addlen = 0;
|
||||
@@ -150,6 +153,19 @@ SQRESULT sqstd_format(HSQUIRRELVM v,SQInteger nformatstringidx,SQInteger *outlen
|
||||
return SQ_OK;
|
||||
}
|
||||
|
||||
static SQInteger _string_printf(HSQUIRRELVM v)
|
||||
{
|
||||
SQChar *dest = NULL;
|
||||
SQInteger length = 0;
|
||||
if(SQ_FAILED(sqstd_format(v,2,&length,&dest)))
|
||||
return -1;
|
||||
|
||||
SQPRINTFUNCTION printfunc = sq_getprintfunc(v);
|
||||
if(printfunc) printfunc(v,dest);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static SQInteger _string_format(HSQUIRRELVM v)
|
||||
{
|
||||
SQChar *dest = NULL;
|
||||
@@ -459,6 +475,7 @@ static const SQRegFunction rexobj_funcs[]={
|
||||
#define _DECL_FUNC(name,nparams,pmask) {_SC(#name),_string_##name,nparams,pmask}
|
||||
static const SQRegFunction stringlib_funcs[]={
|
||||
_DECL_FUNC(format,-2,_SC(".s")),
|
||||
_DECL_FUNC(printf,-2,_SC(".s")),
|
||||
_DECL_FUNC(strip,2,_SC(".s")),
|
||||
_DECL_FUNC(lstrip,2,_SC(".s")),
|
||||
_DECL_FUNC(rstrip,2,_SC(".s")),
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/* see copyright notice in squirrel.h */
|
||||
#include <squirrel.h>
|
||||
#include <squirrel/squirrel.h>
|
||||
#include <time.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <sqstdsystem.h>
|
||||
#include <squirrel/sqstdsystem.h>
|
||||
|
||||
#ifdef SQUNICODE
|
||||
#include <wchar.h>
|
||||
|
||||
@@ -11,18 +11,26 @@ set(SQUIRREL_SRC sqapi.cpp
|
||||
sqtable.cpp
|
||||
sqvm.cpp)
|
||||
|
||||
add_library(squirrel SHARED ${SQUIRREL_SRC})
|
||||
install(TARGETS squirrel RUNTIME DESTINATION ${INSTALL_BIN_DIR}
|
||||
if(NOT DEFINED DISABLE_DYNAMIC)
|
||||
add_library(squirrel SHARED ${SQUIRREL_SRC})
|
||||
if(NOT DEFINED SQ_DISABLE_INSTALLER)
|
||||
install(TARGETS squirrel RUNTIME DESTINATION ${INSTALL_BIN_DIR}
|
||||
LIBRARY DESTINATION ${INSTALL_LIB_DIR}
|
||||
ARCHIVE DESTINATION ${INSTALL_LIB_DIR})
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(NOT DEFINED DISABLE_STATIC)
|
||||
add_library(squirrel_static STATIC ${SQUIRREL_SRC})
|
||||
install(TARGETS squirrel_static ARCHIVE DESTINATION ${INSTALL_LIB_DIR})
|
||||
if(NOT DEFINED SQ_DISABLE_INSTALLER)
|
||||
install(TARGETS squirrel_static ARCHIVE DESTINATION ${INSTALL_LIB_DIR})
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(DEFINED LONG_OUTPUT_NAMES)
|
||||
set_target_properties(squirrel PROPERTIES OUTPUT_NAME squirrel3)
|
||||
if(NOT DEFINED DISABLE_DYNAMIC)
|
||||
set_target_properties(squirrel PROPERTIES OUTPUT_NAME squirrel3)
|
||||
endif()
|
||||
|
||||
if(NOT DEFINED DISABLE_STATIC)
|
||||
set_target_properties(squirrel_static PROPERTIES OUTPUT_NAME squirrel3_static)
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
SQUIRREL= ..
|
||||
|
||||
|
||||
OUT= $(SQUIRREL)/lib/libsquirrel.a
|
||||
INCZ= -I$(SQUIRREL)/include -I. -Iinclude
|
||||
DEFS=
|
||||
OUT?= $(SQUIRREL)/lib/libsquirrel.a
|
||||
INCZ?= -I$(SQUIRREL)/include -I. -Iinclude
|
||||
DEFS= $(CC_EXTRA_FLAGS)
|
||||
LIB=
|
||||
|
||||
OBJS= \
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
static bool sq_aux_gettypedarg(HSQUIRRELVM v,SQInteger idx,SQObjectType type,SQObjectPtr **o)
|
||||
{
|
||||
*o = &stack_get(v,idx);
|
||||
if(type(**o) != type){
|
||||
if(sq_type(**o) != type){
|
||||
SQObjectPtr oval = v->PrintObjVal(**o);
|
||||
v->Raise_Error(_SC("wrong argument type, expected '%s' got '%.50s'"),IdType2Name(type),_stringval(oval));
|
||||
return false;
|
||||
@@ -150,7 +150,7 @@ void sq_notifyallexceptions(HSQUIRRELVM v, SQBool enable)
|
||||
|
||||
void sq_addref(HSQUIRRELVM v,HSQOBJECT *po)
|
||||
{
|
||||
if(!ISREFCOUNTED(type(*po))) return;
|
||||
if(!ISREFCOUNTED(sq_type(*po))) return;
|
||||
#ifdef NO_GARBAGE_COLLECTOR
|
||||
__AddRef(po->_type,po->_unVal);
|
||||
#else
|
||||
@@ -160,7 +160,7 @@ void sq_addref(HSQUIRRELVM v,HSQOBJECT *po)
|
||||
|
||||
SQUnsignedInteger sq_getrefcount(HSQUIRRELVM v,HSQOBJECT *po)
|
||||
{
|
||||
if(!ISREFCOUNTED(type(*po))) return 0;
|
||||
if(!ISREFCOUNTED(sq_type(*po))) return 0;
|
||||
#ifdef NO_GARBAGE_COLLECTOR
|
||||
return po->_unVal.pRefCounted->_uiRef;
|
||||
#else
|
||||
@@ -170,7 +170,7 @@ SQUnsignedInteger sq_getrefcount(HSQUIRRELVM v,HSQOBJECT *po)
|
||||
|
||||
SQBool sq_release(HSQUIRRELVM v,HSQOBJECT *po)
|
||||
{
|
||||
if(!ISREFCOUNTED(type(*po))) return SQTrue;
|
||||
if(!ISREFCOUNTED(sq_type(*po))) return SQTrue;
|
||||
#ifdef NO_GARBAGE_COLLECTOR
|
||||
bool ret = (po->_unVal.pRefCounted->_uiRef <= 1) ? SQTrue : SQFalse;
|
||||
__Release(po->_type,po->_unVal);
|
||||
@@ -182,7 +182,7 @@ SQBool sq_release(HSQUIRRELVM v,HSQOBJECT *po)
|
||||
|
||||
SQUnsignedInteger sq_getvmrefcount(HSQUIRRELVM SQ_UNUSED_ARG(v), const HSQOBJECT *po)
|
||||
{
|
||||
if (!ISREFCOUNTED(type(*po))) return 0;
|
||||
if (!ISREFCOUNTED(sq_type(*po))) return 0;
|
||||
return po->_unVal.pRefCounted->_uiRef;
|
||||
}
|
||||
|
||||
@@ -290,7 +290,7 @@ SQRESULT sq_newclass(HSQUIRRELVM v,SQBool hasbase)
|
||||
SQClass *baseclass = NULL;
|
||||
if(hasbase) {
|
||||
SQObjectPtr &base = stack_get(v,-1);
|
||||
if(type(base) != OT_CLASS)
|
||||
if(sq_type(base) != OT_CLASS)
|
||||
return sq_throwerror(v,_SC("invalid base type"));
|
||||
baseclass = _class(base);
|
||||
}
|
||||
@@ -304,7 +304,7 @@ SQBool sq_instanceof(HSQUIRRELVM v)
|
||||
{
|
||||
SQObjectPtr &inst = stack_get(v,-1);
|
||||
SQObjectPtr &cl = stack_get(v,-2);
|
||||
if(type(inst) != OT_INSTANCE || type(cl) != OT_CLASS)
|
||||
if(sq_type(inst) != OT_INSTANCE || sq_type(cl) != OT_CLASS)
|
||||
return sq_throwerror(v,_SC("invalid param type"));
|
||||
return _instance(inst)->InstanceOf(_class(cl))?SQTrue:SQFalse;
|
||||
}
|
||||
@@ -397,14 +397,14 @@ void sq_newclosure(HSQUIRRELVM v,SQFUNCTION func,SQUnsignedInteger nfreevars)
|
||||
SQRESULT sq_getclosureinfo(HSQUIRRELVM v,SQInteger idx,SQUnsignedInteger *nparams,SQUnsignedInteger *nfreevars)
|
||||
{
|
||||
SQObject o = stack_get(v, idx);
|
||||
if(type(o) == OT_CLOSURE) {
|
||||
if(sq_type(o) == OT_CLOSURE) {
|
||||
SQClosure *c = _closure(o);
|
||||
SQFunctionProto *proto = c->_function;
|
||||
*nparams = (SQUnsignedInteger)proto->_nparameters;
|
||||
*nfreevars = (SQUnsignedInteger)proto->_noutervalues;
|
||||
return SQ_OK;
|
||||
}
|
||||
else if(type(o) == OT_NATIVECLOSURE)
|
||||
else if(sq_type(o) == OT_NATIVECLOSURE)
|
||||
{
|
||||
SQNativeClosure *c = _nativeclosure(o);
|
||||
*nparams = (SQUnsignedInteger)c->_nparamscheck;
|
||||
@@ -459,7 +459,7 @@ SQRESULT sq_bindenv(HSQUIRRELVM v,SQInteger idx)
|
||||
!sq_isclass(env) &&
|
||||
!sq_isinstance(env))
|
||||
return sq_throwerror(v,_SC("invalid environment"));
|
||||
SQWeakRef *w = _refcounted(env)->GetWeakRef(type(env));
|
||||
SQWeakRef *w = _refcounted(env)->GetWeakRef(sq_type(env));
|
||||
SQObjectPtr ret;
|
||||
if(sq_isclosure(o)) {
|
||||
SQClosure *c = _closure(o)->Clone();
|
||||
@@ -510,7 +510,7 @@ SQRESULT sq_setclosureroot(HSQUIRRELVM v,SQInteger idx)
|
||||
v->Pop();
|
||||
return SQ_OK;
|
||||
}
|
||||
return sq_throwerror(v, _SC("ivalid type"));
|
||||
return sq_throwerror(v, _SC("invalid type"));
|
||||
}
|
||||
|
||||
SQRESULT sq_getclosureroot(HSQUIRRELVM v,SQInteger idx)
|
||||
@@ -524,7 +524,7 @@ SQRESULT sq_getclosureroot(HSQUIRRELVM v,SQInteger idx)
|
||||
SQRESULT sq_clear(HSQUIRRELVM v,SQInteger idx)
|
||||
{
|
||||
SQObject &o=stack_get(v,idx);
|
||||
switch(type(o)) {
|
||||
switch(sq_type(o)) {
|
||||
case OT_TABLE: _table(o)->Clear(); break;
|
||||
case OT_ARRAY: _array(o)->Resize(0); break;
|
||||
default:
|
||||
@@ -558,7 +558,7 @@ SQRESULT sq_setroottable(HSQUIRRELVM v)
|
||||
v->Pop();
|
||||
return SQ_OK;
|
||||
}
|
||||
return sq_throwerror(v, _SC("ivalid type"));
|
||||
return sq_throwerror(v, _SC("invalid type"));
|
||||
}
|
||||
|
||||
SQRESULT sq_setconsttable(HSQUIRRELVM v)
|
||||
@@ -569,7 +569,7 @@ SQRESULT sq_setconsttable(HSQUIRRELVM v)
|
||||
v->Pop();
|
||||
return SQ_OK;
|
||||
}
|
||||
return sq_throwerror(v, _SC("ivalid type, expected table"));
|
||||
return sq_throwerror(v, _SC("invalid type, expected table"));
|
||||
}
|
||||
|
||||
void sq_setforeignptr(HSQUIRRELVM v,SQUserPointer p)
|
||||
@@ -619,7 +619,7 @@ void sq_push(HSQUIRRELVM v,SQInteger idx)
|
||||
|
||||
SQObjectType sq_gettype(HSQUIRRELVM v,SQInteger idx)
|
||||
{
|
||||
return type(stack_get(v, idx));
|
||||
return sq_type(stack_get(v, idx));
|
||||
}
|
||||
|
||||
SQRESULT sq_typeof(HSQUIRRELVM v,SQInteger idx)
|
||||
@@ -657,6 +657,10 @@ SQRESULT sq_getinteger(HSQUIRRELVM v,SQInteger idx,SQInteger *i)
|
||||
*i = tointeger(o);
|
||||
return SQ_OK;
|
||||
}
|
||||
if(sq_isbool(o)) {
|
||||
*i = SQVM::IsFalse(o)?SQFalse:SQTrue;
|
||||
return SQ_OK;
|
||||
}
|
||||
return SQ_ERROR;
|
||||
}
|
||||
|
||||
@@ -680,6 +684,15 @@ SQRESULT sq_getbool(HSQUIRRELVM v,SQInteger idx,SQBool *b)
|
||||
return SQ_ERROR;
|
||||
}
|
||||
|
||||
SQRESULT sq_getstringandsize(HSQUIRRELVM v,SQInteger idx,const SQChar **c,SQInteger *size)
|
||||
{
|
||||
SQObjectPtr *o = NULL;
|
||||
_GETSAFE_OBJ(v, idx, OT_STRING,o);
|
||||
*c = _stringval(*o);
|
||||
*size = _string(*o)->_len;
|
||||
return SQ_OK;
|
||||
}
|
||||
|
||||
SQRESULT sq_getstring(HSQUIRRELVM v,SQInteger idx,const SQChar **c)
|
||||
{
|
||||
SQObjectPtr *o = NULL;
|
||||
@@ -710,7 +723,7 @@ SQRESULT sq_clone(HSQUIRRELVM v,SQInteger idx)
|
||||
SQInteger sq_getsize(HSQUIRRELVM v, SQInteger idx)
|
||||
{
|
||||
SQObjectPtr &o = stack_get(v, idx);
|
||||
SQObjectType type = type(o);
|
||||
SQObjectType type = sq_type(o);
|
||||
switch(type) {
|
||||
case OT_STRING: return _string(o)->_len;
|
||||
case OT_TABLE: return _table(o)->CountUsed();
|
||||
@@ -741,7 +754,7 @@ SQRESULT sq_getuserdata(HSQUIRRELVM v,SQInteger idx,SQUserPointer *p,SQUserPoint
|
||||
SQRESULT sq_settypetag(HSQUIRRELVM v,SQInteger idx,SQUserPointer typetag)
|
||||
{
|
||||
SQObjectPtr &o = stack_get(v,idx);
|
||||
switch(type(o)) {
|
||||
switch(sq_type(o)) {
|
||||
case OT_USERDATA: _userdata(o)->_typetag = typetag; break;
|
||||
case OT_CLASS: _class(o)->_typetag = typetag; break;
|
||||
default: return sq_throwerror(v,_SC("invalid object type"));
|
||||
@@ -751,7 +764,7 @@ SQRESULT sq_settypetag(HSQUIRRELVM v,SQInteger idx,SQUserPointer typetag)
|
||||
|
||||
SQRESULT sq_getobjtypetag(const HSQOBJECT *o,SQUserPointer * typetag)
|
||||
{
|
||||
switch(type(*o)) {
|
||||
switch(sq_type(*o)) {
|
||||
case OT_INSTANCE: *typetag = _instance(*o)->_class->_typetag; break;
|
||||
case OT_USERDATA: *typetag = _userdata(*o)->_typetag; break;
|
||||
case OT_CLASS: *typetag = _class(*o)->_typetag; break;
|
||||
@@ -763,8 +776,8 @@ SQRESULT sq_getobjtypetag(const HSQOBJECT *o,SQUserPointer * typetag)
|
||||
SQRESULT sq_gettypetag(HSQUIRRELVM v,SQInteger idx,SQUserPointer *typetag)
|
||||
{
|
||||
SQObjectPtr &o = stack_get(v,idx);
|
||||
if(SQ_FAILED(sq_getobjtypetag(&o,typetag)))
|
||||
return sq_throwerror(v,_SC("invalid object type"));
|
||||
if (SQ_FAILED(sq_getobjtypetag(&o, typetag)))
|
||||
return SQ_ERROR;// this is not an error it should be a bool but would break backward compatibility
|
||||
return SQ_OK;
|
||||
}
|
||||
|
||||
@@ -779,7 +792,7 @@ SQRESULT sq_getuserpointer(HSQUIRRELVM v, SQInteger idx, SQUserPointer *p)
|
||||
SQRESULT sq_setinstanceup(HSQUIRRELVM v, SQInteger idx, SQUserPointer p)
|
||||
{
|
||||
SQObjectPtr &o = stack_get(v,idx);
|
||||
if(type(o) != OT_INSTANCE) return sq_throwerror(v,_SC("the object is not a class instance"));
|
||||
if(sq_type(o) != OT_INSTANCE) return sq_throwerror(v,_SC("the object is not a class instance"));
|
||||
_instance(o)->_userpointer = p;
|
||||
return SQ_OK;
|
||||
}
|
||||
@@ -787,7 +800,7 @@ SQRESULT sq_setinstanceup(HSQUIRRELVM v, SQInteger idx, SQUserPointer p)
|
||||
SQRESULT sq_setclassudsize(HSQUIRRELVM v, SQInteger idx, SQInteger udsize)
|
||||
{
|
||||
SQObjectPtr &o = stack_get(v,idx);
|
||||
if(type(o) != OT_CLASS) return sq_throwerror(v,_SC("the object is not a class"));
|
||||
if(sq_type(o) != OT_CLASS) return sq_throwerror(v,_SC("the object is not a class"));
|
||||
if(_class(o)->_locked) return sq_throwerror(v,_SC("the class is locked"));
|
||||
_class(o)->_udsize = udsize;
|
||||
return SQ_OK;
|
||||
@@ -797,7 +810,7 @@ SQRESULT sq_setclassudsize(HSQUIRRELVM v, SQInteger idx, SQInteger udsize)
|
||||
SQRESULT sq_getinstanceup(HSQUIRRELVM v, SQInteger idx, SQUserPointer *p,SQUserPointer typetag)
|
||||
{
|
||||
SQObjectPtr &o = stack_get(v,idx);
|
||||
if(type(o) != OT_INSTANCE) return sq_throwerror(v,_SC("the object is not a class instance"));
|
||||
if(sq_type(o) != OT_INSTANCE) return sq_throwerror(v,_SC("the object is not a class instance"));
|
||||
(*p) = _instance(o)->_userpointer;
|
||||
if(typetag != 0) {
|
||||
SQClass *cl = _instance(o)->_class;
|
||||
@@ -854,9 +867,9 @@ SQRESULT sq_newslot(HSQUIRRELVM v, SQInteger idx, SQBool bstatic)
|
||||
{
|
||||
sq_aux_paramscheck(v, 3);
|
||||
SQObjectPtr &self = stack_get(v, idx);
|
||||
if(type(self) == OT_TABLE || type(self) == OT_CLASS) {
|
||||
if(sq_type(self) == OT_TABLE || sq_type(self) == OT_CLASS) {
|
||||
SQObjectPtr &key = v->GetUp(-2);
|
||||
if(type(key) == OT_NULL) return sq_throwerror(v, _SC("null is not a valid key"));
|
||||
if(sq_type(key) == OT_NULL) return sq_throwerror(v, _SC("null is not a valid key"));
|
||||
v->NewSlot(self, key, v->GetUp(-1),bstatic?true:false);
|
||||
v->Pop(2);
|
||||
}
|
||||
@@ -869,7 +882,7 @@ SQRESULT sq_deleteslot(HSQUIRRELVM v,SQInteger idx,SQBool pushval)
|
||||
SQObjectPtr *self;
|
||||
_GETSAFE_OBJ(v, idx, OT_TABLE,self);
|
||||
SQObjectPtr &key = v->GetUp(-1);
|
||||
if(type(key) == OT_NULL) return sq_throwerror(v, _SC("null is not a valid key"));
|
||||
if(sq_type(key) == OT_NULL) return sq_throwerror(v, _SC("null is not a valid key"));
|
||||
SQObjectPtr res;
|
||||
if(!v->DeleteSlot(*self, key, res)){
|
||||
v->Pop();
|
||||
@@ -894,11 +907,11 @@ SQRESULT sq_rawset(HSQUIRRELVM v,SQInteger idx)
|
||||
{
|
||||
SQObjectPtr &self = stack_get(v, idx);
|
||||
SQObjectPtr &key = v->GetUp(-2);
|
||||
if(type(key) == OT_NULL) {
|
||||
if(sq_type(key) == OT_NULL) {
|
||||
v->Pop(2);
|
||||
return sq_throwerror(v, _SC("null key"));
|
||||
}
|
||||
switch(type(self)) {
|
||||
switch(sq_type(self)) {
|
||||
case OT_TABLE:
|
||||
_table(self)->NewSlot(key, v->GetUp(-1));
|
||||
v->Pop(2);
|
||||
@@ -931,22 +944,28 @@ SQRESULT sq_rawset(HSQUIRRELVM v,SQInteger idx)
|
||||
SQRESULT sq_newmember(HSQUIRRELVM v,SQInteger idx,SQBool bstatic)
|
||||
{
|
||||
SQObjectPtr &self = stack_get(v, idx);
|
||||
if(type(self) != OT_CLASS) return sq_throwerror(v, _SC("new member only works with classes"));
|
||||
if(sq_type(self) != OT_CLASS) return sq_throwerror(v, _SC("new member only works with classes"));
|
||||
SQObjectPtr &key = v->GetUp(-3);
|
||||
if(type(key) == OT_NULL) return sq_throwerror(v, _SC("null key"));
|
||||
if(!v->NewSlotA(self,key,v->GetUp(-2),v->GetUp(-1),bstatic?true:false,false))
|
||||
if(sq_type(key) == OT_NULL) return sq_throwerror(v, _SC("null key"));
|
||||
if(!v->NewSlotA(self,key,v->GetUp(-2),v->GetUp(-1),bstatic?true:false,false)) {
|
||||
v->Pop(3);
|
||||
return SQ_ERROR;
|
||||
}
|
||||
v->Pop(3);
|
||||
return SQ_OK;
|
||||
}
|
||||
|
||||
SQRESULT sq_rawnewmember(HSQUIRRELVM v,SQInteger idx,SQBool bstatic)
|
||||
{
|
||||
SQObjectPtr &self = stack_get(v, idx);
|
||||
if(type(self) != OT_CLASS) return sq_throwerror(v, _SC("new member only works with classes"));
|
||||
if(sq_type(self) != OT_CLASS) return sq_throwerror(v, _SC("new member only works with classes"));
|
||||
SQObjectPtr &key = v->GetUp(-3);
|
||||
if(type(key) == OT_NULL) return sq_throwerror(v, _SC("null key"));
|
||||
if(!v->NewSlotA(self,key,v->GetUp(-2),v->GetUp(-1),bstatic?true:false,true))
|
||||
if(sq_type(key) == OT_NULL) return sq_throwerror(v, _SC("null key"));
|
||||
if(!v->NewSlotA(self,key,v->GetUp(-2),v->GetUp(-1),bstatic?true:false,true)) {
|
||||
v->Pop(3);
|
||||
return SQ_ERROR;
|
||||
}
|
||||
v->Pop(3);
|
||||
return SQ_OK;
|
||||
}
|
||||
|
||||
@@ -954,19 +973,23 @@ SQRESULT sq_setdelegate(HSQUIRRELVM v,SQInteger idx)
|
||||
{
|
||||
SQObjectPtr &self = stack_get(v, idx);
|
||||
SQObjectPtr &mt = v->GetUp(-1);
|
||||
SQObjectType type = type(self);
|
||||
SQObjectType type = sq_type(self);
|
||||
switch(type) {
|
||||
case OT_TABLE:
|
||||
if(type(mt) == OT_TABLE) {
|
||||
if(!_table(self)->SetDelegate(_table(mt))) return sq_throwerror(v, _SC("delagate cycle")); v->Pop();}
|
||||
else if(type(mt)==OT_NULL) {
|
||||
if(sq_type(mt) == OT_TABLE) {
|
||||
if(!_table(self)->SetDelegate(_table(mt))) {
|
||||
return sq_throwerror(v, _SC("delagate cycle"));
|
||||
}
|
||||
v->Pop();
|
||||
}
|
||||
else if(sq_type(mt)==OT_NULL) {
|
||||
_table(self)->SetDelegate(NULL); v->Pop(); }
|
||||
else return sq_aux_invalidtype(v,type);
|
||||
break;
|
||||
case OT_USERDATA:
|
||||
if(type(mt)==OT_TABLE) {
|
||||
if(sq_type(mt)==OT_TABLE) {
|
||||
_userdata(self)->SetDelegate(_table(mt)); v->Pop(); }
|
||||
else if(type(mt)==OT_NULL) {
|
||||
else if(sq_type(mt)==OT_NULL) {
|
||||
_userdata(self)->SetDelegate(NULL); v->Pop(); }
|
||||
else return sq_aux_invalidtype(v, type);
|
||||
break;
|
||||
@@ -997,7 +1020,7 @@ SQRESULT sq_rawdeleteslot(HSQUIRRELVM v,SQInteger idx,SQBool pushval)
|
||||
SQRESULT sq_getdelegate(HSQUIRRELVM v,SQInteger idx)
|
||||
{
|
||||
SQObjectPtr &self=stack_get(v,idx);
|
||||
switch(type(self)){
|
||||
switch(sq_type(self)){
|
||||
case OT_TABLE:
|
||||
case OT_USERDATA:
|
||||
if(!_delegable(self)->_delegate){
|
||||
@@ -1026,7 +1049,7 @@ SQRESULT sq_rawget(HSQUIRRELVM v,SQInteger idx)
|
||||
{
|
||||
SQObjectPtr &self=stack_get(v,idx);
|
||||
SQObjectPtr &obj = v->GetUp(-1);
|
||||
switch(type(self)) {
|
||||
switch(sq_type(self)) {
|
||||
case OT_TABLE:
|
||||
if(_table(self)->Get(obj,obj))
|
||||
return SQ_OK;
|
||||
@@ -1076,7 +1099,7 @@ const SQChar *sq_getlocal(HSQUIRRELVM v,SQUnsignedInteger level,SQUnsignedIntege
|
||||
stackbase-=ci._prevstkbase;
|
||||
}
|
||||
SQVM::CallInfo &ci=v->_callsstack[lvl];
|
||||
if(type(ci._closure)!=OT_CLOSURE)
|
||||
if(sq_type(ci._closure)!=OT_CLOSURE)
|
||||
return NULL;
|
||||
SQClosure *c=_closure(ci._closure);
|
||||
SQFunctionProto *func=c->_function;
|
||||
@@ -1128,7 +1151,7 @@ SQRESULT sq_reservestack(HSQUIRRELVM v,SQInteger nsize)
|
||||
{
|
||||
if (((SQUnsignedInteger)v->_top + nsize) > v->_stack.size()) {
|
||||
if(v->_nmetamethodscall) {
|
||||
return sq_throwerror(v,_SC("cannot resize stack while in a metamethod"));
|
||||
return sq_throwerror(v,_SC("cannot resize stack while in a metamethod"));
|
||||
}
|
||||
v->_stack.resize(v->_stack.size() + ((v->_top + nsize) - v->_stack.size()));
|
||||
}
|
||||
@@ -1137,7 +1160,7 @@ SQRESULT sq_reservestack(HSQUIRRELVM v,SQInteger nsize)
|
||||
|
||||
SQRESULT sq_resume(HSQUIRRELVM v,SQBool retval,SQBool raiseerror)
|
||||
{
|
||||
if (type(v->GetUp(-1)) == OT_GENERATOR)
|
||||
if (sq_type(v->GetUp(-1)) == OT_GENERATOR)
|
||||
{
|
||||
v->PushNull(); //retval
|
||||
if (!v->Execute(v->GetUp(-2), 0, v->_top, v->GetUp(-1), raiseerror, SQVM::ET_RESUME_GENERATOR))
|
||||
@@ -1155,7 +1178,7 @@ SQRESULT sq_call(HSQUIRRELVM v,SQInteger params,SQBool retval,SQBool raiseerror)
|
||||
if(v->Call(v->GetUp(-(params+1)),params,v->_top-params,res,raiseerror?true:false)){
|
||||
|
||||
if(!v->_suspended) {
|
||||
v->Pop(params);//pop closure and args
|
||||
v->Pop(params);//pop args
|
||||
}
|
||||
if(retval){
|
||||
v->Push(res); return SQ_OK;
|
||||
@@ -1171,6 +1194,25 @@ SQRESULT sq_call(HSQUIRRELVM v,SQInteger params,SQBool retval,SQBool raiseerror)
|
||||
return sq_throwerror(v,_SC("call failed"));
|
||||
}
|
||||
|
||||
SQRESULT sq_tailcall(HSQUIRRELVM v, SQInteger nparams)
|
||||
{
|
||||
SQObjectPtr &res = v->GetUp(-(nparams + 1));
|
||||
if (sq_type(res) != OT_CLOSURE) {
|
||||
return sq_throwerror(v, _SC("only closure can be tail called"));
|
||||
}
|
||||
SQClosure *clo = _closure(res);
|
||||
if (clo->_function->_bgenerator)
|
||||
{
|
||||
return sq_throwerror(v, _SC("generators cannot be tail called"));
|
||||
}
|
||||
|
||||
SQInteger stackbase = (v->_top - nparams) - v->_stackbase;
|
||||
if (!v->TailCall(clo, stackbase, nparams)) {
|
||||
return SQ_ERROR;
|
||||
}
|
||||
return SQ_TAILCALL_FLAG;
|
||||
}
|
||||
|
||||
SQRESULT sq_suspendvm(HSQUIRRELVM v)
|
||||
{
|
||||
return v->Suspend();
|
||||
@@ -1199,29 +1241,24 @@ SQRESULT sq_wakeupvm(HSQUIRRELVM v,SQBool wakeupret,SQBool retval,SQBool raiseer
|
||||
|
||||
void sq_setreleasehook(HSQUIRRELVM v,SQInteger idx,SQRELEASEHOOK hook)
|
||||
{
|
||||
if(sq_gettop(v) >= 1){
|
||||
SQObjectPtr &ud=stack_get(v,idx);
|
||||
switch( type(ud) ) {
|
||||
case OT_USERDATA: _userdata(ud)->_hook = hook; break;
|
||||
case OT_INSTANCE: _instance(ud)->_hook = hook; break;
|
||||
case OT_CLASS: _class(ud)->_hook = hook; break;
|
||||
default: break; //shutup compiler
|
||||
}
|
||||
SQObjectPtr &ud=stack_get(v,idx);
|
||||
switch(sq_type(ud) ) {
|
||||
case OT_USERDATA: _userdata(ud)->_hook = hook; break;
|
||||
case OT_INSTANCE: _instance(ud)->_hook = hook; break;
|
||||
case OT_CLASS: _class(ud)->_hook = hook; break;
|
||||
default: return;
|
||||
}
|
||||
}
|
||||
|
||||
SQRELEASEHOOK sq_getreleasehook(HSQUIRRELVM v,SQInteger idx)
|
||||
{
|
||||
if(sq_gettop(v) >= 1){
|
||||
SQObjectPtr &ud=stack_get(v,idx);
|
||||
switch( type(ud) ) {
|
||||
case OT_USERDATA: return _userdata(ud)->_hook; break;
|
||||
case OT_INSTANCE: return _instance(ud)->_hook; break;
|
||||
case OT_CLASS: return _class(ud)->_hook; break;
|
||||
default: break; //shutup compiler
|
||||
}
|
||||
SQObjectPtr &ud=stack_get(v,idx);
|
||||
switch(sq_type(ud) ) {
|
||||
case OT_USERDATA: return _userdata(ud)->_hook; break;
|
||||
case OT_INSTANCE: return _instance(ud)->_hook; break;
|
||||
case OT_CLASS: return _class(ud)->_hook; break;
|
||||
default: return NULL;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void sq_setcompilererrorhandler(HSQUIRRELVM v,SQCOMPILERERROR f)
|
||||
@@ -1235,7 +1272,7 @@ SQRESULT sq_writeclosure(HSQUIRRELVM v,SQWRITEFUNC w,SQUserPointer up)
|
||||
_GETSAFE_OBJ(v, -1, OT_CLOSURE,o);
|
||||
unsigned short tag = SQ_BYTECODE_STREAM_TAG;
|
||||
if(_closure(*o)->_function->_noutervalues)
|
||||
return sq_throwerror(v,_SC("a closure with free valiables bound it cannot be serialized"));
|
||||
return sq_throwerror(v,_SC("a closure with free variables bound cannot be serialized"));
|
||||
if(w(up,&tag,2) != 2)
|
||||
return sq_throwerror(v,_SC("io error"));
|
||||
if(!_closure(*o)->Save(v,up,w))
|
||||
@@ -1296,7 +1333,7 @@ const SQChar *sq_getfreevariable(HSQUIRRELVM v,SQInteger idx,SQUnsignedInteger n
|
||||
{
|
||||
SQObjectPtr &self=stack_get(v,idx);
|
||||
const SQChar *name = NULL;
|
||||
switch(type(self))
|
||||
switch(sq_type(self))
|
||||
{
|
||||
case OT_CLOSURE:{
|
||||
SQClosure *clo = _closure(self);
|
||||
@@ -1324,7 +1361,7 @@ const SQChar *sq_getfreevariable(HSQUIRRELVM v,SQInteger idx,SQUnsignedInteger n
|
||||
SQRESULT sq_setfreevariable(HSQUIRRELVM v,SQInteger idx,SQUnsignedInteger nval)
|
||||
{
|
||||
SQObjectPtr &self=stack_get(v,idx);
|
||||
switch(type(self))
|
||||
switch(sq_type(self))
|
||||
{
|
||||
case OT_CLOSURE:{
|
||||
SQFunctionProto *fp = _closure(self)->_function;
|
||||
@@ -1341,7 +1378,7 @@ SQRESULT sq_setfreevariable(HSQUIRRELVM v,SQInteger idx,SQUnsignedInteger nval)
|
||||
else return sq_throwerror(v,_SC("invalid free var index"));
|
||||
break;
|
||||
default:
|
||||
return sq_aux_invalidtype(v,type(self));
|
||||
return sq_aux_invalidtype(v, sq_type(self));
|
||||
}
|
||||
v->Pop();
|
||||
return SQ_OK;
|
||||
@@ -1354,7 +1391,7 @@ SQRESULT sq_setattributes(HSQUIRRELVM v,SQInteger idx)
|
||||
SQObjectPtr &key = stack_get(v,-2);
|
||||
SQObjectPtr &val = stack_get(v,-1);
|
||||
SQObjectPtr attrs;
|
||||
if(type(key) == OT_NULL) {
|
||||
if(sq_type(key) == OT_NULL) {
|
||||
attrs = _class(*o)->_attributes;
|
||||
_class(*o)->_attributes = val;
|
||||
v->Pop(2);
|
||||
@@ -1375,7 +1412,7 @@ SQRESULT sq_getattributes(HSQUIRRELVM v,SQInteger idx)
|
||||
_GETSAFE_OBJ(v, idx, OT_CLASS,o);
|
||||
SQObjectPtr &key = stack_get(v,-1);
|
||||
SQObjectPtr attrs;
|
||||
if(type(key) == OT_NULL) {
|
||||
if(sq_type(key) == OT_NULL) {
|
||||
attrs = _class(*o)->_attributes;
|
||||
v->Pop();
|
||||
v->Push(attrs);
|
||||
@@ -1407,7 +1444,7 @@ SQRESULT sq_getmemberhandle(HSQUIRRELVM v,SQInteger idx,HSQMEMBERHANDLE *handle)
|
||||
|
||||
SQRESULT _getmemberbyhandle(HSQUIRRELVM v,SQObjectPtr &self,const HSQMEMBERHANDLE *handle,SQObjectPtr *&val)
|
||||
{
|
||||
switch(type(self)) {
|
||||
switch(sq_type(self)) {
|
||||
case OT_INSTANCE: {
|
||||
SQInstance *i = _instance(self);
|
||||
if(handle->_static) {
|
||||
@@ -1490,8 +1527,8 @@ SQRESULT sq_createinstance(HSQUIRRELVM v,SQInteger idx)
|
||||
void sq_weakref(HSQUIRRELVM v,SQInteger idx)
|
||||
{
|
||||
SQObject &o=stack_get(v,idx);
|
||||
if(ISREFCOUNTED(type(o))) {
|
||||
v->Push(_refcounted(o)->GetWeakRef(type(o)));
|
||||
if(ISREFCOUNTED(sq_type(o))) {
|
||||
v->Push(_refcounted(o)->GetWeakRef(sq_type(o)));
|
||||
return;
|
||||
}
|
||||
v->Push(o);
|
||||
@@ -1500,7 +1537,7 @@ void sq_weakref(HSQUIRRELVM v,SQInteger idx)
|
||||
SQRESULT sq_getweakrefval(HSQUIRRELVM v,SQInteger idx)
|
||||
{
|
||||
SQObjectPtr &o = stack_get(v,idx);
|
||||
if(type(o) != OT_WEAKREF) {
|
||||
if(sq_type(o) != OT_WEAKREF) {
|
||||
return sq_throwerror(v,_SC("the object must be a weakref"));
|
||||
}
|
||||
v->Push(_weakref(o)->_obj);
|
||||
@@ -1529,7 +1566,7 @@ SQRESULT sq_getdefaultdelegate(HSQUIRRELVM v,SQObjectType t)
|
||||
SQRESULT sq_next(HSQUIRRELVM v,SQInteger idx)
|
||||
{
|
||||
SQObjectPtr o=stack_get(v,idx),&refpos = stack_get(v,-1),realkey,val;
|
||||
if(type(o) == OT_GENERATOR) {
|
||||
if(sq_type(o) == OT_GENERATOR) {
|
||||
return sq_throwerror(v,_SC("cannot iterate a generator"));
|
||||
}
|
||||
int faketojump;
|
||||
|
||||
@@ -156,7 +156,14 @@ static SQInteger base_getstackinfos(HSQUIRRELVM v)
|
||||
static SQInteger base_assert(HSQUIRRELVM v)
|
||||
{
|
||||
if(SQVM::IsFalse(stack_get(v,2))){
|
||||
return sq_throwerror(v,_SC("assertion failed"));
|
||||
SQInteger top = sq_gettop(v);
|
||||
if (top>2 && SQ_SUCCEEDED(sq_tostring(v,3))) {
|
||||
const SQChar *str = 0;
|
||||
if (SQ_SUCCEEDED(sq_getstring(v,-1,&str))) {
|
||||
return sq_throwerror(v, str);
|
||||
}
|
||||
}
|
||||
return sq_throwerror(v, _SC("assertion failed"));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -169,7 +176,7 @@ static SQInteger get_slice_params(HSQUIRRELVM v,SQInteger &sidx,SQInteger &eidx,
|
||||
o=stack_get(v,1);
|
||||
if(top>1){
|
||||
SQObjectPtr &start=stack_get(v,2);
|
||||
if(type(start)!=OT_NULL && sq_isnumeric(start)){
|
||||
if(sq_type(start)!=OT_NULL && sq_isnumeric(start)){
|
||||
sidx=tointeger(start);
|
||||
}
|
||||
}
|
||||
@@ -283,7 +290,7 @@ static const SQRegFunction base_funcs[]={
|
||||
{_SC("setroottable"),base_setroottable,2, NULL},
|
||||
{_SC("getconsttable"),base_getconsttable,1, NULL},
|
||||
{_SC("setconsttable"),base_setconsttable,2, NULL},
|
||||
{_SC("assert"),base_assert,2, NULL},
|
||||
{_SC("assert"),base_assert,-2, NULL},
|
||||
{_SC("print"),base_print,2, NULL},
|
||||
{_SC("error"),base_error,2, NULL},
|
||||
{_SC("compilestring"),base_compilestring,-2, _SC(".ss")},
|
||||
@@ -340,7 +347,7 @@ static SQInteger default_delegate_len(HSQUIRRELVM v)
|
||||
static SQInteger default_delegate_tofloat(HSQUIRRELVM v)
|
||||
{
|
||||
SQObjectPtr &o=stack_get(v,1);
|
||||
switch(type(o)){
|
||||
switch(sq_type(o)){
|
||||
case OT_STRING:{
|
||||
SQObjectPtr res;
|
||||
if(str2num(_stringval(o),res,10)){
|
||||
@@ -369,7 +376,7 @@ static SQInteger default_delegate_tointeger(HSQUIRRELVM v)
|
||||
if(sq_gettop(v) > 1) {
|
||||
sq_getinteger(v,2,&base);
|
||||
}
|
||||
switch(type(o)){
|
||||
switch(sq_type(o)){
|
||||
case OT_STRING:{
|
||||
SQObjectPtr res;
|
||||
if(str2num(_stringval(o),res,base)){
|
||||
@@ -406,7 +413,7 @@ static SQInteger obj_delegate_weakref(HSQUIRRELVM v)
|
||||
|
||||
static SQInteger obj_clear(HSQUIRRELVM v)
|
||||
{
|
||||
return sq_clear(v,-1);
|
||||
return SQ_SUCCEEDED(sq_clear(v,-1)) ? 1 : SQ_ERROR;
|
||||
}
|
||||
|
||||
|
||||
@@ -443,7 +450,7 @@ static SQInteger container_rawexists(HSQUIRRELVM v)
|
||||
|
||||
static SQInteger container_rawset(HSQUIRRELVM v)
|
||||
{
|
||||
return sq_rawset(v,-3);
|
||||
return SQ_SUCCEEDED(sq_rawset(v,-3)) ? 1 : SQ_ERROR;
|
||||
}
|
||||
|
||||
|
||||
@@ -465,6 +472,34 @@ static SQInteger table_getdelegate(HSQUIRRELVM v)
|
||||
return SQ_SUCCEEDED(sq_getdelegate(v,-1))?1:SQ_ERROR;
|
||||
}
|
||||
|
||||
static SQInteger table_filter(HSQUIRRELVM v)
|
||||
{
|
||||
SQObject &o = stack_get(v,1);
|
||||
SQTable *tbl = _table(o);
|
||||
SQObjectPtr ret = SQTable::Create(_ss(v),0);
|
||||
|
||||
SQObjectPtr itr, key, val;
|
||||
SQInteger nitr;
|
||||
while((nitr = tbl->Next(false, itr, key, val)) != -1) {
|
||||
itr = (SQInteger)nitr;
|
||||
|
||||
v->Push(o);
|
||||
v->Push(key);
|
||||
v->Push(val);
|
||||
if(SQ_FAILED(sq_call(v,3,SQTrue,SQFalse))) {
|
||||
return SQ_ERROR;
|
||||
}
|
||||
if(!SQVM::IsFalse(v->GetUp(-1))) {
|
||||
_table(ret)->NewSlot(key, val);
|
||||
}
|
||||
v->Pop();
|
||||
}
|
||||
|
||||
v->Push(ret);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
const SQRegFunction SQSharedState::_table_default_delegate_funcz[]={
|
||||
{_SC("len"),default_delegate_len,1, _SC("t")},
|
||||
{_SC("rawget"),container_rawget,2, _SC("t")},
|
||||
@@ -476,6 +511,7 @@ const SQRegFunction SQSharedState::_table_default_delegate_funcz[]={
|
||||
{_SC("clear"),obj_clear,1, _SC(".")},
|
||||
{_SC("setdelegate"),table_setdelegate,2, _SC(".t|o")},
|
||||
{_SC("getdelegate"),table_getdelegate,1, _SC(".")},
|
||||
{_SC("filter"),table_filter,2, _SC("tc")},
|
||||
{NULL,(SQFUNCTION)0,0,NULL}
|
||||
};
|
||||
|
||||
@@ -483,18 +519,19 @@ const SQRegFunction SQSharedState::_table_default_delegate_funcz[]={
|
||||
|
||||
static SQInteger array_append(HSQUIRRELVM v)
|
||||
{
|
||||
return sq_arrayappend(v,-2);
|
||||
return SQ_SUCCEEDED(sq_arrayappend(v,-2)) ? 1 : SQ_ERROR;
|
||||
}
|
||||
|
||||
static SQInteger array_extend(HSQUIRRELVM v)
|
||||
{
|
||||
_array(stack_get(v,1))->Extend(_array(stack_get(v,2)));
|
||||
return 0;
|
||||
sq_pop(v,1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static SQInteger array_reverse(HSQUIRRELVM v)
|
||||
{
|
||||
return sq_arrayreverse(v,-1);
|
||||
return SQ_SUCCEEDED(sq_arrayreverse(v,-1)) ? 1 : SQ_ERROR;
|
||||
}
|
||||
|
||||
static SQInteger array_pop(HSQUIRRELVM v)
|
||||
@@ -519,7 +556,8 @@ static SQInteger array_insert(HSQUIRRELVM v)
|
||||
SQObject &val=stack_get(v,3);
|
||||
if(!_array(o)->Insert(tointeger(idx),val))
|
||||
return sq_throwerror(v,_SC("index out of range"));
|
||||
return 0;
|
||||
sq_pop(v,2);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static SQInteger array_remove(HSQUIRRELVM v)
|
||||
@@ -542,10 +580,15 @@ static SQInteger array_resize(HSQUIRRELVM v)
|
||||
SQObject &nsize = stack_get(v, 2);
|
||||
SQObjectPtr fill;
|
||||
if(sq_isnumeric(nsize)) {
|
||||
SQInteger sz = tointeger(nsize);
|
||||
if (sz<0)
|
||||
return sq_throwerror(v, _SC("resizing to negative length"));
|
||||
|
||||
if(sq_gettop(v) > 2)
|
||||
fill = stack_get(v, 3);
|
||||
_array(o)->Resize(tointeger(nsize),fill);
|
||||
return 0;
|
||||
_array(o)->Resize(sz,fill);
|
||||
sq_settop(v, 1);
|
||||
return 1;
|
||||
}
|
||||
return sq_throwerror(v, _SC("size must be a number"));
|
||||
}
|
||||
@@ -582,7 +625,8 @@ static SQInteger array_apply(HSQUIRRELVM v)
|
||||
SQObject &o = stack_get(v,1);
|
||||
if(SQ_FAILED(__map_array(_array(o),_array(o),v)))
|
||||
return SQ_ERROR;
|
||||
return 0;
|
||||
sq_pop(v,1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static SQInteger array_reduce(HSQUIRRELVM v)
|
||||
@@ -749,7 +793,8 @@ static SQInteger array_sort(HSQUIRRELVM v)
|
||||
return SQ_ERROR;
|
||||
|
||||
}
|
||||
return 0;
|
||||
sq_settop(v,1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static SQInteger array_slice(HSQUIRRELVM v)
|
||||
@@ -885,7 +930,12 @@ static SQInteger closure_pcall(HSQUIRRELVM v)
|
||||
|
||||
static SQInteger closure_call(HSQUIRRELVM v)
|
||||
{
|
||||
return SQ_SUCCEEDED(sq_call(v,sq_gettop(v)-1,SQTrue,SQTrue))?1:SQ_ERROR;
|
||||
SQObjectPtr &c = stack_get(v, -1);
|
||||
if (sq_type(c) == OT_CLOSURE && (_closure(c)->_function->_bgenerator == false))
|
||||
{
|
||||
return sq_tailcall(v, sq_gettop(v) - 1);
|
||||
}
|
||||
return SQ_SUCCEEDED(sq_call(v, sq_gettop(v) - 1, SQTrue, SQTrue)) ? 1 : SQ_ERROR;
|
||||
}
|
||||
|
||||
static SQInteger _closure_acall(HSQUIRRELVM v,SQBool raiseerror)
|
||||
@@ -931,7 +981,7 @@ static SQInteger closure_setroot(HSQUIRRELVM v)
|
||||
static SQInteger closure_getinfos(HSQUIRRELVM v) {
|
||||
SQObject o = stack_get(v,1);
|
||||
SQTable *res = SQTable::Create(_ss(v),4);
|
||||
if(type(o) == OT_CLOSURE) {
|
||||
if(sq_type(o) == OT_CLOSURE) {
|
||||
SQFunctionProto *f = _closure(o)->_function;
|
||||
SQInteger nparams = f->_nparameters + (f->_varparams?1:0);
|
||||
SQObjectPtr params = SQArray::Create(_ss(v),nparams);
|
||||
@@ -1010,7 +1060,7 @@ const SQRegFunction SQSharedState::_generator_default_delegate_funcz[]={
|
||||
static SQInteger thread_call(HSQUIRRELVM v)
|
||||
{
|
||||
SQObjectPtr o = stack_get(v,1);
|
||||
if(type(o) == OT_THREAD) {
|
||||
if(sq_type(o) == OT_THREAD) {
|
||||
SQInteger nparams = sq_gettop(v);
|
||||
_thread(o)->Push(_thread(o)->_roottable);
|
||||
for(SQInteger i = 2; i<(nparams+1); i++)
|
||||
@@ -1029,7 +1079,7 @@ static SQInteger thread_call(HSQUIRRELVM v)
|
||||
static SQInteger thread_wakeup(HSQUIRRELVM v)
|
||||
{
|
||||
SQObjectPtr o = stack_get(v,1);
|
||||
if(type(o) == OT_THREAD) {
|
||||
if(sq_type(o) == OT_THREAD) {
|
||||
SQVM *thread = _thread(o);
|
||||
SQInteger state = sq_getvmstate(thread);
|
||||
if(state != SQ_VMSTATE_SUSPENDED) {
|
||||
@@ -1065,7 +1115,7 @@ static SQInteger thread_wakeup(HSQUIRRELVM v)
|
||||
static SQInteger thread_wakeupthrow(HSQUIRRELVM v)
|
||||
{
|
||||
SQObjectPtr o = stack_get(v,1);
|
||||
if(type(o) == OT_THREAD) {
|
||||
if(sq_type(o) == OT_THREAD) {
|
||||
SQVM *thread = _thread(o);
|
||||
SQInteger state = sq_getvmstate(thread);
|
||||
if(state != SQ_VMSTATE_SUSPENDED) {
|
||||
@@ -1125,7 +1175,7 @@ static SQInteger thread_getstatus(HSQUIRRELVM v)
|
||||
static SQInteger thread_getstackinfos(HSQUIRRELVM v)
|
||||
{
|
||||
SQObjectPtr o = stack_get(v,1);
|
||||
if(type(o) == OT_THREAD) {
|
||||
if(sq_type(o) == OT_THREAD) {
|
||||
SQVM *thread = _thread(o);
|
||||
SQInteger threadtop = sq_gettop(thread);
|
||||
SQInteger level;
|
||||
@@ -1134,7 +1184,7 @@ static SQInteger thread_getstackinfos(HSQUIRRELVM v)
|
||||
if(SQ_FAILED(res))
|
||||
{
|
||||
sq_settop(thread,threadtop);
|
||||
if(type(thread->_lasterror) == OT_STRING) {
|
||||
if(sq_type(thread->_lasterror) == OT_STRING) {
|
||||
sq_throwerror(v,_stringval(thread->_lasterror));
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -53,7 +53,7 @@ SQClass::~SQClass()
|
||||
bool SQClass::NewSlot(SQSharedState *ss,const SQObjectPtr &key,const SQObjectPtr &val,bool bstatic)
|
||||
{
|
||||
SQObjectPtr temp;
|
||||
bool belongs_to_static_table = type(val) == OT_CLOSURE || type(val) == OT_NATIVECLOSURE || bstatic;
|
||||
bool belongs_to_static_table = sq_type(val) == OT_CLOSURE || sq_type(val) == OT_NATIVECLOSURE || bstatic;
|
||||
if(_locked && !belongs_to_static_table)
|
||||
return false; //the class already has an instance so cannot be modified
|
||||
if(_members->Get(key,temp) && _isfield(temp)) //overrides the default value
|
||||
@@ -63,18 +63,18 @@ bool SQClass::NewSlot(SQSharedState *ss,const SQObjectPtr &key,const SQObjectPtr
|
||||
}
|
||||
if(belongs_to_static_table) {
|
||||
SQInteger mmidx;
|
||||
if((type(val) == OT_CLOSURE || type(val) == OT_NATIVECLOSURE) &&
|
||||
if((sq_type(val) == OT_CLOSURE || sq_type(val) == OT_NATIVECLOSURE) &&
|
||||
(mmidx = ss->GetMetaMethodIdxByName(key)) != -1) {
|
||||
_metamethods[mmidx] = val;
|
||||
}
|
||||
else {
|
||||
SQObjectPtr theval = val;
|
||||
if(_base && type(val) == OT_CLOSURE) {
|
||||
if(_base && sq_type(val) == OT_CLOSURE) {
|
||||
theval = _closure(val)->Clone();
|
||||
_closure(theval)->_base = _base;
|
||||
__ObjAddRef(_base); //ref for the closure
|
||||
}
|
||||
if(type(temp) == OT_NULL) {
|
||||
if(sq_type(temp) == OT_NULL) {
|
||||
bool isconstructor;
|
||||
SQVM::IsEqual(ss->_constructoridx, key, isconstructor);
|
||||
if(isconstructor) {
|
||||
@@ -189,9 +189,9 @@ SQInstance::~SQInstance()
|
||||
if(_class){ Finalize(); } //if _class is null it was already finalized by the GC
|
||||
}
|
||||
|
||||
bool SQInstance::GetMetaMethod(SQVM SQ_UNUSED_ARG(*v),SQMetaMethod mm,SQObjectPtr &res)
|
||||
bool SQInstance::GetMetaMethod(SQVM* SQ_UNUSED_ARG(v),SQMetaMethod mm,SQObjectPtr &res)
|
||||
{
|
||||
if(type(_class->_metamethods[mm]) != OT_NULL) {
|
||||
if(sq_type(_class->_metamethods[mm]) != OT_NULL) {
|
||||
res = _class->_metamethods[mm];
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -191,7 +191,7 @@ public:
|
||||
}
|
||||
else {
|
||||
if(_raiseerror && _ss(_vm)->_compilererrorhandler) {
|
||||
_ss(_vm)->_compilererrorhandler(_vm, _compilererror, type(_sourcename) == OT_STRING?_stringval(_sourcename):_SC("unknown"),
|
||||
_ss(_vm)->_compilererrorhandler(_vm, _compilererror, sq_type(_sourcename) == OT_STRING?_stringval(_sourcename):_SC("unknown"),
|
||||
_lex._currentline, _lex._currentcolumn);
|
||||
}
|
||||
_vm->_lasterror = SQString::Create(_ss(_vm), _compilererror, -1);
|
||||
@@ -466,6 +466,7 @@ public:
|
||||
INVOKE_EXP(f);
|
||||
SQInteger op1 = _fs->PopTarget();SQInteger op2 = _fs->PopTarget();
|
||||
_fs->AddInstruction(op, _fs->PushTarget(), op1, op2, op3);
|
||||
_es.etype = EXPR;
|
||||
}
|
||||
void LogicalOrExp()
|
||||
{
|
||||
@@ -482,6 +483,7 @@ public:
|
||||
if(trg != second_exp) _fs->AddInstruction(_OP_MOVE, trg, second_exp);
|
||||
_fs->SnoozeOpt();
|
||||
_fs->SetIntructionParam(jpos, 1, (_fs->GetCurrentPos() - jpos));
|
||||
_es.etype = EXPR;
|
||||
break;
|
||||
}else return;
|
||||
}
|
||||
@@ -501,6 +503,7 @@ public:
|
||||
if(trg != second_exp) _fs->AddInstruction(_OP_MOVE, trg, second_exp);
|
||||
_fs->SnoozeOpt();
|
||||
_fs->SetIntructionParam(jpos, 1, (_fs->GetCurrentPos() - jpos));
|
||||
_es.etype = EXPR;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -762,7 +765,7 @@ public:
|
||||
/* Handle named constant */
|
||||
SQObjectPtr constval;
|
||||
SQObject constid;
|
||||
if(type(constant) == OT_TABLE) {
|
||||
if(sq_type(constant) == OT_TABLE) {
|
||||
Expect('.');
|
||||
constid = Expect(TK_IDENTIFIER);
|
||||
if(!_table(constant)->Get(constid, constval)) {
|
||||
@@ -776,7 +779,7 @@ public:
|
||||
_es.epos = _fs->PushTarget();
|
||||
|
||||
/* generate direct or literal function depending on size */
|
||||
SQObjectType ctype = type(constval);
|
||||
SQObjectType ctype = sq_type(constval);
|
||||
switch(ctype) {
|
||||
case OT_INTEGER: EmitLoadConstInt(_integer(constval),_es.epos); break;
|
||||
case OT_FLOAT: EmitLoadConstFloat(_float(constval),_es.epos); break;
|
||||
@@ -859,6 +862,7 @@ public:
|
||||
case TK_TYPEOF : Lex() ;UnaryOP(_OP_TYPEOF); break;
|
||||
case TK_RESUME : Lex(); UnaryOP(_OP_RESUME); break;
|
||||
case TK_CLONE : Lex(); UnaryOP(_OP_CLONE); break;
|
||||
case TK_RAWCALL: Lex(); Expect('('); FunctionCallArgs(true); break;
|
||||
case TK_MINUSMINUS :
|
||||
case TK_PLUSPLUS :PrefixIncDec(_token); break;
|
||||
case TK_DELETE : DeleteExpr(); break;
|
||||
@@ -915,7 +919,7 @@ public:
|
||||
}
|
||||
return (!_es.donot_get || ( _es.donot_get && (_token == _SC('.') || _token == _SC('['))));
|
||||
}
|
||||
void FunctionCallArgs()
|
||||
void FunctionCallArgs(bool rawcall = false)
|
||||
{
|
||||
SQInteger nargs = 1;//this
|
||||
while(_token != _SC(')')) {
|
||||
@@ -928,6 +932,10 @@ public:
|
||||
}
|
||||
}
|
||||
Lex();
|
||||
if (rawcall) {
|
||||
if (nargs < 3) Error(_SC("rawcall requires at least 2 parameters (callee and this)"));
|
||||
nargs -= 2; //removes callee and this from count
|
||||
}
|
||||
for(SQInteger i = 0; i < (nargs - 1); i++) _fs->PopTarget();
|
||||
SQInteger stackbase = _fs->PopTarget();
|
||||
SQInteger closure = _fs->PopTarget();
|
||||
@@ -1163,9 +1171,10 @@ public:
|
||||
}
|
||||
_fs->AddInstruction(_OP_JMP, 0, jmppos - _fs->GetCurrentPos() - 1, 0);
|
||||
if(jzpos> 0) _fs->SetIntructionParam(jzpos, 1, _fs->GetCurrentPos() - jzpos);
|
||||
END_SCOPE();
|
||||
|
||||
|
||||
END_BREAKBLE_BLOCK(continuetrg);
|
||||
|
||||
END_SCOPE();
|
||||
}
|
||||
void ForEachStatement()
|
||||
{
|
||||
@@ -1337,11 +1346,11 @@ public:
|
||||
val._unVal.fFloat = -_lex._fvalue;
|
||||
break;
|
||||
default:
|
||||
Error(_SC("scalar expected : integer,float"));
|
||||
Error(_SC("scalar expected : integer, float"));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
Error(_SC("scalar expected : integer,float or string"));
|
||||
Error(_SC("scalar expected : integer, float, or string"));
|
||||
}
|
||||
Lex();
|
||||
return val;
|
||||
|
||||
@@ -70,6 +70,7 @@ struct SQVM;
|
||||
#define TK_STATIC 322
|
||||
#define TK_ENUM 323
|
||||
#define TK_CONST 324
|
||||
#define TK_RAWCALL 325
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -17,8 +17,8 @@ SQRESULT sq_getfunctioninfo(HSQUIRRELVM v,SQInteger level,SQFunctionInfo *fi)
|
||||
SQClosure *c = _closure(ci._closure);
|
||||
SQFunctionProto *proto = c->_function;
|
||||
fi->funcid = proto;
|
||||
fi->name = type(proto->_name) == OT_STRING?_stringval(proto->_name):_SC("unknown");
|
||||
fi->source = type(proto->_sourcename) == OT_STRING?_stringval(proto->_sourcename):_SC("unknown");
|
||||
fi->name = sq_type(proto->_name) == OT_STRING?_stringval(proto->_name):_SC("unknown");
|
||||
fi->source = sq_type(proto->_sourcename) == OT_STRING?_stringval(proto->_sourcename):_SC("unknown");
|
||||
fi->line = proto->_lineinfos[0]._line;
|
||||
return SQ_OK;
|
||||
}
|
||||
@@ -32,12 +32,12 @@ SQRESULT sq_stackinfos(HSQUIRRELVM v, SQInteger level, SQStackInfos *si)
|
||||
if (cssize > level) {
|
||||
memset(si, 0, sizeof(SQStackInfos));
|
||||
SQVM::CallInfo &ci = v->_callsstack[cssize-level-1];
|
||||
switch (type(ci._closure)) {
|
||||
switch (sq_type(ci._closure)) {
|
||||
case OT_CLOSURE:{
|
||||
SQFunctionProto *func = _closure(ci._closure)->_function;
|
||||
if (type(func->_name) == OT_STRING)
|
||||
if (sq_type(func->_name) == OT_STRING)
|
||||
si->funcname = _stringval(func->_name);
|
||||
if (type(func->_sourcename) == OT_STRING)
|
||||
if (sq_type(func->_sourcename) == OT_STRING)
|
||||
si->source = _stringval(func->_sourcename);
|
||||
si->line = func->GetLine(ci._ip);
|
||||
}
|
||||
@@ -45,7 +45,7 @@ SQRESULT sq_stackinfos(HSQUIRRELVM v, SQInteger level, SQStackInfos *si)
|
||||
case OT_NATIVECLOSURE:
|
||||
si->source = _SC("NATIVE");
|
||||
si->funcname = _SC("unknown");
|
||||
if(type(_nativeclosure(ci._closure)->_name) == OT_STRING)
|
||||
if(sq_type(_nativeclosure(ci._closure)->_name) == OT_STRING)
|
||||
si->funcname = _stringval(_nativeclosure(ci._closure)->_name);
|
||||
si->line = -1;
|
||||
break;
|
||||
@@ -73,7 +73,7 @@ void SQVM::Raise_Error(const SQObjectPtr &desc)
|
||||
|
||||
SQString *SQVM::PrintObjVal(const SQObjectPtr &o)
|
||||
{
|
||||
switch(type(o)) {
|
||||
switch(sq_type(o)) {
|
||||
case OT_STRING: return _string(o);
|
||||
case OT_INTEGER:
|
||||
scsprintf(_sp(sq_rsl(NUMBER_MAX_CHAR+1)),sq_rsl(NUMBER_MAX_CHAR), _PRINT_INT_FMT, _integer(o));
|
||||
@@ -107,7 +107,7 @@ void SQVM::Raise_ParamTypeError(SQInteger nparam,SQInteger typemask,SQInteger ty
|
||||
SQInteger found = 0;
|
||||
for(SQInteger i=0; i<16; i++)
|
||||
{
|
||||
SQInteger mask = 0x00000001 << i;
|
||||
SQInteger mask = ((SQInteger)1) << i;
|
||||
if(typemask & (mask)) {
|
||||
if(found>0) StringCat(exptypes,SQString::Create(_ss(this), _SC("|"), -1), exptypes);
|
||||
found ++;
|
||||
|
||||
@@ -77,7 +77,7 @@ SQInstructionDesc g_InstrDesc[]={
|
||||
#endif
|
||||
void DumpLiteral(SQObjectPtr &o)
|
||||
{
|
||||
switch(type(o)){
|
||||
switch(sq_type(o)){
|
||||
case OT_STRING: scprintf(_SC("\"%s\""),_stringval(o));break;
|
||||
case OT_FLOAT: scprintf(_SC("{%f}"),_float(o));break;
|
||||
case OT_INTEGER: scprintf(_SC("{") _PRINT_INT_FMT _SC("}"),_integer(o));break;
|
||||
@@ -117,10 +117,10 @@ void SQFuncState::Dump(SQFunctionProto *func)
|
||||
{
|
||||
SQUnsignedInteger n=0,i;
|
||||
SQInteger si;
|
||||
scprintf(_SC("SQInstruction sizeof %d\n"),sizeof(SQInstruction));
|
||||
scprintf(_SC("SQObject sizeof %d\n"),sizeof(SQObject));
|
||||
scprintf(_SC("SQInstruction sizeof %d\n"),(SQInt32)sizeof(SQInstruction));
|
||||
scprintf(_SC("SQObject sizeof %d\n"), (SQInt32)sizeof(SQObject));
|
||||
scprintf(_SC("--------------------------------------------------------------------\n"));
|
||||
scprintf(_SC("*****FUNCTION [%s]\n"),type(func->_name)==OT_STRING?_stringval(func->_name):_SC("unknown"));
|
||||
scprintf(_SC("*****FUNCTION [%s]\n"),sq_type(func->_name)==OT_STRING?_stringval(func->_name):_SC("unknown"));
|
||||
scprintf(_SC("-----LITERALS\n"));
|
||||
SQObjectPtr refidx,key,val;
|
||||
SQInteger idx;
|
||||
@@ -131,7 +131,7 @@ void SQFuncState::Dump(SQFunctionProto *func)
|
||||
templiterals[_integer(val)]=key;
|
||||
}
|
||||
for(i=0;i<templiterals.size();i++){
|
||||
scprintf(_SC("[%d] "),n);
|
||||
scprintf(_SC("[%d] "), (SQInt32)n);
|
||||
DumpLiteral(templiterals[i]);
|
||||
scprintf(_SC("\n"));
|
||||
n++;
|
||||
@@ -141,7 +141,7 @@ void SQFuncState::Dump(SQFunctionProto *func)
|
||||
scprintf(_SC("<<VARPARAMS>>\n"));
|
||||
n=0;
|
||||
for(i=0;i<_parameters.size();i++){
|
||||
scprintf(_SC("[%d] "),n);
|
||||
scprintf(_SC("[%d] "), (SQInt32)n);
|
||||
DumpLiteral(_parameters[i]);
|
||||
scprintf(_SC("\n"));
|
||||
n++;
|
||||
@@ -149,13 +149,13 @@ void SQFuncState::Dump(SQFunctionProto *func)
|
||||
scprintf(_SC("-----LOCALS\n"));
|
||||
for(si=0;si<func->_nlocalvarinfos;si++){
|
||||
SQLocalVarInfo lvi=func->_localvarinfos[si];
|
||||
scprintf(_SC("[%d] %s \t%d %d\n"),lvi._pos,_stringval(lvi._name),lvi._start_op,lvi._end_op);
|
||||
scprintf(_SC("[%d] %s \t%d %d\n"), (SQInt32)lvi._pos,_stringval(lvi._name), (SQInt32)lvi._start_op, (SQInt32)lvi._end_op);
|
||||
n++;
|
||||
}
|
||||
scprintf(_SC("-----LINE INFO\n"));
|
||||
for(i=0;i<_lineinfos.size();i++){
|
||||
SQLineInfo li=_lineinfos[i];
|
||||
scprintf(_SC("op [%d] line [%d] \n"),li._op,li._line);
|
||||
scprintf(_SC("op [%d] line [%d] \n"), (SQInt32)li._op, (SQInt32)li._line);
|
||||
n++;
|
||||
}
|
||||
scprintf(_SC("-----dump\n"));
|
||||
@@ -165,7 +165,7 @@ void SQFuncState::Dump(SQFunctionProto *func)
|
||||
if(inst.op==_OP_LOAD || inst.op==_OP_DLOAD || inst.op==_OP_PREPCALLK || inst.op==_OP_GETK ){
|
||||
|
||||
SQInteger lidx = inst._arg1;
|
||||
scprintf(_SC("[%03d] %15s %d "),n,g_InstrDesc[inst.op].name,inst._arg0);
|
||||
scprintf(_SC("[%03d] %15s %d "), (SQInt32)n,g_InstrDesc[inst.op].name,inst._arg0);
|
||||
if(lidx >= 0xFFFFFFFF)
|
||||
scprintf(_SC("null"));
|
||||
else {
|
||||
@@ -196,18 +196,18 @@ void SQFuncState::Dump(SQFunctionProto *func)
|
||||
}
|
||||
}
|
||||
else if(inst.op==_OP_LOADFLOAT) {
|
||||
scprintf(_SC("[%03d] %15s %d %f %d %d\n"),n,g_InstrDesc[inst.op].name,inst._arg0,*((SQFloat*)&inst._arg1),inst._arg2,inst._arg3);
|
||||
scprintf(_SC("[%03d] %15s %d %f %d %d\n"), (SQInt32)n,g_InstrDesc[inst.op].name,inst._arg0,*((SQFloat*)&inst._arg1),inst._arg2,inst._arg3);
|
||||
}
|
||||
/* else if(inst.op==_OP_ARITH){
|
||||
scprintf(_SC("[%03d] %15s %d %d %d %c\n"),n,g_InstrDesc[inst.op].name,inst._arg0,inst._arg1,inst._arg2,inst._arg3);
|
||||
}*/
|
||||
else {
|
||||
scprintf(_SC("[%03d] %15s %d %d %d %d\n"),n,g_InstrDesc[inst.op].name,inst._arg0,inst._arg1,inst._arg2,inst._arg3);
|
||||
scprintf(_SC("[%03d] %15s %d %d %d %d\n"), (SQInt32)n,g_InstrDesc[inst.op].name,inst._arg0,inst._arg1,inst._arg2,inst._arg3);
|
||||
}
|
||||
n++;
|
||||
}
|
||||
scprintf(_SC("-----\n"));
|
||||
scprintf(_SC("stack size[%d]\n"),func->_stacksize);
|
||||
scprintf(_SC("stack size[%d]\n"), (SQInt32)func->_stacksize);
|
||||
scprintf(_SC("--------------------------------------------------------------------\n\n"));
|
||||
}
|
||||
#endif
|
||||
@@ -290,7 +290,7 @@ SQInteger SQFuncState::PopTarget()
|
||||
SQUnsignedInteger npos=_targetstack.back();
|
||||
assert(npos < _vlocals.size());
|
||||
SQLocalVarInfo &t = _vlocals[npos];
|
||||
if(type(t._name)==OT_NULL){
|
||||
if(sq_type(t._name)==OT_NULL){
|
||||
_vlocals.pop_back();
|
||||
}
|
||||
_targetstack.pop_back();
|
||||
@@ -322,7 +322,7 @@ void SQFuncState::SetStackSize(SQInteger n)
|
||||
while(size>n){
|
||||
size--;
|
||||
SQLocalVarInfo lvi = _vlocals.back();
|
||||
if(type(lvi._name)!=OT_NULL){
|
||||
if(sq_type(lvi._name)!=OT_NULL){
|
||||
if(lvi._end_op == UINT_MINUS_ONE) { //this means is an outer
|
||||
_outers--;
|
||||
}
|
||||
@@ -346,7 +346,7 @@ bool SQFuncState::IsConstant(const SQObject &name,SQObject &e)
|
||||
bool SQFuncState::IsLocal(SQUnsignedInteger stkpos)
|
||||
{
|
||||
if(stkpos>=_vlocals.size())return false;
|
||||
else if(type(_vlocals[stkpos]._name)!=OT_NULL)return true;
|
||||
else if(sq_type(_vlocals[stkpos]._name)!=OT_NULL)return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -369,7 +369,7 @@ SQInteger SQFuncState::GetLocalVariable(const SQObject &name)
|
||||
SQInteger locals=_vlocals.size();
|
||||
while(locals>=1){
|
||||
SQLocalVarInfo &lvi = _vlocals[locals-1];
|
||||
if(type(lvi._name)==OT_STRING && _string(lvi._name)==_string(name)){
|
||||
if(sq_type(lvi._name)==OT_STRING && _string(lvi._name)==_string(name)){
|
||||
return locals-1;
|
||||
}
|
||||
locals--;
|
||||
|
||||
@@ -67,6 +67,8 @@ void SQLexer::Init(SQSharedState *ss, SQLEXREADFUNC rg, SQUserPointer up,Compile
|
||||
ADD_KEYWORD(const,TK_CONST);
|
||||
ADD_KEYWORD(__LINE__,TK___LINE__);
|
||||
ADD_KEYWORD(__FILE__,TK___FILE__);
|
||||
ADD_KEYWORD(rawcall, TK_RAWCALL);
|
||||
|
||||
|
||||
_readf = rg;
|
||||
_up = up;
|
||||
@@ -381,7 +383,7 @@ SQInteger SQLexer::ReadString(SQInteger ndelim,bool verbatim)
|
||||
break;
|
||||
case _SC('U'):
|
||||
case _SC('u'): {
|
||||
const SQInteger maxdigits = x == 'u' ? 4 : 8;
|
||||
const SQInteger maxdigits = CUR_CHAR == 'u' ? 4 : 8;
|
||||
SQChar temp[8 + 1];
|
||||
ProcessStringHexEscape(temp, maxdigits);
|
||||
SQChar *stemp;
|
||||
@@ -389,7 +391,7 @@ SQInteger SQLexer::ReadString(SQInteger ndelim,bool verbatim)
|
||||
#if WCHAR_SIZE == 2
|
||||
AddUTF16(scstrtoul(temp, &stemp, 16));
|
||||
#else
|
||||
ADD_CHAR((SQChar)scstrtoul(temp, &stemp, 16));
|
||||
APPEND_CHAR((SQChar)scstrtoul(temp, &stemp, 16));
|
||||
#endif
|
||||
#else
|
||||
AddUTF8(scstrtoul(temp, &stemp, 16));
|
||||
|
||||
@@ -43,7 +43,7 @@ const SQChar *IdType2Name(SQObjectType type)
|
||||
|
||||
const SQChar *GetTypeName(const SQObjectPtr &obj1)
|
||||
{
|
||||
return IdType2Name(type(obj1));
|
||||
return IdType2Name(sq_type(obj1));
|
||||
}
|
||||
|
||||
SQString *SQString::Create(SQSharedState *ss,const SQChar *s,SQInteger len)
|
||||
@@ -72,7 +72,7 @@ SQInteger SQString::Next(const SQObjectPtr &refpos, SQObjectPtr &outkey, SQObjec
|
||||
|
||||
SQUnsignedInteger TranslateIndex(const SQObjectPtr &idx)
|
||||
{
|
||||
switch(type(idx)){
|
||||
switch(sq_type(idx)){
|
||||
case OT_NULL:
|
||||
return 0;
|
||||
case OT_INTEGER:
|
||||
@@ -139,7 +139,7 @@ bool SQGenerator::Yield(SQVM *v,SQInteger target)
|
||||
|
||||
_stack.resize(size);
|
||||
SQObject _this = v->_stack[v->_stackbase];
|
||||
_stack._vals[0] = ISREFCOUNTED(type(_this)) ? SQObjectPtr(_refcounted(_this)->GetWeakRef(type(_this))) : _this;
|
||||
_stack._vals[0] = ISREFCOUNTED(sq_type(_this)) ? SQObjectPtr(_refcounted(_this)->GetWeakRef(sq_type(_this))) : _this;
|
||||
for(SQInteger n =1; n<target; n++) {
|
||||
_stack._vals[n] = v->_stack[v->_stackbase+n];
|
||||
}
|
||||
@@ -191,7 +191,7 @@ bool SQGenerator::Resume(SQVM *v,SQObjectPtr &dest)
|
||||
et._stacksize += newbase;
|
||||
}
|
||||
SQObject _this = _stack._vals[0];
|
||||
v->_stack[v->_stackbase] = type(_this) == OT_WEAKREF ? _weakref(_this)->_obj : _this;
|
||||
v->_stack[v->_stackbase] = sq_type(_this) == OT_WEAKREF ? _weakref(_this)->_obj : _this;
|
||||
|
||||
for(SQInteger n = 1; n<size; n++) {
|
||||
v->_stack[v->_stackbase+n] = _stack._vals[n];
|
||||
@@ -312,9 +312,9 @@ bool CheckTag(HSQUIRRELVM v,SQWRITEFUNC read,SQUserPointer up,SQUnsignedInteger3
|
||||
|
||||
bool WriteObject(HSQUIRRELVM v,SQUserPointer up,SQWRITEFUNC write,SQObjectPtr &o)
|
||||
{
|
||||
SQUnsignedInteger32 _type = (SQUnsignedInteger32)type(o);
|
||||
SQUnsignedInteger32 _type = (SQUnsignedInteger32)sq_type(o);
|
||||
_CHECK_IO(SafeWrite(v,write,up,&_type,sizeof(_type)));
|
||||
switch(type(o)){
|
||||
switch(sq_type(o)){
|
||||
case OT_STRING:
|
||||
_CHECK_IO(SafeWrite(v,write,up,&_string(o)->_len,sizeof(SQInteger)));
|
||||
_CHECK_IO(SafeWrite(v,write,up,_stringval(o),sq_rsl(_string(o)->_len)));
|
||||
|
||||
@@ -101,7 +101,7 @@ struct SQWeakRef : SQRefCounted
|
||||
SQObject _obj;
|
||||
};
|
||||
|
||||
#define _realval(o) (type((o)) != OT_WEAKREF?(SQObject)o:_weakref(o)->_obj)
|
||||
#define _realval(o) (sq_type((o)) != OT_WEAKREF?(SQObject)o:_weakref(o)->_obj)
|
||||
|
||||
struct SQObjectPtr;
|
||||
|
||||
@@ -128,8 +128,7 @@ struct SQObjectPtr;
|
||||
(obj)->_uiRef++; \
|
||||
}
|
||||
|
||||
#define type(obj) ((obj)._type)
|
||||
#define is_delegable(t) (type(t)&SQOBJECT_DELEGABLE)
|
||||
#define is_delegable(t) (sq_type(t)&SQOBJECT_DELEGABLE)
|
||||
#define raw_type(obj) _RAW_TYPE((obj)._type)
|
||||
|
||||
#define _integer(obj) ((obj)._unVal.nInteger)
|
||||
@@ -155,8 +154,8 @@ struct SQObjectPtr;
|
||||
#define _stringval(obj) (obj)._unVal.pString->_val
|
||||
#define _userdataval(obj) ((SQUserPointer)sq_aligning((obj)._unVal.pUserData + 1))
|
||||
|
||||
#define tofloat(num) ((type(num)==OT_INTEGER)?(SQFloat)_integer(num):_float(num))
|
||||
#define tointeger(num) ((type(num)==OT_FLOAT)?(SQInteger)_float(num):_integer(num))
|
||||
#define tofloat(num) ((sq_type(num)==OT_INTEGER)?(SQFloat)_integer(num):_float(num))
|
||||
#define tointeger(num) ((sq_type(num)==OT_FLOAT)?(SQInteger)_float(num):_integer(num))
|
||||
/////////////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////////////
|
||||
#if defined(SQUSEDOUBLE) && !defined(_SQ64) || !defined(SQUSEDOUBLE) && defined(_SQ64)
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
#include <assert.h>
|
||||
#include <new>
|
||||
//squirrel stuff
|
||||
#include <squirrel.h>
|
||||
#include <squirrel/squirrel.h>
|
||||
#include "sqobject.h"
|
||||
#include "sqstate.h"
|
||||
|
||||
|
||||
@@ -12,12 +12,6 @@
|
||||
#include "squserdata.h"
|
||||
#include "sqclass.h"
|
||||
|
||||
//SQObjectPtr _null_;
|
||||
//SQObjectPtr _true_(true);
|
||||
//SQObjectPtr _false_(false);
|
||||
//SQObjectPtr _one_((SQInteger)1);
|
||||
//SQObjectPtr _minusone_((SQInteger)-1);
|
||||
|
||||
SQSharedState::SQSharedState()
|
||||
{
|
||||
_compilererrorhandler = NULL;
|
||||
@@ -41,31 +35,29 @@ SQSharedState::SQSharedState()
|
||||
bool CompileTypemask(SQIntVec &res,const SQChar *typemask)
|
||||
{
|
||||
SQInteger i = 0;
|
||||
|
||||
SQInteger mask = 0;
|
||||
while(typemask[i] != 0) {
|
||||
|
||||
switch(typemask[i]){
|
||||
case 'o': mask |= _RT_NULL; break;
|
||||
case 'i': mask |= _RT_INTEGER; break;
|
||||
case 'f': mask |= _RT_FLOAT; break;
|
||||
case 'n': mask |= (_RT_FLOAT | _RT_INTEGER); break;
|
||||
case 's': mask |= _RT_STRING; break;
|
||||
case 't': mask |= _RT_TABLE; break;
|
||||
case 'a': mask |= _RT_ARRAY; break;
|
||||
case 'u': mask |= _RT_USERDATA; break;
|
||||
case 'c': mask |= (_RT_CLOSURE | _RT_NATIVECLOSURE); break;
|
||||
case 'b': mask |= _RT_BOOL; break;
|
||||
case 'g': mask |= _RT_GENERATOR; break;
|
||||
case 'p': mask |= _RT_USERPOINTER; break;
|
||||
case 'v': mask |= _RT_THREAD; break;
|
||||
case 'x': mask |= _RT_INSTANCE; break;
|
||||
case 'y': mask |= _RT_CLASS; break;
|
||||
case 'r': mask |= _RT_WEAKREF; break;
|
||||
case '.': mask = -1; res.push_back(mask); i++; mask = 0; continue;
|
||||
case ' ': i++; continue; //ignores spaces
|
||||
default:
|
||||
return false;
|
||||
switch(typemask[i]) {
|
||||
case 'o': mask |= _RT_NULL; break;
|
||||
case 'i': mask |= _RT_INTEGER; break;
|
||||
case 'f': mask |= _RT_FLOAT; break;
|
||||
case 'n': mask |= (_RT_FLOAT | _RT_INTEGER); break;
|
||||
case 's': mask |= _RT_STRING; break;
|
||||
case 't': mask |= _RT_TABLE; break;
|
||||
case 'a': mask |= _RT_ARRAY; break;
|
||||
case 'u': mask |= _RT_USERDATA; break;
|
||||
case 'c': mask |= (_RT_CLOSURE | _RT_NATIVECLOSURE); break;
|
||||
case 'b': mask |= _RT_BOOL; break;
|
||||
case 'g': mask |= _RT_GENERATOR; break;
|
||||
case 'p': mask |= _RT_USERPOINTER; break;
|
||||
case 'v': mask |= _RT_THREAD; break;
|
||||
case 'x': mask |= _RT_INSTANCE; break;
|
||||
case 'y': mask |= _RT_CLASS; break;
|
||||
case 'r': mask |= _RT_WEAKREF; break;
|
||||
case '.': mask = -1; res.push_back(mask); i++; mask = 0; continue;
|
||||
case ' ': i++; continue; //ignores spaces
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
i++;
|
||||
if(typemask[i] == '|') {
|
||||
@@ -160,7 +152,6 @@ void SQSharedState::Init()
|
||||
_class_default_delegate = CreateDefaultDelegate(this,_class_default_delegate_funcz);
|
||||
_instance_default_delegate = CreateDefaultDelegate(this,_instance_default_delegate_funcz);
|
||||
_weakref_default_delegate = CreateDefaultDelegate(this,_weakref_default_delegate_funcz);
|
||||
|
||||
}
|
||||
|
||||
SQSharedState::~SQSharedState()
|
||||
@@ -221,7 +212,7 @@ SQSharedState::~SQSharedState()
|
||||
|
||||
SQInteger SQSharedState::GetMetaMethodIdxByName(const SQObjectPtr &name)
|
||||
{
|
||||
if(type(name) != OT_STRING)
|
||||
if(sq_type(name) != OT_STRING)
|
||||
return -1;
|
||||
SQObjectPtr ret;
|
||||
if(_table(_metamethodsmap)->Get(name,ret)) {
|
||||
@@ -234,7 +225,7 @@ SQInteger SQSharedState::GetMetaMethodIdxByName(const SQObjectPtr &name)
|
||||
|
||||
void SQSharedState::MarkObject(SQObjectPtr &o,SQCollectable **chain)
|
||||
{
|
||||
switch(type(o)){
|
||||
switch(sq_type(o)){
|
||||
case OT_TABLE:_table(o)->Mark(chain);break;
|
||||
case OT_ARRAY:_array(o)->Mark(chain);break;
|
||||
case OT_USERDATA:_userdata(o)->Mark(chain);break;
|
||||
@@ -250,7 +241,7 @@ void SQSharedState::MarkObject(SQObjectPtr &o,SQCollectable **chain)
|
||||
}
|
||||
}
|
||||
|
||||
void SQSharedState::RunMark(SQVM SQ_UNUSED_ARG(*vm),SQCollectable **tchain)
|
||||
void SQSharedState::RunMark(SQVM* SQ_UNUSED_ARG(vm),SQCollectable **tchain)
|
||||
{
|
||||
SQVM *vms = _thread(_root_vm);
|
||||
|
||||
@@ -282,7 +273,6 @@ SQInteger SQSharedState::ResurrectUnreachable(SQVM *vm)
|
||||
|
||||
SQCollectable *resurrected = _gc_chain;
|
||||
SQCollectable *t = resurrected;
|
||||
//SQCollectable *nx = NULL;
|
||||
|
||||
_gc_chain = tchain;
|
||||
|
||||
@@ -423,7 +413,7 @@ void RefTable::Mark(SQCollectable **chain)
|
||||
{
|
||||
RefNode *nodes = (RefNode *)_nodes;
|
||||
for(SQUnsignedInteger n = 0; n < _numofslots; n++) {
|
||||
if(type(nodes->obj) != OT_NULL) {
|
||||
if(sq_type(nodes->obj) != OT_NULL) {
|
||||
SQSharedState::MarkObject(nodes->obj,chain);
|
||||
}
|
||||
nodes++;
|
||||
@@ -485,7 +475,7 @@ void RefTable::Resize(SQUnsignedInteger size)
|
||||
//rehash
|
||||
SQUnsignedInteger nfound = 0;
|
||||
for(SQUnsignedInteger n = 0; n < oldnumofslots; n++) {
|
||||
if(type(t->obj) != OT_NULL) {
|
||||
if(sq_type(t->obj) != OT_NULL) {
|
||||
//add back;
|
||||
assert(t->refs != 0);
|
||||
RefNode *nn = Add(::HashObj(t->obj)&(_numofslots-1),t->obj);
|
||||
@@ -518,7 +508,7 @@ RefTable::RefNode *RefTable::Get(SQObject &obj,SQHash &mainpos,RefNode **prev,bo
|
||||
mainpos = ::HashObj(obj)&(_numofslots-1);
|
||||
*prev = NULL;
|
||||
for (ref = _buckets[mainpos]; ref; ) {
|
||||
if(_rawval(ref->obj) == _rawval(obj) && type(ref->obj) == type(obj))
|
||||
if(_rawval(ref->obj) == _rawval(obj) && sq_type(ref->obj) == sq_type(obj))
|
||||
break;
|
||||
*prev = ref;
|
||||
ref = ref->next;
|
||||
|
||||
@@ -62,7 +62,7 @@ void SQTable::Rehash(bool force)
|
||||
_usednodes = 0;
|
||||
for (SQInteger i=0; i<oldsize; i++) {
|
||||
_HashNode *old = nold+i;
|
||||
if (type(old->key) != OT_NULL)
|
||||
if (sq_type(old->key) != OT_NULL)
|
||||
NewSlot(old->key,old->val);
|
||||
}
|
||||
for(SQInteger k=0;k<oldsize;k++)
|
||||
@@ -107,7 +107,7 @@ SQTable *SQTable::Clone()
|
||||
|
||||
bool SQTable::Get(const SQObjectPtr &key,SQObjectPtr &val)
|
||||
{
|
||||
if(type(key) == OT_NULL)
|
||||
if(sq_type(key) == OT_NULL)
|
||||
return false;
|
||||
_HashNode *n = _Get(key, HashObj(key) & (_numofnodes - 1));
|
||||
if (n) {
|
||||
@@ -118,7 +118,7 @@ bool SQTable::Get(const SQObjectPtr &key,SQObjectPtr &val)
|
||||
}
|
||||
bool SQTable::NewSlot(const SQObjectPtr &key,const SQObjectPtr &val)
|
||||
{
|
||||
assert(type(key) != OT_NULL);
|
||||
assert(sq_type(key) != OT_NULL);
|
||||
SQHash h = HashObj(key) & (_numofnodes - 1);
|
||||
_HashNode *n = _Get(key, h);
|
||||
if (n) {
|
||||
@@ -132,7 +132,7 @@ bool SQTable::NewSlot(const SQObjectPtr &key,const SQObjectPtr &val)
|
||||
//key not found I'll insert it
|
||||
//main pos is not free
|
||||
|
||||
if(type(mp->key) != OT_NULL) {
|
||||
if(sq_type(mp->key) != OT_NULL) {
|
||||
n = _firstfree; /* get a free place */
|
||||
SQHash mph = HashObj(mp->key) & (_numofnodes - 1);
|
||||
_HashNode *othern; /* main position of colliding node */
|
||||
@@ -161,7 +161,7 @@ bool SQTable::NewSlot(const SQObjectPtr &key,const SQObjectPtr &val)
|
||||
mp->key = key;
|
||||
|
||||
for (;;) { /* correct `firstfree' */
|
||||
if (type(_firstfree->key) == OT_NULL && _firstfree->next == NULL) {
|
||||
if (sq_type(_firstfree->key) == OT_NULL && _firstfree->next == NULL) {
|
||||
mp->val = val;
|
||||
_usednodes++;
|
||||
return true; /* OK; table still has a free place */
|
||||
@@ -177,7 +177,7 @@ SQInteger SQTable::Next(bool getweakrefs,const SQObjectPtr &refpos, SQObjectPtr
|
||||
{
|
||||
SQInteger idx = (SQInteger)TranslateIndex(refpos);
|
||||
while (idx < _numofnodes) {
|
||||
if(type(_nodes[idx].key) != OT_NULL) {
|
||||
if(sq_type(_nodes[idx].key) != OT_NULL) {
|
||||
//first found
|
||||
_HashNode &n = _nodes[idx];
|
||||
outkey = n.key;
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
|
||||
inline SQHash HashObj(const SQObjectPtr &key)
|
||||
{
|
||||
switch(type(key)) {
|
||||
switch(sq_type(key)) {
|
||||
case OT_STRING: return _string(key)->_hash;
|
||||
case OT_FLOAT: return (SQHash)((SQInteger)_float(key));
|
||||
case OT_BOOL: case OT_INTEGER: return (SQHash)((SQInteger)_integer(key));
|
||||
@@ -67,7 +67,7 @@ public:
|
||||
{
|
||||
_HashNode *n = &_nodes[hash];
|
||||
do{
|
||||
if(_rawval(n->key) == _rawval(key) && type(n->key) == type(key)){
|
||||
if(_rawval(n->key) == _rawval(key) && sq_type(n->key) == sq_type(key)){
|
||||
return n;
|
||||
}
|
||||
}while((n = n->next));
|
||||
@@ -80,7 +80,7 @@ public:
|
||||
_HashNode *n = &_nodes[hash & (_numofnodes - 1)];
|
||||
_HashNode *res = NULL;
|
||||
do{
|
||||
if(type(n->key) == OT_STRING && (scstrcmp(_stringval(n->key),key) == 0)){
|
||||
if(sq_type(n->key) == OT_STRING && (scstrcmp(_stringval(n->key),key) == 0)){
|
||||
res = n;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -15,11 +15,13 @@
|
||||
#include "sqclass.h"
|
||||
|
||||
#define TOP() (_stack._vals[_top-1])
|
||||
#define TARGET _stack._vals[_stackbase+arg0]
|
||||
#define STK(a) _stack._vals[_stackbase+(a)]
|
||||
|
||||
bool SQVM::BW_OP(SQUnsignedInteger op,SQObjectPtr &trg,const SQObjectPtr &o1,const SQObjectPtr &o2)
|
||||
{
|
||||
SQInteger res;
|
||||
if((type(o1)|type(o2)) == OT_INTEGER)
|
||||
if((sq_type(o1)| sq_type(o2)) == OT_INTEGER)
|
||||
{
|
||||
SQInteger i1 = _integer(o1), i2 = _integer(o2);
|
||||
switch(op) {
|
||||
@@ -39,7 +41,7 @@ bool SQVM::BW_OP(SQUnsignedInteger op,SQObjectPtr &trg,const SQObjectPtr &o1,con
|
||||
|
||||
#define _ARITH_(op,trg,o1,o2) \
|
||||
{ \
|
||||
SQInteger tmask = type(o1)|type(o2); \
|
||||
SQInteger tmask = sq_type(o1)|sq_type(o2); \
|
||||
switch(tmask) { \
|
||||
case OT_INTEGER: trg = _integer(o1) op _integer(o2);break; \
|
||||
case (OT_FLOAT|OT_INTEGER): \
|
||||
@@ -50,7 +52,7 @@ bool SQVM::BW_OP(SQUnsignedInteger op,SQObjectPtr &trg,const SQObjectPtr &o1,con
|
||||
|
||||
#define _ARITH_NOZERO(op,trg,o1,o2,err) \
|
||||
{ \
|
||||
SQInteger tmask = type(o1)|type(o2); \
|
||||
SQInteger tmask = sq_type(o1)|sq_type(o2); \
|
||||
switch(tmask) { \
|
||||
case OT_INTEGER: { SQInteger i2 = _integer(o2); if(i2 == 0) { Raise_Error(err); SQ_THROW(); } trg = _integer(o1) op i2; } break;\
|
||||
case (OT_FLOAT|OT_INTEGER): \
|
||||
@@ -61,7 +63,7 @@ bool SQVM::BW_OP(SQUnsignedInteger op,SQObjectPtr &trg,const SQObjectPtr &o1,con
|
||||
|
||||
bool SQVM::ARITH_OP(SQUnsignedInteger op,SQObjectPtr &trg,const SQObjectPtr &o1,const SQObjectPtr &o2)
|
||||
{
|
||||
SQInteger tmask = type(o1)|type(o2);
|
||||
SQInteger tmask = sq_type(o1)| sq_type(o2);
|
||||
switch(tmask) {
|
||||
case OT_INTEGER:{
|
||||
SQInteger res, i1 = _integer(o1), i2 = _integer(o2);
|
||||
@@ -175,7 +177,7 @@ bool SQVM::ArithMetaMethod(SQInteger op,const SQObjectPtr &o1,const SQObjectPtr
|
||||
bool SQVM::NEG_OP(SQObjectPtr &trg,const SQObjectPtr &o)
|
||||
{
|
||||
|
||||
switch(type(o)) {
|
||||
switch(sq_type(o)) {
|
||||
case OT_INTEGER:
|
||||
trg = -_integer(o);
|
||||
return true;
|
||||
@@ -204,7 +206,7 @@ bool SQVM::NEG_OP(SQObjectPtr &trg,const SQObjectPtr &o)
|
||||
#define _RET_SUCCEED(exp) { result = (exp); return true; }
|
||||
bool SQVM::ObjCmp(const SQObjectPtr &o1,const SQObjectPtr &o2,SQInteger &result)
|
||||
{
|
||||
SQObjectType t1 = type(o1), t2 = type(o2);
|
||||
SQObjectType t1 = sq_type(o1), t2 = sq_type(o2);
|
||||
if(t1 == t2) {
|
||||
if(_rawval(o1) == _rawval(o2))_RET_SUCCEED(0);
|
||||
SQObjectPtr res;
|
||||
@@ -223,7 +225,7 @@ bool SQVM::ObjCmp(const SQObjectPtr &o1,const SQObjectPtr &o2,SQInteger &result)
|
||||
if(_delegable(o1)->GetMetaMethod(this, MT_CMP, closure)) {
|
||||
Push(o1);Push(o2);
|
||||
if(CallMetaMethod(closure,MT_CMP,2,res)) {
|
||||
if(type(res) != OT_INTEGER) {
|
||||
if(sq_type(res) != OT_INTEGER) {
|
||||
Raise_Error(_SC("_cmp must return an integer"));
|
||||
return false;
|
||||
}
|
||||
@@ -281,7 +283,7 @@ bool SQVM::CMP_OP(CmpOP op, const SQObjectPtr &o1,const SQObjectPtr &o2,SQObject
|
||||
|
||||
bool SQVM::ToString(const SQObjectPtr &o,SQObjectPtr &res)
|
||||
{
|
||||
switch(type(o)) {
|
||||
switch(sq_type(o)) {
|
||||
case OT_STRING:
|
||||
res = o;
|
||||
return true;
|
||||
@@ -301,8 +303,8 @@ bool SQVM::ToString(const SQObjectPtr &o,SQObjectPtr &res)
|
||||
SQObjectPtr closure;
|
||||
if(_delegable(o)->GetMetaMethod(this, MT_TOSTRING, closure)) {
|
||||
Push(o);
|
||||
if(CallMetaMethod(closure,MT_TOSTRING,1,res)) {;
|
||||
if(type(res) == OT_STRING)
|
||||
if(CallMetaMethod(closure,MT_TOSTRING,1,res)) {
|
||||
if(sq_type(res) == OT_STRING)
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
@@ -517,7 +519,7 @@ bool SQVM::FOREACH_OP(SQObjectPtr &o1,SQObjectPtr &o2,SQObjectPtr
|
||||
&o3,SQObjectPtr &o4,SQInteger SQ_UNUSED_ARG(arg_2),int exitpos,int &jump)
|
||||
{
|
||||
SQInteger nrefidx;
|
||||
switch(type(o1)) {
|
||||
switch(sq_type(o1)) {
|
||||
case OT_TABLE:
|
||||
if((nrefidx = _table(o1)->Next(false,o4, o2, o3)) == -1) _FINISH(exitpos);
|
||||
o4 = (SQInteger)nrefidx; _FINISH(1);
|
||||
@@ -540,7 +542,7 @@ bool SQVM::FOREACH_OP(SQObjectPtr &o1,SQObjectPtr &o2,SQObjectPtr
|
||||
Push(o4);
|
||||
if(CallMetaMethod(closure, MT_NEXTI, 2, itr)) {
|
||||
o4 = o2 = itr;
|
||||
if(type(itr) == OT_NULL) _FINISH(exitpos);
|
||||
if(sq_type(itr) == OT_NULL) _FINISH(exitpos);
|
||||
if(!Get(o1, itr, o3, 0, DONT_FALL_BACK)) {
|
||||
Raise_Error(_SC("_nexti returned an invalid idx")); // cloud be changed
|
||||
return false;
|
||||
@@ -559,7 +561,7 @@ bool SQVM::FOREACH_OP(SQObjectPtr &o1,SQObjectPtr &o2,SQObjectPtr
|
||||
if(_generator(o1)->_state == SQGenerator::eDead) _FINISH(exitpos);
|
||||
if(_generator(o1)->_state == SQGenerator::eSuspended) {
|
||||
SQInteger idx = 0;
|
||||
if(type(o4) == OT_INTEGER) {
|
||||
if(sq_type(o4) == OT_INTEGER) {
|
||||
idx = _integer(o4) + 1;
|
||||
}
|
||||
o2 = idx;
|
||||
@@ -614,14 +616,14 @@ bool SQVM::CLASS_OP(SQObjectPtr &target,SQInteger baseclass,SQInteger attributes
|
||||
SQClass *base = NULL;
|
||||
SQObjectPtr attrs;
|
||||
if(baseclass != -1) {
|
||||
if(type(_stack._vals[_stackbase+baseclass]) != OT_CLASS) { Raise_Error(_SC("trying to inherit from a %s"),GetTypeName(_stack._vals[_stackbase+baseclass])); return false; }
|
||||
if(sq_type(_stack._vals[_stackbase+baseclass]) != OT_CLASS) { Raise_Error(_SC("trying to inherit from a %s"),GetTypeName(_stack._vals[_stackbase+baseclass])); return false; }
|
||||
base = _class(_stack._vals[_stackbase + baseclass]);
|
||||
}
|
||||
if(attributes != MAX_FUNC_STACKSIZE) {
|
||||
attrs = _stack._vals[_stackbase+attributes];
|
||||
}
|
||||
target = SQClass::Create(_ss(this),base);
|
||||
if(type(_class(target)->_metamethods[MT_INHERITED]) != OT_NULL) {
|
||||
if(sq_type(_class(target)->_metamethods[MT_INHERITED]) != OT_NULL) {
|
||||
int nparams = 2;
|
||||
SQObjectPtr ret;
|
||||
Push(target); Push(attrs);
|
||||
@@ -637,7 +639,7 @@ bool SQVM::CLASS_OP(SQObjectPtr &target,SQInteger baseclass,SQInteger attributes
|
||||
|
||||
bool SQVM::IsEqual(const SQObjectPtr &o1,const SQObjectPtr &o2,bool &res)
|
||||
{
|
||||
if(type(o1) == type(o2)) {
|
||||
if(sq_type(o1) == sq_type(o2)) {
|
||||
res = (_rawval(o1) == _rawval(o2));
|
||||
}
|
||||
else {
|
||||
@@ -653,8 +655,8 @@ bool SQVM::IsEqual(const SQObjectPtr &o1,const SQObjectPtr &o2,bool &res)
|
||||
|
||||
bool SQVM::IsFalse(SQObjectPtr &o)
|
||||
{
|
||||
if(((type(o) & SQOBJECT_CANBEFALSE)
|
||||
&& ( ((type(o) == OT_FLOAT) && (_float(o) == SQFloat(0.0))) ))
|
||||
if(((sq_type(o) & SQOBJECT_CANBEFALSE)
|
||||
&& ( ((sq_type(o) == OT_FLOAT) && (_float(o) == SQFloat(0.0))) ))
|
||||
#if !defined(SQUSEDOUBLE) || (defined(SQUSEDOUBLE) && defined(_SQ64))
|
||||
|| (_integer(o) == 0) ) //OT_NULL|OT_INTEGER|OT_BOOL
|
||||
#else
|
||||
@@ -721,24 +723,29 @@ exception_restore:
|
||||
case _OP_DLOAD: TARGET = ci->_literals[arg1]; STK(arg2) = ci->_literals[arg3];continue;
|
||||
case _OP_TAILCALL:{
|
||||
SQObjectPtr &t = STK(arg1);
|
||||
if (type(t) == OT_CLOSURE
|
||||
if (sq_type(t) == OT_CLOSURE
|
||||
&& (!_closure(t)->_function->_bgenerator)){
|
||||
SQObjectPtr clo = t;
|
||||
SQInteger last_top = _top;
|
||||
if(_openouters) CloseOuters(&(_stack._vals[_stackbase]));
|
||||
for (SQInteger i = 0; i < arg3; i++) STK(i) = STK(arg2 + i);
|
||||
_GUARD(StartCall(_closure(clo), ci->_target, arg3, _stackbase, true));
|
||||
if (last_top >= _top) {
|
||||
_top = last_top;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
case _OP_CALL: {
|
||||
SQObjectPtr clo = STK(arg1);
|
||||
switch (type(clo)) {
|
||||
switch (sq_type(clo)) {
|
||||
case OT_CLOSURE:
|
||||
_GUARD(StartCall(_closure(clo), sarg0, arg3, _stackbase+arg2, false));
|
||||
continue;
|
||||
case OT_NATIVECLOSURE: {
|
||||
bool suspend;
|
||||
_GUARD(CallNative(_nativeclosure(clo), arg3, _stackbase+arg2, clo,suspend));
|
||||
bool tailcall;
|
||||
_GUARD(CallNative(_nativeclosure(clo), arg3, _stackbase+arg2, clo, (SQInt32)sarg0, suspend, tailcall));
|
||||
if(suspend){
|
||||
_suspended = SQTrue;
|
||||
_suspended_target = sarg0;
|
||||
@@ -747,7 +754,7 @@ exception_restore:
|
||||
outres = clo;
|
||||
return true;
|
||||
}
|
||||
if(sarg0 != -1) {
|
||||
if(sarg0 != -1 && !tailcall) {
|
||||
STK(arg0) = clo;
|
||||
}
|
||||
}
|
||||
@@ -759,17 +766,17 @@ exception_restore:
|
||||
STK(arg0) = inst;
|
||||
}
|
||||
SQInteger stkbase;
|
||||
switch(type(clo)) {
|
||||
switch(sq_type(clo)) {
|
||||
case OT_CLOSURE:
|
||||
stkbase = _stackbase+arg2;
|
||||
_stack._vals[stkbase] = inst;
|
||||
_GUARD(StartCall(_closure(clo), -1, arg3, stkbase, false));
|
||||
break;
|
||||
case OT_NATIVECLOSURE:
|
||||
bool suspend;
|
||||
bool dummy;
|
||||
stkbase = _stackbase+arg2;
|
||||
_stack._vals[stkbase] = inst;
|
||||
_GUARD(CallNative(_nativeclosure(clo), arg3, stkbase, clo,suspend));
|
||||
_GUARD(CallNative(_nativeclosure(clo), arg3, stkbase, clo, -1, dummy, dummy));
|
||||
break;
|
||||
default: break; //shutup GCC 4.x
|
||||
}
|
||||
@@ -857,7 +864,7 @@ exception_restore:
|
||||
case _OP_LOADNULLS:{ for(SQInt32 n=0; n < arg1; n++) STK(arg0+n).Null(); }continue;
|
||||
case _OP_LOADROOT: {
|
||||
SQWeakRef *w = _closure(ci->_closure)->_root;
|
||||
if(type(w->_obj) != OT_NULL) {
|
||||
if(sq_type(w->_obj) != OT_NULL) {
|
||||
TARGET = w->_obj;
|
||||
} else {
|
||||
TARGET = _roottable; //shoud this be like this? or null
|
||||
@@ -933,7 +940,7 @@ exception_restore:
|
||||
case _OP_INC: {SQObjectPtr o(sarg3); _GUARD(DerefInc('+',TARGET, STK(arg1), STK(arg2), o, false, arg1));} continue;
|
||||
case _OP_INCL: {
|
||||
SQObjectPtr &a = STK(arg1);
|
||||
if(type(a) == OT_INTEGER) {
|
||||
if(sq_type(a) == OT_INTEGER) {
|
||||
a._unVal.nInteger = _integer(a) + sarg3;
|
||||
}
|
||||
else {
|
||||
@@ -944,7 +951,7 @@ exception_restore:
|
||||
case _OP_PINC: {SQObjectPtr o(sarg3); _GUARD(DerefInc('+',TARGET, STK(arg1), STK(arg2), o, true, arg1));} continue;
|
||||
case _OP_PINCL: {
|
||||
SQObjectPtr &a = STK(arg1);
|
||||
if(type(a) == OT_INTEGER) {
|
||||
if(sq_type(a) == OT_INTEGER) {
|
||||
TARGET = a;
|
||||
a._unVal.nInteger = _integer(a) + sarg3;
|
||||
}
|
||||
@@ -956,9 +963,9 @@ exception_restore:
|
||||
case _OP_CMP: _GUARD(CMP_OP((CmpOP)arg3,STK(arg2),STK(arg1),TARGET)) continue;
|
||||
case _OP_EXISTS: TARGET = Get(STK(arg1), STK(arg2), temp_reg, GET_FLAG_DO_NOT_RAISE_ERROR | GET_FLAG_RAW, DONT_FALL_BACK) ? true : false; continue;
|
||||
case _OP_INSTANCEOF:
|
||||
if(type(STK(arg1)) != OT_CLASS)
|
||||
if(sq_type(STK(arg1)) != OT_CLASS)
|
||||
{Raise_Error(_SC("cannot apply instanceof between a %s and a %s"),GetTypeName(STK(arg1)),GetTypeName(STK(arg2))); SQ_THROW();}
|
||||
TARGET = (type(STK(arg2)) == OT_INSTANCE) ? (_instance(STK(arg2))->InstanceOf(_class(STK(arg1)))?true:false) : false;
|
||||
TARGET = (sq_type(STK(arg2)) == OT_INSTANCE) ? (_instance(STK(arg2))->InstanceOf(_class(STK(arg1)))?true:false) : false;
|
||||
continue;
|
||||
case _OP_AND:
|
||||
if(IsFalse(STK(arg2))) {
|
||||
@@ -975,7 +982,7 @@ exception_restore:
|
||||
case _OP_NEG: _GUARD(NEG_OP(TARGET,STK(arg1))); continue;
|
||||
case _OP_NOT: TARGET = IsFalse(STK(arg1)); continue;
|
||||
case _OP_BWNOT:
|
||||
if(type(STK(arg1)) == OT_INTEGER) {
|
||||
if(sq_type(STK(arg1)) == OT_INTEGER) {
|
||||
SQInteger t = _integer(STK(arg1));
|
||||
TARGET = SQInteger(~t);
|
||||
continue;
|
||||
@@ -1005,7 +1012,7 @@ exception_restore:
|
||||
}
|
||||
continue;
|
||||
case _OP_RESUME:
|
||||
if(type(STK(arg1)) != OT_GENERATOR){ Raise_Error(_SC("trying to resume a '%s',only genenerator can be resumed"), GetTypeName(STK(arg1))); SQ_THROW();}
|
||||
if(sq_type(STK(arg1)) != OT_GENERATOR){ Raise_Error(_SC("trying to resume a '%s',only genenerator can be resumed"), GetTypeName(STK(arg1))); SQ_THROW();}
|
||||
_GUARD(_generator(STK(arg1))->Resume(this, TARGET));
|
||||
traps += ci->_etraps;
|
||||
continue;
|
||||
@@ -1014,7 +1021,7 @@ exception_restore:
|
||||
ci->_ip += tojump; }
|
||||
continue;
|
||||
case _OP_POSTFOREACH:
|
||||
assert(type(STK(arg0)) == OT_GENERATOR);
|
||||
assert(sq_type(STK(arg0)) == OT_GENERATOR);
|
||||
if(_generator(STK(arg0))->_state == SQGenerator::eDead)
|
||||
ci->_ip += (sarg1 - 1);
|
||||
continue;
|
||||
@@ -1104,7 +1111,7 @@ bool SQVM::CreateClassInstance(SQClass *theclass, SQObjectPtr &inst, SQObjectPtr
|
||||
|
||||
void SQVM::CallErrorHandler(SQObjectPtr &error)
|
||||
{
|
||||
if(type(_errorhandler) != OT_NULL) {
|
||||
if(sq_type(_errorhandler) != OT_NULL) {
|
||||
SQObjectPtr out;
|
||||
Push(_roottable); Push(error);
|
||||
Call(_errorhandler, 2, _top-2, out,SQFalse);
|
||||
@@ -1118,8 +1125,8 @@ void SQVM::CallDebugHook(SQInteger type,SQInteger forcedline)
|
||||
_debughook = false;
|
||||
SQFunctionProto *func=_closure(ci->_closure)->_function;
|
||||
if(_debughook_native) {
|
||||
const SQChar *src = type(func->_sourcename) == OT_STRING?_stringval(func->_sourcename):NULL;
|
||||
const SQChar *fname = type(func->_name) == OT_STRING?_stringval(func->_name):NULL;
|
||||
const SQChar *src = sq_type(func->_sourcename) == OT_STRING?_stringval(func->_sourcename):NULL;
|
||||
const SQChar *fname = sq_type(func->_name) == OT_STRING?_stringval(func->_name):NULL;
|
||||
SQInteger line = forcedline?forcedline:func->GetLine(ci->_ip);
|
||||
_debughook_native(this,type,src,line,fname);
|
||||
}
|
||||
@@ -1133,7 +1140,7 @@ void SQVM::CallDebugHook(SQInteger type,SQInteger forcedline)
|
||||
_debughook = true;
|
||||
}
|
||||
|
||||
bool SQVM::CallNative(SQNativeClosure *nclosure, SQInteger nargs, SQInteger newbase, SQObjectPtr &retval, bool &suspend)
|
||||
bool SQVM::CallNative(SQNativeClosure *nclosure, SQInteger nargs, SQInteger newbase, SQObjectPtr &retval, SQInt32 target,bool &suspend, bool &tailcall)
|
||||
{
|
||||
SQInteger nparamscheck = nclosure->_nparamscheck;
|
||||
SQInteger newtop = newbase + nargs + nclosure->_noutervalues;
|
||||
@@ -1154,8 +1161,8 @@ bool SQVM::CallNative(SQNativeClosure *nclosure, SQInteger nargs, SQInteger newb
|
||||
SQIntVec &tc = nclosure->_typecheck;
|
||||
if((tcs = tc.size())) {
|
||||
for(SQInteger i = 0; i < nargs && i < tcs; i++) {
|
||||
if((tc._vals[i] != -1) && !(type(_stack._vals[newbase+i]) & tc._vals[i])) {
|
||||
Raise_ParamTypeError(i,tc._vals[i],type(_stack._vals[newbase+i]));
|
||||
if((tc._vals[i] != -1) && !(sq_type(_stack._vals[newbase+i]) & tc._vals[i])) {
|
||||
Raise_ParamTypeError(i,tc._vals[i], sq_type(_stack._vals[newbase+i]));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1163,6 +1170,7 @@ bool SQVM::CallNative(SQNativeClosure *nclosure, SQInteger nargs, SQInteger newb
|
||||
|
||||
if(!EnterFrame(newbase, newtop, false)) return false;
|
||||
ci->_closure = nclosure;
|
||||
ci->_target = target;
|
||||
|
||||
SQInteger outers = nclosure->_noutervalues;
|
||||
for (SQInteger i = 0; i < outers; i++) {
|
||||
@@ -1177,7 +1185,12 @@ bool SQVM::CallNative(SQNativeClosure *nclosure, SQInteger nargs, SQInteger newb
|
||||
_nnativecalls--;
|
||||
|
||||
suspend = false;
|
||||
if (ret == SQ_SUSPEND_FLAG) {
|
||||
tailcall = false;
|
||||
if (ret == SQ_TAILCALL_FLAG) {
|
||||
tailcall = true;
|
||||
return true;
|
||||
}
|
||||
else if (ret == SQ_SUSPEND_FLAG) {
|
||||
suspend = true;
|
||||
}
|
||||
else if (ret < 0) {
|
||||
@@ -1196,13 +1209,30 @@ bool SQVM::CallNative(SQNativeClosure *nclosure, SQInteger nargs, SQInteger newb
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SQVM::TailCall(SQClosure *closure, SQInteger parambase,SQInteger nparams)
|
||||
{
|
||||
SQInteger last_top = _top;
|
||||
SQObjectPtr clo = closure;
|
||||
if (ci->_root)
|
||||
{
|
||||
Raise_Error("root calls cannot invoke tailcalls");
|
||||
return false;
|
||||
}
|
||||
for (SQInteger i = 0; i < nparams; i++) STK(i) = STK(parambase + i);
|
||||
bool ret = StartCall(closure, ci->_target, nparams, _stackbase, true);
|
||||
if (last_top >= _top) {
|
||||
_top = last_top;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
#define FALLBACK_OK 0
|
||||
#define FALLBACK_NO_MATCH 1
|
||||
#define FALLBACK_ERROR 2
|
||||
|
||||
bool SQVM::Get(const SQObjectPtr &self, const SQObjectPtr &key, SQObjectPtr &dest, SQUnsignedInteger getflags, SQInteger selfidx)
|
||||
{
|
||||
switch(type(self)){
|
||||
switch(sq_type(self)){
|
||||
case OT_TABLE:
|
||||
if(_table(self)->Get(key,dest))return true;
|
||||
break;
|
||||
@@ -1243,7 +1273,7 @@ bool SQVM::Get(const SQObjectPtr &self, const SQObjectPtr &key, SQObjectPtr &des
|
||||
//#ifdef ROOT_FALLBACK
|
||||
if(selfidx == 0) {
|
||||
SQWeakRef *w = _closure(ci->_closure)->_root;
|
||||
if(type(w->_obj) != OT_NULL)
|
||||
if(sq_type(w->_obj) != OT_NULL)
|
||||
{
|
||||
if(Get(*((const SQObjectPtr *)&w->_obj),key,dest,0,DONT_FALL_BACK)) return true;
|
||||
}
|
||||
@@ -1257,7 +1287,7 @@ bool SQVM::Get(const SQObjectPtr &self, const SQObjectPtr &key, SQObjectPtr &des
|
||||
bool SQVM::InvokeDefaultDelegate(const SQObjectPtr &self,const SQObjectPtr &key,SQObjectPtr &dest)
|
||||
{
|
||||
SQTable *ddel = NULL;
|
||||
switch(type(self)) {
|
||||
switch(sq_type(self)) {
|
||||
case OT_CLASS: ddel = _class_ddel; break;
|
||||
case OT_TABLE: ddel = _table_ddel; break;
|
||||
case OT_ARRAY: ddel = _array_ddel; break;
|
||||
@@ -1276,7 +1306,7 @@ bool SQVM::InvokeDefaultDelegate(const SQObjectPtr &self,const SQObjectPtr &key,
|
||||
|
||||
SQInteger SQVM::FallBackGet(const SQObjectPtr &self,const SQObjectPtr &key,SQObjectPtr &dest)
|
||||
{
|
||||
switch(type(self)){
|
||||
switch(sq_type(self)){
|
||||
case OT_TABLE:
|
||||
case OT_USERDATA:
|
||||
//delegation
|
||||
@@ -1299,7 +1329,7 @@ SQInteger SQVM::FallBackGet(const SQObjectPtr &self,const SQObjectPtr &key,SQObj
|
||||
}
|
||||
else {
|
||||
Pop(2);
|
||||
if(type(_lasterror) != OT_NULL) { //NULL means "clean failure" (not found)
|
||||
if(sq_type(_lasterror) != OT_NULL) { //NULL means "clean failure" (not found)
|
||||
return FALLBACK_ERROR;
|
||||
}
|
||||
}
|
||||
@@ -1314,7 +1344,7 @@ SQInteger SQVM::FallBackGet(const SQObjectPtr &self,const SQObjectPtr &key,SQObj
|
||||
|
||||
bool SQVM::Set(const SQObjectPtr &self,const SQObjectPtr &key,const SQObjectPtr &val,SQInteger selfidx)
|
||||
{
|
||||
switch(type(self)){
|
||||
switch(sq_type(self)){
|
||||
case OT_TABLE:
|
||||
if(_table(self)->Set(key,val)) return true;
|
||||
break;
|
||||
@@ -1328,6 +1358,7 @@ bool SQVM::Set(const SQObjectPtr &self,const SQObjectPtr &key,const SQObjectPtr
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
case OT_USERDATA: break; // must fall back
|
||||
default:
|
||||
Raise_Error(_SC("trying to set '%s'"),GetTypeName(self));
|
||||
return false;
|
||||
@@ -1348,7 +1379,7 @@ bool SQVM::Set(const SQObjectPtr &self,const SQObjectPtr &key,const SQObjectPtr
|
||||
|
||||
SQInteger SQVM::FallBackSet(const SQObjectPtr &self,const SQObjectPtr &key,const SQObjectPtr &val)
|
||||
{
|
||||
switch(type(self)) {
|
||||
switch(sq_type(self)) {
|
||||
case OT_TABLE:
|
||||
if(_table(self)->_delegate) {
|
||||
if(Set(_table(self)->_delegate,key,val,DONT_FALL_BACK)) return FALLBACK_OK;
|
||||
@@ -1367,9 +1398,8 @@ SQInteger SQVM::FallBackSet(const SQObjectPtr &self,const SQObjectPtr &key,const
|
||||
return FALLBACK_OK;
|
||||
}
|
||||
else {
|
||||
if(type(_lasterror) != OT_NULL) { //NULL means "clean failure" (not found)
|
||||
//error
|
||||
Pop(3);
|
||||
Pop(3);
|
||||
if(sq_type(_lasterror) != OT_NULL) { //NULL means "clean failure" (not found)
|
||||
return FALLBACK_ERROR;
|
||||
}
|
||||
}
|
||||
@@ -1386,7 +1416,7 @@ bool SQVM::Clone(const SQObjectPtr &self,SQObjectPtr &target)
|
||||
{
|
||||
SQObjectPtr temp_reg;
|
||||
SQObjectPtr newobj;
|
||||
switch(type(self)){
|
||||
switch(sq_type(self)){
|
||||
case OT_TABLE:
|
||||
newobj = _table(self)->Clone();
|
||||
goto cloned_mt;
|
||||
@@ -1414,14 +1444,14 @@ cloned_mt:
|
||||
|
||||
bool SQVM::NewSlotA(const SQObjectPtr &self,const SQObjectPtr &key,const SQObjectPtr &val,const SQObjectPtr &attrs,bool bstatic,bool raw)
|
||||
{
|
||||
if(type(self) != OT_CLASS) {
|
||||
if(sq_type(self) != OT_CLASS) {
|
||||
Raise_Error(_SC("object must be a class"));
|
||||
return false;
|
||||
}
|
||||
SQClass *c = _class(self);
|
||||
if(!raw) {
|
||||
SQObjectPtr &mm = c->_metamethods[MT_NEWMEMBER];
|
||||
if(type(mm) != OT_NULL ) {
|
||||
if(sq_type(mm) != OT_NULL ) {
|
||||
Push(self); Push(key); Push(val);
|
||||
Push(attrs);
|
||||
Push(bstatic);
|
||||
@@ -1430,7 +1460,7 @@ bool SQVM::NewSlotA(const SQObjectPtr &self,const SQObjectPtr &key,const SQObjec
|
||||
}
|
||||
if(!NewSlot(self, key, val,bstatic))
|
||||
return false;
|
||||
if(type(attrs) != OT_NULL) {
|
||||
if(sq_type(attrs) != OT_NULL) {
|
||||
c->SetAttributes(key,attrs);
|
||||
}
|
||||
return true;
|
||||
@@ -1438,8 +1468,8 @@ bool SQVM::NewSlotA(const SQObjectPtr &self,const SQObjectPtr &key,const SQObjec
|
||||
|
||||
bool SQVM::NewSlot(const SQObjectPtr &self,const SQObjectPtr &key,const SQObjectPtr &val,bool bstatic)
|
||||
{
|
||||
if(type(key) == OT_NULL) { Raise_Error(_SC("null cannot be used as index")); return false; }
|
||||
switch(type(self)) {
|
||||
if(sq_type(key) == OT_NULL) { Raise_Error(_SC("null cannot be used as index")); return false; }
|
||||
switch(sq_type(self)) {
|
||||
case OT_TABLE: {
|
||||
bool rawcall = true;
|
||||
if(_table(self)->_delegate) {
|
||||
@@ -1499,7 +1529,7 @@ bool SQVM::NewSlot(const SQObjectPtr &self,const SQObjectPtr &key,const SQObject
|
||||
|
||||
bool SQVM::DeleteSlot(const SQObjectPtr &self,const SQObjectPtr &key,SQObjectPtr &res)
|
||||
{
|
||||
switch(type(self)) {
|
||||
switch(sq_type(self)) {
|
||||
case OT_TABLE:
|
||||
case OT_INSTANCE:
|
||||
case OT_USERDATA: {
|
||||
@@ -1511,7 +1541,7 @@ bool SQVM::DeleteSlot(const SQObjectPtr &self,const SQObjectPtr &key,SQObjectPtr
|
||||
return CallMetaMethod(closure,MT_DELSLOT,2,res);
|
||||
}
|
||||
else {
|
||||
if(type(self) == OT_TABLE) {
|
||||
if(sq_type(self) == OT_TABLE) {
|
||||
if(_table(self)->Get(key,t)) {
|
||||
_table(self)->Remove(key);
|
||||
}
|
||||
@@ -1540,13 +1570,13 @@ bool SQVM::Call(SQObjectPtr &closure,SQInteger nparams,SQInteger stackbase,SQObj
|
||||
#ifdef _DEBUG
|
||||
SQInteger prevstackbase = _stackbase;
|
||||
#endif
|
||||
switch(type(closure)) {
|
||||
switch(sq_type(closure)) {
|
||||
case OT_CLOSURE:
|
||||
return Execute(closure, nparams, stackbase, outres, raiseerror);
|
||||
break;
|
||||
case OT_NATIVECLOSURE:{
|
||||
bool suspend;
|
||||
return CallNative(_nativeclosure(closure), nparams, stackbase, outres,suspend);
|
||||
bool dummy;
|
||||
return CallNative(_nativeclosure(closure), nparams, stackbase, outres, -1, dummy, dummy);
|
||||
|
||||
}
|
||||
break;
|
||||
@@ -1554,7 +1584,7 @@ SQInteger prevstackbase = _stackbase;
|
||||
SQObjectPtr constr;
|
||||
SQObjectPtr temp;
|
||||
CreateClassInstance(_class(closure),outres,constr);
|
||||
SQObjectType ctype = type(constr);
|
||||
SQObjectType ctype = sq_type(constr);
|
||||
if (ctype == OT_NATIVECLOSURE || ctype == OT_CLOSURE) {
|
||||
_stack[stackbase] = outres;
|
||||
return Call(constr,nparams,stackbase,temp,raiseerror);
|
||||
@@ -1632,7 +1662,7 @@ bool SQVM::EnterFrame(SQInteger newbase, SQInteger newtop, bool tailcall)
|
||||
_top = newtop;
|
||||
if(newtop + MIN_STACK_OVERHEAD > (SQInteger)_stack.size()) {
|
||||
if(_nmetamethodscall) {
|
||||
Raise_Error(_SC("stack overflow, cannot resize stack while in a metamethod"));
|
||||
Raise_Error(_SC("stack overflow, cannot resize stack while in a metamethod"));
|
||||
return false;
|
||||
}
|
||||
_stack.resize(newtop + (MIN_STACK_OVERHEAD << 2));
|
||||
@@ -1716,10 +1746,10 @@ void SQVM::dumpstack(SQInteger stackbase,bool dumpall)
|
||||
for(SQInteger i=0;i<size;i++){
|
||||
SQObjectPtr &obj=_stack[i];
|
||||
if(stackbase==i)scprintf(_SC(">"));else scprintf(_SC(" "));
|
||||
scprintf(_SC("[%d]:"),n);
|
||||
switch(type(obj)){
|
||||
scprintf(_SC("[" _PRINT_INT_FMT "]:"),n);
|
||||
switch(sq_type(obj)){
|
||||
case OT_FLOAT: scprintf(_SC("FLOAT %.3f"),_float(obj));break;
|
||||
case OT_INTEGER: scprintf(_SC("INTEGER %d"),_integer(obj));break;
|
||||
case OT_INTEGER: scprintf(_SC("INTEGER " _PRINT_INT_FMT),_integer(obj));break;
|
||||
case OT_BOOL: scprintf(_SC("BOOL %s"),_integer(obj)?"true":"false");break;
|
||||
case OT_STRING: scprintf(_SC("STRING %s"),_stringval(obj));break;
|
||||
case OT_NULL: scprintf(_SC("NULL")); break;
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#define MIN_STACK_OVERHEAD 15
|
||||
|
||||
#define SQ_SUSPEND_FLAG -666
|
||||
#define SQ_TAILCALL_FLAG -777
|
||||
#define DONT_FALL_BACK 666
|
||||
//#define EXISTS_FALL_BACK -1
|
||||
|
||||
@@ -28,9 +29,6 @@ struct SQExceptionTrap{
|
||||
|
||||
#define _INLINE
|
||||
|
||||
#define STK(a) _stack._vals[_stackbase+(a)]
|
||||
#define TARGET _stack._vals[_stackbase+arg0]
|
||||
|
||||
typedef sqvector<SQExceptionTrap> ExceptionsTraps;
|
||||
|
||||
struct SQVM : public CHAINABLE_OBJ
|
||||
@@ -59,7 +57,8 @@ public:
|
||||
bool Init(SQVM *friendvm, SQInteger stacksize);
|
||||
bool Execute(SQObjectPtr &func, SQInteger nargs, SQInteger stackbase, SQObjectPtr &outres, SQBool raiseerror, ExecutionType et = ET_CALL);
|
||||
//starts a native call return when the NATIVE closure returns
|
||||
bool CallNative(SQNativeClosure *nclosure, SQInteger nargs, SQInteger newbase, SQObjectPtr &retval,bool &suspend);
|
||||
bool CallNative(SQNativeClosure *nclosure, SQInteger nargs, SQInteger newbase, SQObjectPtr &retval, SQInt32 target, bool &suspend,bool &tailcall);
|
||||
bool TailCall(SQClosure *closure, SQInteger firstparam, SQInteger nparams);
|
||||
//starts a SQUIRREL call in the same "Execution loop"
|
||||
bool StartCall(SQClosure *closure, SQInteger target, SQInteger nargs, SQInteger stackbase, bool tailcall);
|
||||
bool CreateClassInstance(SQClass *theclass, SQObjectPtr &inst, SQObjectPtr &constructor);
|
||||
|
||||
Reference in New Issue
Block a user