Merge branch 'master' into infrastructure_sharing
Conflicts: src/aircraft_cmd.cpp src/economy.cpp src/lang/english.txt src/order_gui.cpp src/roadveh_cmd.cpp src/saveload/saveload.cpp src/settings.cpp src/settings_gui.cpp src/train_cmd.cpp
This commit is contained in:
3
src/3rdparty/README.licensing
vendored
Normal file
3
src/3rdparty/README.licensing
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
The files in this directory are not licensed under the same terms as the
|
||||
rest of OpenTTD. Licensing details can be found in OpenTTD's readme.txt
|
||||
and in this directory or subdirectories as well.
|
2
src/3rdparty/md5/md5.cpp
vendored
2
src/3rdparty/md5/md5.cpp
vendored
@@ -60,6 +60,8 @@
|
||||
#include "../../core/endian_func.hpp"
|
||||
#include "md5.h"
|
||||
|
||||
#include "../../safeguards.h"
|
||||
|
||||
#define T_MASK ((uint32)~0)
|
||||
#define T1 /* 0xd76aa478 */ (T_MASK ^ 0x28955b87)
|
||||
#define T2 /* 0xe8c7b756 */ (T_MASK ^ 0x173848a9)
|
||||
|
299
src/3rdparty/os2/getaddrinfo.c
vendored
Normal file
299
src/3rdparty/os2/getaddrinfo.c
vendored
Normal file
@@ -0,0 +1,299 @@
|
||||
/*
|
||||
* This file is part of libESMTP, a library for submission of RFC 2822
|
||||
* formatted electronic mail messages using the SMTP protocol described
|
||||
* in RFC 2821.
|
||||
*
|
||||
* Copyright (C) 2001,2002 Brian Stafford <brian@stafford.uklinux.net>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
/* An emulation of the RFC 2553 / Posix getaddrinfo resolver interface.
|
||||
*/
|
||||
|
||||
#if !HAVE_GETADDRINFO
|
||||
|
||||
/* Need to turn off Posix features in glibc to build this */
|
||||
#undef _POSIX_C_SOURCE
|
||||
#undef _XOPEN_SOURCE
|
||||
|
||||
#include "getaddrinfo.h"
|
||||
//#include "compat/inet_pton.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <netdb.h>
|
||||
|
||||
static struct addrinfo *
|
||||
dup_addrinfo (struct addrinfo *info, void *addr, size_t addrlen) {
|
||||
struct addrinfo *ret;
|
||||
|
||||
ret = malloc (sizeof (struct addrinfo));
|
||||
if (ret == NULL)
|
||||
return NULL;
|
||||
memcpy (ret, info, sizeof (struct addrinfo));
|
||||
ret->ai_addr = malloc (addrlen);
|
||||
if (ret->ai_addr == NULL) {
|
||||
free (ret);
|
||||
return NULL;
|
||||
}
|
||||
memcpy (ret->ai_addr, addr, addrlen);
|
||||
ret->ai_addrlen = addrlen;
|
||||
return ret;
|
||||
}
|
||||
|
||||
int
|
||||
getaddrinfo (const char *nodename, const char *servname,
|
||||
const struct addrinfo *hints, struct addrinfo **res)
|
||||
{
|
||||
struct hostent *hp;
|
||||
struct servent *servent;
|
||||
const char *socktype;
|
||||
int port;
|
||||
struct addrinfo hint, result;
|
||||
struct addrinfo *ai, *sai, *eai;
|
||||
char **addrs;
|
||||
|
||||
if (servname == NULL && nodename == NULL)
|
||||
return EAI_NONAME;
|
||||
|
||||
memset (&result, 0, sizeof result);
|
||||
|
||||
/* default for hints */
|
||||
if (hints == NULL) {
|
||||
memset (&hint, 0, sizeof hint);
|
||||
hint.ai_family = PF_UNSPEC;
|
||||
hints = &hint;
|
||||
}
|
||||
|
||||
if (servname == NULL)
|
||||
port = 0;
|
||||
else {
|
||||
/* check for tcp or udp sockets only */
|
||||
if (hints->ai_socktype == SOCK_STREAM)
|
||||
socktype = "tcp";
|
||||
else if (hints->ai_socktype == SOCK_DGRAM)
|
||||
socktype = "udp";
|
||||
else
|
||||
return EAI_SERVICE;
|
||||
result.ai_socktype = hints->ai_socktype;
|
||||
|
||||
/* Note: maintain port in host byte order to make debugging easier */
|
||||
if (isdigit (*servname))
|
||||
port = strtol (servname, NULL, 10);
|
||||
else if ((servent = getservbyname (servname, socktype)) != NULL)
|
||||
port = ntohs (servent->s_port);
|
||||
else
|
||||
return EAI_NONAME;
|
||||
}
|
||||
|
||||
/* if nodename == NULL refer to the local host for a client or any
|
||||
for a server */
|
||||
if (nodename == NULL) {
|
||||
struct sockaddr_in sin;
|
||||
|
||||
/* check protocol family is PF_UNSPEC or PF_INET - could try harder
|
||||
for IPv6 but that's more code than I'm prepared to write */
|
||||
if (hints->ai_family == PF_UNSPEC || hints->ai_family == PF_INET)
|
||||
result.ai_family = AF_INET;
|
||||
else
|
||||
return EAI_FAMILY;
|
||||
|
||||
sin.sin_family = result.ai_family;
|
||||
sin.sin_port = htons (port);
|
||||
if (hints->ai_flags & AI_PASSIVE)
|
||||
sin.sin_addr.s_addr = htonl (INADDR_ANY);
|
||||
else
|
||||
sin.sin_addr.s_addr = htonl (INADDR_LOOPBACK);
|
||||
/* Duplicate result and addr and return */
|
||||
*res = dup_addrinfo (&result, &sin, sizeof sin);
|
||||
return (*res == NULL) ? EAI_MEMORY : 0;
|
||||
}
|
||||
|
||||
/* If AI_NUMERIC is specified, use inet_pton to translate numbers and
|
||||
dots notation. */
|
||||
if (hints->ai_flags & AI_NUMERICHOST) {
|
||||
struct sockaddr_in sin;
|
||||
|
||||
/* check protocol family is PF_UNSPEC or PF_INET */
|
||||
if (hints->ai_family == PF_UNSPEC || hints->ai_family == PF_INET)
|
||||
result.ai_family = AF_INET;
|
||||
else
|
||||
return EAI_FAMILY;
|
||||
|
||||
sin.sin_family = result.ai_family;
|
||||
sin.sin_port = htons (port);
|
||||
if (inet_pton(result.ai_family, nodename, &sin.sin_addr)==0)
|
||||
return EAI_NONAME;
|
||||
sin.sin_addr.s_addr = inet_addr (nodename);
|
||||
/* Duplicate result and addr and return */
|
||||
*res = dup_addrinfo (&result, &sin, sizeof sin);
|
||||
return (*res == NULL) ? EAI_MEMORY : 0;
|
||||
}
|
||||
|
||||
#if HAVE_H_ERRNO
|
||||
h_errno = 0;
|
||||
#endif
|
||||
errno = 0;
|
||||
hp = gethostbyname(nodename);
|
||||
if (hp == NULL) {
|
||||
#ifdef EAI_SYSTEM
|
||||
if (errno != 0) {
|
||||
return EAI_SYSTEM;
|
||||
}
|
||||
#endif
|
||||
switch (h_errno) {
|
||||
case HOST_NOT_FOUND:
|
||||
return EAI_NODATA;
|
||||
case NO_DATA:
|
||||
return EAI_NODATA;
|
||||
#if defined(NO_ADDRESS) && NO_ADDRESS != NO_DATA
|
||||
case NO_ADDRESS:
|
||||
return EAI_NODATA;
|
||||
#endif
|
||||
case NO_RECOVERY:
|
||||
return EAI_FAIL;
|
||||
case TRY_AGAIN:
|
||||
return EAI_AGAIN;
|
||||
default:
|
||||
return EAI_FAIL;
|
||||
}
|
||||
return EAI_FAIL;
|
||||
}
|
||||
|
||||
/* Check that the address family is acceptable.
|
||||
*/
|
||||
switch (hp->h_addrtype) {
|
||||
case AF_INET:
|
||||
if (!(hints->ai_family == PF_UNSPEC || hints->ai_family == PF_INET))
|
||||
return EAI_FAMILY;
|
||||
break;
|
||||
#ifndef __OS2__
|
||||
case AF_INET6:
|
||||
if (!(hints->ai_family == PF_UNSPEC || hints->ai_family == PF_INET6))
|
||||
return EAI_FAMILY;
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
return EAI_FAMILY;
|
||||
}
|
||||
|
||||
/* For each element pointed to by hp, create an element in the
|
||||
result linked list. */
|
||||
sai = eai = NULL;
|
||||
for (addrs = hp->h_addr_list; *addrs != NULL; addrs++) {
|
||||
struct sockaddr sa;
|
||||
size_t addrlen;
|
||||
|
||||
if (hp->h_length < 1)
|
||||
continue;
|
||||
sa.sa_family = hp->h_addrtype;
|
||||
switch (hp->h_addrtype) {
|
||||
case AF_INET:
|
||||
((struct sockaddr_in *) &sa)->sin_port = htons (port);
|
||||
memcpy (&((struct sockaddr_in *) &sa)->sin_addr,
|
||||
*addrs, hp->h_length);
|
||||
addrlen = sizeof (struct sockaddr_in);
|
||||
break;
|
||||
#ifndef __OS2__
|
||||
case AF_INET6:
|
||||
#if SIN6_LEN
|
||||
((struct sockaddr_in6 *) &sa)->sin6_len = hp->h_length;
|
||||
#endif
|
||||
((struct sockaddr_in6 *) &sa)->sin6_port = htons (port);
|
||||
memcpy (&((struct sockaddr_in6 *) &sa)->sin6_addr,
|
||||
*addrs, hp->h_length);
|
||||
addrlen = sizeof (struct sockaddr_in6);
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
continue;
|
||||
}
|
||||
|
||||
result.ai_family = hp->h_addrtype;
|
||||
ai = dup_addrinfo (&result, &sa, addrlen);
|
||||
if (ai == NULL) {
|
||||
freeaddrinfo (sai);
|
||||
return EAI_MEMORY;
|
||||
}
|
||||
if (sai == NULL)
|
||||
sai = ai;
|
||||
else
|
||||
eai->ai_next = ai;
|
||||
eai = ai;
|
||||
}
|
||||
|
||||
if (sai == NULL) {
|
||||
return EAI_NODATA;
|
||||
}
|
||||
|
||||
if (hints->ai_flags & AI_CANONNAME) {
|
||||
sai->ai_canonname = malloc (strlen (hp->h_name) + 1);
|
||||
if (sai->ai_canonname == NULL) {
|
||||
freeaddrinfo (sai);
|
||||
return EAI_MEMORY;
|
||||
}
|
||||
strcpy (sai->ai_canonname, hp->h_name);
|
||||
}
|
||||
|
||||
*res = sai;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
freeaddrinfo (struct addrinfo *ai)
|
||||
{
|
||||
struct addrinfo *next;
|
||||
|
||||
while (ai != NULL) {
|
||||
next = ai->ai_next;
|
||||
if (ai->ai_canonname != NULL)
|
||||
free (ai->ai_canonname);
|
||||
if (ai->ai_addr != NULL)
|
||||
free (ai->ai_addr);
|
||||
free (ai);
|
||||
ai = next;
|
||||
}
|
||||
}
|
||||
|
||||
const char *
|
||||
gai_strerror (int ecode)
|
||||
{
|
||||
static const char *eai_descr[] = {
|
||||
"no error",
|
||||
"address family for nodename not supported", /* EAI_ADDRFAMILY */
|
||||
"temporary failure in name resolution", /* EAI_AGAIN */
|
||||
"invalid value for ai_flags", /* EAI_BADFLAGS */
|
||||
"non-recoverable failure in name resolution", /* EAI_FAIL */
|
||||
"ai_family not supported", /* EAI_FAMILY */
|
||||
"memory allocation failure", /* EAI_MEMORY */
|
||||
"no address associated with nodename", /* EAI_NODATA */
|
||||
"nodename nor servname provided, or not known", /* EAI_NONAME */
|
||||
"servname not supported for ai_socktype", /* EAI_SERVICE */
|
||||
"ai_socktype not supported", /* EAI_SOCKTYPE */
|
||||
"system error returned in errno", /* EAI_SYSTEM */
|
||||
"argument buffer overflow", /* EAI_OVERFLOW */
|
||||
};
|
||||
|
||||
if (ecode < 0 || ecode > (int) (sizeof eai_descr/ sizeof eai_descr[0]))
|
||||
return "unknown error";
|
||||
return eai_descr[ecode];
|
||||
}
|
||||
|
||||
#endif /* HAVE_GETADDRINFO */
|
101
src/3rdparty/os2/getaddrinfo.h
vendored
Normal file
101
src/3rdparty/os2/getaddrinfo.h
vendored
Normal file
@@ -0,0 +1,101 @@
|
||||
#ifndef _getaddrinfo_h
|
||||
#define _getaddrinfo_h
|
||||
|
||||
/*
|
||||
* Shamelessly duplicated from the fetchmail public sources
|
||||
* for use by the Squid Project under GNU Public License.
|
||||
*
|
||||
* Update/Maintenance History:
|
||||
*
|
||||
* 15-Aug-2007 : Copied from fetchmail 6.3.8
|
||||
* - added protection around libray headers
|
||||
*
|
||||
* 16-Aug-2007 : Altered configure checks
|
||||
* Un-hacked slightly to use system gethostbyname()
|
||||
*
|
||||
* Original License and code follows.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This file is part of libESMTP, a library for submission of RFC 2822
|
||||
* formatted electronic mail messages using the SMTP protocol described
|
||||
* in RFC 2821.
|
||||
*
|
||||
* Copyright (C) 2001,2002 Brian Stafford <brian@stafford.uklinux.net>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
/* Structure and prototypes taken from RFC 2553 */
|
||||
|
||||
/* SG 23/09/2007:
|
||||
On Windows the following definitions are already available, may be that
|
||||
this could be needed on some other platform */
|
||||
typedef int socklen_t;
|
||||
|
||||
struct addrinfo {
|
||||
int ai_flags; /* AI_PASSIVE, AI_CANONNAME, AI_NUMERICHOST */
|
||||
int ai_family; /* PF_xxx */
|
||||
int ai_socktype; /* SOCK_xxx */
|
||||
int ai_protocol; /* 0 or IPPROTO_xxx for IPv4 and IPv6 */
|
||||
socklen_t ai_addrlen; /* length of ai_addr */
|
||||
char *ai_canonname; /* canonical name for nodename */
|
||||
struct sockaddr *ai_addr; /* binary address */
|
||||
struct addrinfo *ai_next; /* next structure in linked list */
|
||||
};
|
||||
|
||||
/* Supposed to be defined in <netdb.h> */
|
||||
#define AI_ADDRCONFIG 0
|
||||
#define AI_PASSIVE 1 /* Socket address is intended for `bind'. */
|
||||
#define AI_CANONNAME 2 /* Request for canonical name. */
|
||||
#define AI_NUMERICHOST 4 /* Don't use name resolution. */
|
||||
|
||||
/* Supposed to be defined in <netdb.h> */
|
||||
#define EAI_ADDRFAMILY 1 /* address family for nodename not supported */
|
||||
#define EAI_AGAIN 2 /* temporary failure in name resolution */
|
||||
#define EAI_BADFLAGS 3 /* invalid value for ai_flags */
|
||||
#define EAI_FAIL 4 /* non-recoverable failure in name resolution */
|
||||
#define EAI_FAMILY 5 /* ai_family not supported */
|
||||
#define EAI_MEMORY 6 /* memory allocation failure */
|
||||
#define EAI_NODATA 7 /* no address associated with nodename */
|
||||
#define EAI_NONAME 8 /* nodename nor servname provided, or not known */
|
||||
#define EAI_SERVICE 9 /* servname not supported for ai_socktype */
|
||||
#define EAI_SOCKTYPE 10 /* ai_socktype not supported */
|
||||
|
||||
#ifndef EAI_SYSTEM
|
||||
/* Not defined on mingw32. */
|
||||
#define EAI_SYSTEM 11 /* System error returned in `errno'. */
|
||||
#endif
|
||||
#ifndef EAI_OVERFLOW
|
||||
/* Not defined on mingw32. */
|
||||
#define EAI_OVERFLOW 12 /* Argument buffer overflow. */
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
/* RFC 2553 / Posix resolver */
|
||||
int getaddrinfo (const char *nodename, const char *servname,
|
||||
const struct addrinfo *hints, struct addrinfo **res);
|
||||
/* Free addrinfo structure and associated storage */
|
||||
void freeaddrinfo (struct addrinfo *ai);
|
||||
|
||||
/* Convert error return from getaddrinfo() to string */
|
||||
const char *gai_strerror (int code);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _getaddrinfo_h */
|
367
src/3rdparty/os2/getnameinfo.c
vendored
Normal file
367
src/3rdparty/os2/getnameinfo.c
vendored
Normal file
@@ -0,0 +1,367 @@
|
||||
/*
|
||||
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the project nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Issues to be discussed:
|
||||
* - RFC2553 says that we should raise error on short buffer. X/Open says
|
||||
* we need to truncate the result. We obey RFC2553 (and X/Open should be
|
||||
* modified). ipngwg rough consensus seems to follow RFC2553. RFC3493 says
|
||||
* nothing about it, but defines a new error code EAI_OVERFLOW which seems
|
||||
* to be intended the code for this case.
|
||||
* - What is "local" in NI_NOFQDN? (see comments in the code)
|
||||
* - NI_NAMEREQD and NI_NUMERICHOST conflict with each other.
|
||||
* - (KAME extension) always attach textual scopeid (fe80::1%lo0), if
|
||||
* sin6_scope_id is filled - standardization status?
|
||||
* - what should we do if we should do getservbyport("sctp")?
|
||||
*/
|
||||
|
||||
/*
|
||||
* Considerations about thread-safeness
|
||||
* The code in this file is thread-safe, and so the thread-safeness of
|
||||
* getnameinfo() depends on the property of backend functions.
|
||||
* - getservbyport() is not thread safe for most systems we are targeting.
|
||||
* - getipnodebyaddr() is thread safe. However, many resolver libraries
|
||||
* used in the function are not thread safe.
|
||||
* - gethostbyaddr() is usually not thread safe.
|
||||
*/
|
||||
|
||||
#if !HAVE_GETNAMEINFO
|
||||
|
||||
#include <sys/socket.h>
|
||||
#include <net/if.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <arpa/nameser.h>
|
||||
#include <netdb.h>
|
||||
#include <resolv.h>
|
||||
#include <string.h>
|
||||
#include <stddef.h>
|
||||
#include <errno.h>
|
||||
#include <inttypes.h>
|
||||
#include "getaddrinfo.h"
|
||||
#include "getnameinfo.h"
|
||||
|
||||
static const struct afd {
|
||||
int a_af;
|
||||
int a_addrlen;
|
||||
int a_socklen;
|
||||
int a_off;
|
||||
int a_portoff;
|
||||
} afdl [] = {
|
||||
#if INET6
|
||||
{PF_INET6, sizeof(struct in6_addr), sizeof(struct sockaddr_in6),
|
||||
offsetof(struct sockaddr_in6, sin6_addr),
|
||||
offsetof(struct sockaddr_in6, sin6_port)},
|
||||
#endif
|
||||
{PF_INET, sizeof(struct in_addr), sizeof(struct sockaddr_in),
|
||||
offsetof(struct sockaddr_in, sin_addr),
|
||||
offsetof(struct sockaddr_in, sin_port)},
|
||||
{0, 0, 0, 0, 0},
|
||||
};
|
||||
|
||||
#if INET6
|
||||
static int ip6_parsenumeric __P((const struct sockaddr *, const char *, char *,
|
||||
size_t, int));
|
||||
static int ip6_sa2str __P((const struct sockaddr_in6 *, char *, size_t, int));
|
||||
#endif
|
||||
|
||||
int
|
||||
getnameinfo(sa, salen, host, hostlen, serv, servlen, flags)
|
||||
const struct sockaddr *sa;
|
||||
socklen_t salen;
|
||||
char *host;
|
||||
size_t hostlen;
|
||||
char *serv;
|
||||
size_t servlen;
|
||||
int flags;
|
||||
{
|
||||
const struct afd *afd;
|
||||
struct servent *sp;
|
||||
struct hostent *hp;
|
||||
unsigned short port;
|
||||
int family, i;
|
||||
const char *addr;
|
||||
uint32_t v4a;
|
||||
char numserv[512];
|
||||
|
||||
if (sa == NULL)
|
||||
return EAI_FAIL;
|
||||
|
||||
#if HAVE_SA_LEN /*XXX*/
|
||||
if (sa->sa_len != salen)
|
||||
return EAI_FAIL;
|
||||
#endif
|
||||
|
||||
family = sa->sa_family;
|
||||
for (i = 0; afdl[i].a_af; i++)
|
||||
if (afdl[i].a_af == family) {
|
||||
afd = &afdl[i];
|
||||
goto found;
|
||||
}
|
||||
return EAI_FAMILY;
|
||||
|
||||
found:
|
||||
if (salen != afd->a_socklen)
|
||||
return EAI_FAIL;
|
||||
|
||||
/* network byte order */
|
||||
memcpy(&port, (const char *)sa + afd->a_portoff, sizeof(port));
|
||||
addr = (const char *)sa + afd->a_off;
|
||||
|
||||
if (serv == NULL || servlen == 0) {
|
||||
/*
|
||||
* do nothing in this case.
|
||||
* in case you are wondering if "&&" is more correct than
|
||||
* "||" here: RFC3493 says that serv == NULL OR servlen == 0
|
||||
* means that the caller does not want the result.
|
||||
*/
|
||||
} else {
|
||||
if (flags & NI_NUMERICSERV)
|
||||
sp = NULL;
|
||||
else {
|
||||
sp = getservbyport(port,
|
||||
(flags & NI_DGRAM) ? "udp" : "tcp");
|
||||
}
|
||||
if (sp) {
|
||||
if (strlen(sp->s_name) + 1 > servlen)
|
||||
return EAI_OVERFLOW;
|
||||
strncpy(serv, sp->s_name, servlen);
|
||||
} else {
|
||||
snprintf(numserv, sizeof(numserv), "%u", ntohs(port));
|
||||
if (strlen(numserv) + 1 > servlen)
|
||||
return EAI_OVERFLOW;
|
||||
strncpy(serv, numserv, servlen);
|
||||
}
|
||||
}
|
||||
|
||||
switch (sa->sa_family) {
|
||||
case AF_INET:
|
||||
v4a = (uint32_t)
|
||||
ntohl(((const struct sockaddr_in *)sa)->sin_addr.s_addr);
|
||||
if (IN_MULTICAST(v4a) || IN_EXPERIMENTAL(v4a))
|
||||
flags |= NI_NUMERICHOST;
|
||||
v4a >>= IN_CLASSA_NSHIFT;
|
||||
if (v4a == 0)
|
||||
flags |= NI_NUMERICHOST;
|
||||
break;
|
||||
#if INET6
|
||||
case AF_INET6: {
|
||||
const struct sockaddr_in6 *sin6;
|
||||
sin6 = (const struct sockaddr_in6 *)sa;
|
||||
switch (sin6->sin6_addr.s6_addr[0]) {
|
||||
case 0x00:
|
||||
if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr))
|
||||
;
|
||||
else if (IN6_IS_ADDR_LOOPBACK(&sin6->sin6_addr))
|
||||
;
|
||||
else
|
||||
flags |= NI_NUMERICHOST;
|
||||
break;
|
||||
default:
|
||||
if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr))
|
||||
flags |= NI_NUMERICHOST;
|
||||
else if (IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr))
|
||||
flags |= NI_NUMERICHOST;
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
if (host == NULL || hostlen == 0) {
|
||||
/*
|
||||
* do nothing in this case.
|
||||
* in case you are wondering if "&&" is more correct than
|
||||
* "||" here: RFC3493 says that host == NULL or hostlen == 0
|
||||
* means that the caller does not want the result.
|
||||
*/
|
||||
} else if (flags & NI_NUMERICHOST) {
|
||||
/* NUMERICHOST and NAMEREQD conflicts with each other */
|
||||
if (flags & NI_NAMEREQD)
|
||||
return EAI_NONAME;
|
||||
|
||||
goto numeric;
|
||||
} else {
|
||||
#if USE_GETIPNODEBY
|
||||
int h_error = 0;
|
||||
hp = getipnodebyaddr(addr, afd->a_addrlen, afd->a_af, &h_error);
|
||||
#else
|
||||
hp = gethostbyaddr(addr, afd->a_addrlen, afd->a_af);
|
||||
#if 0 // getnameinfo.c:161:9: error: variable 'h_error' set but not used
|
||||
#if HAVE_H_ERRNO
|
||||
h_error = h_errno;
|
||||
#else
|
||||
h_error = EINVAL;
|
||||
#endif
|
||||
#endif /* 0 */
|
||||
#endif
|
||||
|
||||
if (hp) {
|
||||
#if 0
|
||||
if (flags & NI_NOFQDN) {
|
||||
/*
|
||||
* According to RFC3493 section 6.2, NI_NOFQDN
|
||||
* means "node name portion of the FQDN shall
|
||||
* be returned for local hosts." The following
|
||||
* code tries to implement it by returning the
|
||||
* first label (the part before the first
|
||||
* period) of the FQDN. However, it is not
|
||||
* clear if this always makes sense, since the
|
||||
* given address may be outside of "local
|
||||
* hosts." Due to the unclear description, we
|
||||
* disable the code in this implementation.
|
||||
*/
|
||||
char *p;
|
||||
p = strchr(hp->h_name, '.');
|
||||
if (p)
|
||||
*p = '\0';
|
||||
}
|
||||
#endif
|
||||
if (strlen(hp->h_name) + 1 > hostlen) {
|
||||
#if USE_GETIPNODEBY
|
||||
freehostent(hp);
|
||||
#endif
|
||||
return EAI_OVERFLOW;
|
||||
}
|
||||
strncpy(host, hp->h_name, hostlen);
|
||||
#if USE_GETIPNODEBY
|
||||
freehostent(hp);
|
||||
#endif
|
||||
} else {
|
||||
if (flags & NI_NAMEREQD)
|
||||
return EAI_NONAME;
|
||||
|
||||
numeric:
|
||||
switch (afd->a_af) {
|
||||
#if INET6
|
||||
case AF_INET6: {
|
||||
int error;
|
||||
|
||||
if ((error = ip6_parsenumeric(sa, addr, host,
|
||||
hostlen,
|
||||
flags)) != 0)
|
||||
return(error);
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
default:
|
||||
if (inet_ntop(afd->a_af, addr, host,
|
||||
hostlen) == NULL)
|
||||
return EAI_SYSTEM;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return(0);
|
||||
}
|
||||
|
||||
#if INET6
|
||||
static int
|
||||
ip6_parsenumeric(sa, addr, host, hostlen, flags)
|
||||
const struct sockaddr *sa;
|
||||
const char *addr;
|
||||
char *host;
|
||||
size_t hostlen;
|
||||
int flags;
|
||||
{
|
||||
int numaddrlen;
|
||||
char numaddr[512];
|
||||
|
||||
if (inet_ntop(AF_INET6, addr, numaddr, sizeof(numaddr)) == NULL)
|
||||
return EAI_SYSTEM;
|
||||
|
||||
numaddrlen = strlen(numaddr);
|
||||
if (numaddrlen + 1 > hostlen) /* don't forget terminator */
|
||||
return EAI_OVERFLOW;
|
||||
strncpy(host, numaddr, hostlen);
|
||||
|
||||
if (((const struct sockaddr_in6 *)sa)->sin6_scope_id) {
|
||||
char zonebuf[SQUIDHOSTNAMELEN];
|
||||
int zonelen;
|
||||
|
||||
zonelen = ip6_sa2str(
|
||||
(const struct sockaddr_in6 *)(const void *)sa,
|
||||
zonebuf, sizeof(zonebuf), flags);
|
||||
if (zonelen < 0)
|
||||
return EAI_OVERFLOW;
|
||||
if (zonelen + 1 + numaddrlen + 1 > hostlen)
|
||||
return EAI_OVERFLOW;
|
||||
|
||||
/* construct <numeric-addr><delim><zoneid> */
|
||||
memcpy(host + numaddrlen + 1, zonebuf,
|
||||
(size_t)zonelen);
|
||||
host[numaddrlen] = SCOPE_DELIMITER;
|
||||
host[numaddrlen + 1 + zonelen] = '\0';
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* ARGSUSED */
|
||||
static int
|
||||
ip6_sa2str(sa6, buf, bufsiz, flags)
|
||||
const struct sockaddr_in6 *sa6;
|
||||
char *buf;
|
||||
size_t bufsiz;
|
||||
int flags;
|
||||
{
|
||||
unsigned int ifindex;
|
||||
const struct in6_addr *a6;
|
||||
int n;
|
||||
|
||||
ifindex = (unsigned int)sa6->sin6_scope_id;
|
||||
a6 = &sa6->sin6_addr;
|
||||
|
||||
#if NI_NUMERICSCOPE
|
||||
if ((flags & NI_NUMERICSCOPE) != 0) {
|
||||
n = snprintf(buf, bufsiz, "%u", sa6->sin6_scope_id);
|
||||
if (n < 0 || n >= bufsiz)
|
||||
return -1;
|
||||
else
|
||||
return n;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* if_indextoname() does not take buffer size. not a good api... */
|
||||
if ((IN6_IS_ADDR_LINKLOCAL(a6) || IN6_IS_ADDR_MC_LINKLOCAL(a6) ||
|
||||
IN6_IS_ADDR_MC_NODELOCAL(a6)) && bufsiz >= IF_NAMESIZE) {
|
||||
char *p = if_indextoname(ifindex, buf);
|
||||
if (p)
|
||||
return (strlen(p));
|
||||
}
|
||||
|
||||
/* last resort */
|
||||
n = snprintf(buf, bufsiz, "%u", sa6->sin6_scope_id);
|
||||
if (n < 0 || n >= bufsiz)
|
||||
return -1;
|
||||
else
|
||||
return n;
|
||||
}
|
||||
#endif /* INET6 */
|
||||
#endif
|
29
src/3rdparty/os2/getnameinfo.h
vendored
Normal file
29
src/3rdparty/os2/getnameinfo.h
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
#ifndef _getnameinfo_h
|
||||
#define _getnameinfo_h
|
||||
/*
|
||||
* Reconstructed from KAME getnameinfo.c (in lib/)
|
||||
*/
|
||||
|
||||
/* getnameinfo flags */
|
||||
#define NI_NOFQDN 0x0001
|
||||
#define NI_NUMERICHOST 0x0002 /* return numeric form of address */
|
||||
#define NI_NAMEREQD 0x0004 /* request DNS name */
|
||||
#define NI_NUMERICSERV 0x0008
|
||||
#define NI_DGRAM 0x0010
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
/* RFC 2553 / Posix resolver */
|
||||
int getnameinfo(const struct sockaddr *sa,
|
||||
socklen_t salen,
|
||||
char *host,
|
||||
size_t hostlen,
|
||||
char *serv,
|
||||
size_t servlen,
|
||||
int flags );
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _getnameinfo_h */
|
41
src/3rdparty/squirrel/COMPILE
vendored
41
src/3rdparty/squirrel/COMPILE
vendored
@@ -1,41 +0,0 @@
|
||||
Squirrel 2.2.4 stable
|
||||
--------------------------------------------------------
|
||||
What is in this distribution?
|
||||
|
||||
squirrel
|
||||
static library implementing the compiler and interpreter of the language
|
||||
|
||||
sqstdlib
|
||||
the standard utility libraries
|
||||
|
||||
sq
|
||||
stand alone interpreter
|
||||
|
||||
doc
|
||||
The manual
|
||||
|
||||
etc
|
||||
a minimalistic embedding sample
|
||||
|
||||
samples
|
||||
samples programs
|
||||
|
||||
|
||||
HOW TO COMPILE
|
||||
---------------------------------------------------------
|
||||
GCC USERS
|
||||
.........................................................
|
||||
There is a very simple makefile that compiles all libraries and exes
|
||||
from the root of the project run 'make'
|
||||
|
||||
for 32 bits systems
|
||||
|
||||
$ make
|
||||
|
||||
for 64 bits systems
|
||||
|
||||
$ make sq64
|
||||
|
||||
VISUAL C++ USERS
|
||||
.........................................................
|
||||
Open squirrel.dsw from the root project directory and build(dho!)
|
357
src/3rdparty/squirrel/HISTORY
vendored
357
src/3rdparty/squirrel/HISTORY
vendored
@@ -1,357 +0,0 @@
|
||||
***version 2.2.5 stable***
|
||||
-sq_getsize() now returns userdatasize for classes and instances
|
||||
-added parameter 'isstatic' to _newmember metamethod(thx G.Meyer)
|
||||
-now array.sort() is implemented with heapsort
|
||||
-added SQUIRREL_VERSION_NUMBER preprocessor definition
|
||||
-now floats in scientific notation also accept numbers with no '.' (eg. 1e+6 or 1e6)
|
||||
-fixed some compiler warning
|
||||
-fixed a minor compiler bug
|
||||
-fixed some bugs when SQUSEDOUBLE is used in 32bits systems
|
||||
-fixed bug in GC
|
||||
|
||||
***2009-11-15 ***
|
||||
***version 2.2.4 stable***
|
||||
-fixed bug in functions with default parameters
|
||||
|
||||
***2009-06-30 ***
|
||||
***version 2.2.3 stable***
|
||||
-added sq_getfunctioninfo
|
||||
-added compile time flag SQUSEDOUBLE to use double precision floats
|
||||
-added global slot _floatsize_ int the base lib to recognize single precision and double precision builds
|
||||
-sq_wakeupvm can now resume the vm with an exception
|
||||
-added sqstd_format
|
||||
-generators can now be instantiated by calling sq_call() or closure.call()
|
||||
-fixed a bug in sqstd_printcallstack(thx takayuki_h)
|
||||
-fixed modulo by zero(thx jup)
|
||||
-fixed negative enums and constants
|
||||
-fixed generator crash bug if invoked as tail call (thx Mr.Accident)
|
||||
-fixed some minor bug
|
||||
|
||||
***2008-09-24 ***
|
||||
***version 2.2.2 stable***
|
||||
-fixed some behaviour inconsistencies in thread.call() and thread.wakeup() (thx Mr.Accident)
|
||||
-fixed coroutine error propagation
|
||||
-fixed lingering return value from native function (thx Tom Leonard)
|
||||
-fixed a bug if array.sort() is given a bad sort function (thx Tom Leonard)
|
||||
-fixed some minor api bug
|
||||
-added sq_arrayremove() and sq_arrayinsert()
|
||||
|
||||
***2008-05-16 ***
|
||||
***version 2.2.1 stable***
|
||||
-fixed a tailcall bug
|
||||
|
||||
***2008-02-17 ***
|
||||
***version 2.2 stable ***
|
||||
-added _newslot metamethod in classes
|
||||
-added enums added constants
|
||||
-added sq_pushconsttable, sq_setconsttable
|
||||
-added default param
|
||||
-added octal literals(thx Dinosaur)
|
||||
-fixed debug hook, 'calls' and 'returns' are properly notified in the same number.
|
||||
-fixed a coroutine bug
|
||||
|
||||
***2007-07-29 ***
|
||||
***version 2.1.2 stable***
|
||||
-new behaviour for generators iteration using foreach
|
||||
now when a generator is iterated by foreach the value returned by a 'return val' statement
|
||||
will terminate the iteration but will not be returned as foreach iteration
|
||||
-added sq_setclassudsize()
|
||||
-added sq_clear()
|
||||
-added table.clear(), array.clear()
|
||||
-fixed sq_cmp() (thx jyuill)
|
||||
-fixed minor bugs
|
||||
|
||||
***2006-08-21 ***
|
||||
***version 2.1.1 stable***
|
||||
-vm refactoring
|
||||
-optimized internal function memory layout
|
||||
-new global symbol _version_ (is the version string)
|
||||
-code size optimization for float literals(on 32bits float builts)
|
||||
-now the raw ref API(sq_addref etc...) is fully reentrant.
|
||||
-fixed a bug in sq_getdelegate() now pushes null if the object doesn't have a delegate(thx MatzeB)
|
||||
-improved C reference performances in NO_GARBAGE_COLLECTOR builds
|
||||
-sq_getlocal() now enumerates also outer values.
|
||||
-fixed regexp library for GCC users.
|
||||
|
||||
***2006-03-19 ***
|
||||
***version 2.1 stable***
|
||||
-added static class fields, new keyword static
|
||||
-added 64bits architecture support
|
||||
-added global slot _intsize_ int the base lib to recognize 32bits and 64bits builds
|
||||
-added functions with fixed environment, closure.bindenv() built-in function
|
||||
-all types except userdata and null implement the tostring() method
|
||||
-string concatenation now invokes metamethod _tostring
|
||||
-new metamethods for class objects _newmember and _inherited
|
||||
-sq_call() sq_resume() sq_wakeupvm() have a new signature
|
||||
-new C referencing implementation(scales more with the amount of references)
|
||||
-refactored hash table
|
||||
-new api functions sq_newslot(),sq_tobool(),sq_getbase(), sq_instanceof(), sq_bindenv()
|
||||
-the api func sq_createslot was deprecated but still supported in form of C macro on top of sq_newslot
|
||||
-sq_setreleasehook() now also works for classes
|
||||
-stream.readstr() and stream.writestr() have been deprecated(this affects file and blob)
|
||||
-fixed squirrel.h undeclared api calls
|
||||
-fixed few minor bugs
|
||||
-SQChar is now defined as wchar_t
|
||||
-removed warning when building with -Wall -pedantic for GCC users
|
||||
-added new std io function writeclosuretofile()
|
||||
-added new std string functions strip(),rstrip(),lstrip() and split()
|
||||
-regular expressions operators (+,*) now have more POSIX greedyness behaviour
|
||||
-class constructors are now invoked as normal functions
|
||||
|
||||
***2005-10-02 ***
|
||||
***version 2.0.5 stable***
|
||||
-fixed some 64bits incompatibilities (thx sarge)
|
||||
-fixed minor bug in the stdlib format() function (thx Rick)
|
||||
-fixed a bug in dofile() that was preventing to compile empty files
|
||||
-added new API sq_poptop() & sq_getfreevariable()
|
||||
-some performance improvements
|
||||
|
||||
***2005-08-14 ***
|
||||
***version 2.0.4 stable***
|
||||
-weak references and related API calls
|
||||
-added sq_objtobool()
|
||||
-class instances memory policies improved(1 mem allocation for the whole instance)
|
||||
-typetags are now declared as SQUserPointer instead of unsigned int
|
||||
-first pass for 64bits compatibility
|
||||
-fixed minor bug in the stdio stream
|
||||
-fixed a bug in format()
|
||||
-fixed bug in string.tointeger() and string.tofloat()
|
||||
|
||||
***2005-06-24 ***
|
||||
***version 2.0.3 stable***
|
||||
-dofile() and loadfile() in the iolib now can decode ASCII, UTF8 files UCS2 big-endian and little-endian
|
||||
-sq_setparamscheck() : now typemesk can check for null
|
||||
-added string escape sequence \xhhhh
|
||||
-fixed some C++ standard incompatibilities
|
||||
|
||||
***2005-05-15 ***
|
||||
***version 2.0.2 stable***
|
||||
-performances improvements (expecially for GCC users)
|
||||
-removed all dependencies from C++ exception handling
|
||||
-various bugfixes
|
||||
|
||||
***2005-04-12 ***
|
||||
***version 2.0.1 stable***
|
||||
-various bugfixes
|
||||
-sq_setparamscheck() now allows spaces in the typemask
|
||||
|
||||
***2005-04-03 ***
|
||||
***version 2.0 stable***
|
||||
-added API sq_gettypetag()
|
||||
-added built-in function to the bool type(tointeger, tostring etc...)
|
||||
|
||||
***2005-02-27 ***
|
||||
***version 2.0 release candidate 1(RC 1)***
|
||||
-added API sq_reseterror()
|
||||
-modified sq_release()
|
||||
-now class instances can be cloned
|
||||
-various bufixes
|
||||
|
||||
***2005-01-26 ***
|
||||
***version 2.0 beta 1***
|
||||
-added bool type
|
||||
-class properties can be redefined in a derived class
|
||||
-added ops *= /= and %=
|
||||
-new syntax for class attributes declaration </ and /> instead of ( and )
|
||||
-increased the max number of literals per function from 65535 to 16777215
|
||||
-now free variables have proper lexical scoping
|
||||
-added API sq_createinstance(), sq_pushbool(), sq_getbool()
|
||||
-added built-in function type()
|
||||
-added built-in function obj.rawin(key) in table,class and instance
|
||||
-sq_rawget() and sq_rawset() now work also on classes and instances
|
||||
-the VM no longer uses C++ exception handling (more suitable for embedded devices)
|
||||
-various bufixes
|
||||
|
||||
***2004-12-21 ***
|
||||
***version 2.0 alpha 2***
|
||||
-globals scoping changed, now if :: is omitted the VM automatically falls back on the root table
|
||||
-various bufixes
|
||||
-added class level attributes
|
||||
|
||||
***2004-12-12 ***
|
||||
***version 2.0 alpha 1***
|
||||
-codebase branch from version 1.x
|
||||
-added classes
|
||||
-added functions with variable number of parameters(vargc & vargv and the ...)
|
||||
-0 and 0.0 are now considered 'false' by all conditional statements(if,while,for,?,do-while)
|
||||
-added new api functions sq_newclass() sq_setinstanceup() sq_getinstanceup() sq_getattributes() sq_setattributes()
|
||||
-modified api sq_settypetag()
|
||||
|
||||
***2004-11-01 ***
|
||||
***version 1.0 stable***
|
||||
-fixed some minor bug
|
||||
-improoved operator 'delete' performances
|
||||
-added scientific notation for float numbers( eg. 2.e16 or 2.e-2)
|
||||
|
||||
***2004-08-30 ***
|
||||
***version 1.0 release candidate 2(RC 2)***
|
||||
-fixed bug in the vm(thx Pierre Renaux)
|
||||
-fixed bug in the optimizer(thx Pierre Renaux)
|
||||
-fixed some bug in the documentation(thx JD)
|
||||
-added new api functions for raw object handling
|
||||
-removed nested multiline comments
|
||||
-reduced memory footprint in C references
|
||||
|
||||
***2004-08-23 ***
|
||||
***version 1.0 release candidate 1(RC 1)***
|
||||
-fixed division by zero
|
||||
-the 'in' operator and obj.rawget() do not query the default delegate anymore
|
||||
-added function sq_getprintfunc()
|
||||
-added new standard library 'auxlib'(implements default error handlers)
|
||||
|
||||
***2004-07-12 ***
|
||||
***version 1.0 beta 4***
|
||||
-fixed a bug in the integer.tochar() built-in method
|
||||
-fixed unary minus operator
|
||||
-fixed bug in dofile()
|
||||
-fixed inconsistency between != and == operators(on float/integer comparison)
|
||||
-added javascript style unsigned right shift operator '>>>'
|
||||
-added array(size) constructor built-in function
|
||||
-array.resize(size,[fill]) built-in function accepts an optional 'fill' value
|
||||
-improved debug API, added sq_getclosureinfo() and sq_setnativeclosurename()
|
||||
|
||||
***2004-05-23 ***
|
||||
***version 1.0 beta 3***
|
||||
-minor vm bug fixes
|
||||
-string allocation is now faster
|
||||
-tables and array memory usage is now less conservative(they shrink)
|
||||
-added regular expression routines in the standard library
|
||||
-The 'c' expression now accepts only 1 character(thx irbrian)
|
||||
-multiline strings <[ ]> have been substituted with C# style verbatim strings (eg. @"string")
|
||||
-added new keyword 'parent' for accessing the delegate of tables and unserdata
|
||||
-The metamethod '_clone' has been renamed '_cloned'
|
||||
-the _delslot metamethod's behaviour and prototype have been changed
|
||||
-new default function in the integer and float object 'tochar()'
|
||||
-the built-in function chcode2string has been removed
|
||||
-the default method [table].getdelegate() has been removed
|
||||
-new api sq_rawdeleteslot()
|
||||
-new table built-in method rawdelete(key)
|
||||
-the dynamic mudule loading has been removed from the standard distribution
|
||||
-some optimizations in the VM
|
||||
|
||||
***2004-04-21 ***
|
||||
***version 1.0 beta 2***
|
||||
-minor compiler/parser bug fixes
|
||||
-sq_newclosure has a different prototype, the "paramscheck" of paramter has been moved to the new function sq_setparamscheck()
|
||||
-sq_setparamscheck allows to add automatic parameters type checking in native closures
|
||||
-sq_compile() lost the lineinfo parameter
|
||||
-new api sq_enabledebuginfo() globally sets compiler's debug info generation
|
||||
-added consistency check on bytecode serialization
|
||||
-fixed += operator, now works on strings like +
|
||||
-added global slot in the base lib _charsize_ to recognize unicode builds from ascii builds runtime
|
||||
-added registry table
|
||||
-new api call sq_pushregistrytable()
|
||||
-added type tag to the userdata type sq_settypetag()
|
||||
-sq_getuserdata now queries the userdata typetag
|
||||
-the built in function collect_garbage() as been renamed collectgarbage() for consistency reasons
|
||||
-new standard libraries(sqlibs are now obsolete)
|
||||
|
||||
***2004-02-20 ***
|
||||
***version 1.0 beta 1***
|
||||
-fixed a bug in the compiler (thanks Martin Kofler)
|
||||
-fixed bug in the switch case statement
|
||||
-fixed the _unm metamethod
|
||||
-fixed minor bugs in the API
|
||||
-fixed automatic stack resizing
|
||||
-first beta version
|
||||
first pass code clean up in the VM and base lib
|
||||
first pass code coverege test has been done on VM and built-in lib
|
||||
-new VM creation API sq_open() sq_close() (sq_newvm and sq_releasevm are now obsolete)
|
||||
-new api allows to specifiy a "print" function to output text(sq_printfunc)
|
||||
-added some small optimizations
|
||||
-new cooperative multi-threading capabilities in the base library(coroutines), VMs are now a built in type("thread")
|
||||
-new built in functions have been added for manipulating the new "thread" type
|
||||
-friend virtual machines share the same root table, error handler and debug hook by default
|
||||
-new compile time options
|
||||
|
||||
***2004-01-19 ***
|
||||
***version 0.9 alpha***
|
||||
-fixed a garbage collection bug
|
||||
-fixed some API bugs(thanks to Joshua Jensen)
|
||||
-fixed tail calls (in the version 0.8 the tail call optimization was erroneously disabled)
|
||||
-new function parameters semantic, now passing a wrong number of parameters generates an exception
|
||||
-native closures have now a built in parameter number checking
|
||||
-sq_rawget and sq_rawset now work also on arrays
|
||||
-sq_getsize now woks also on userdata
|
||||
-the userdata release hook prototype is changed(now passes the size of the userdata)
|
||||
-the lexer reader function now returns an integer instead of a char that allows better error checking on the input(thx Joshua Jensen)
|
||||
-faster compiler
|
||||
-try/catch blocks do not cause any runtime memory allocation anymore
|
||||
|
||||
***2003-12-06 ***
|
||||
***version 0.8 alpha***
|
||||
-fixed a bug that was preventing to have callable userdata throught the metamethod _call
|
||||
-fixed a garbage collection bug
|
||||
-fixed == operator now can compare correctly different types
|
||||
-new built in method getstackinfos(level)
|
||||
-improoved line informations precision for the debug hook
|
||||
-new api call sq_compilebuffer()
|
||||
-new built-in api function compilestring()
|
||||
-new syntactic sugar for function declarations inside tables
|
||||
-the debug API has been finalized
|
||||
|
||||
***2003-11-17 ***
|
||||
***version 0.7 alpha***
|
||||
-fixed critical bug SQInteger the tail call system
|
||||
-fixed bug in the continue statement code generation
|
||||
-fixed func call param issue(thanks to Rewoonenco Andrew)
|
||||
-added _delslot metamethod(thanks to Rewoonenco Andrew)
|
||||
-new multiline string expression ( delimited by <[ and ]> )
|
||||
-normal strings ("") do not allow embedded new line anymore
|
||||
-reduced vm memory footprint(C refs are shared between friend VMs)
|
||||
-new api method sq_deleteslot()
|
||||
-new debug hook event 'r' is triggered when a function returns
|
||||
|
||||
***2003-11-04 ***
|
||||
***version 0.6 alpha***
|
||||
-fixed switch statement(was executing the default case after a break)
|
||||
-sq_call() doesn't pop the closure (just the params)
|
||||
-the vm execution can be suspended from the C API anytime (micro-threads)
|
||||
-new api calls sq_suspendvm() sq_wakeupvm() sq_getvmstate() and sq_reservestack()
|
||||
|
||||
***2003-10-13 ***
|
||||
***version 0.5 alpha***
|
||||
-fixed some minor bug
|
||||
-tested with non ASCII identifiers in unicode mode(I've tried chinese chars)
|
||||
-added built-in function string.find()
|
||||
-the built-in function array.sort() optionally accepts a cmp(a,b) function
|
||||
-the debug hook function now has a new prototype debug_hook(event_type,sourcefile,line,functionname)
|
||||
-fixed some debug info imprecision
|
||||
|
||||
***2003-10-01 ***
|
||||
***version 0.4 alpha***
|
||||
-faster VM
|
||||
-sq_call will pop arguments and closure also in case of failure
|
||||
-fixed a bug in sq_remove
|
||||
-now the VM detects delegation cycles(and throws an exception)
|
||||
-new operators ++ and --
|
||||
-new operator ',' comma operator
|
||||
-fixed some expression precedence issue
|
||||
-fixed bug in sq_arraypop
|
||||
|
||||
***2003-09-15 ***
|
||||
***version 0.3 alpha***
|
||||
-fixed a bug in array::insert()
|
||||
-optional Unicode core(define SQUNICODE or _UNICODE on Win32)
|
||||
-sq_compiler uses a new reader function SQLEXREADFUNC
|
||||
-the debug hook passes 'l' instead of 'line' for line callbacks
|
||||
and 'c' instead of 'call' for call callbacks
|
||||
-new array.extend() bulit-in function
|
||||
-new API sq_clone()
|
||||
|
||||
***2003-09-10 ***
|
||||
***version 0.2 pre-alpha***
|
||||
-new completely reentrant VM (sq_open and sq_close are now obsolete)
|
||||
-sq_newvm() has a new prototype
|
||||
-allocators are now global and linked in the VM
|
||||
-_newslot meta method added
|
||||
-rawset creates a slot if doesn't exists
|
||||
-the compiler error callback pass the vm handle(thanks Pierre Renaux)
|
||||
-sq_setforeignptr() sq_getforeingptr() are now public
|
||||
-sq_resume() now is possible to resume generators from C
|
||||
-sq_getlasterror() retrieve the last thrown error
|
||||
-improved docs
|
||||
|
||||
***2003-09-06 ***
|
||||
***version 0.1 pre-alpha***
|
||||
first release
|
23
src/3rdparty/squirrel/Makefile
vendored
23
src/3rdparty/squirrel/Makefile
vendored
@@ -1,23 +0,0 @@
|
||||
|
||||
SQUIRREL=.
|
||||
MAKE=make
|
||||
|
||||
sq32:
|
||||
cd squirrel; $(MAKE)
|
||||
cd sqstdlib; $(MAKE)
|
||||
cd sq; $(MAKE)
|
||||
|
||||
sqprof:
|
||||
cd squirrel; $(MAKE) sqprof
|
||||
cd sqstdlib; $(MAKE) sqprof
|
||||
cd sq; $(MAKE) sqprof
|
||||
|
||||
sq64:
|
||||
cd squirrel; $(MAKE) sq64
|
||||
cd sqstdlib; $(MAKE) sq64
|
||||
cd sq; $(MAKE) sq64
|
||||
|
||||
clean:
|
||||
$(MAKE) -C squirrel clean
|
||||
$(MAKE) -C sqstdlib clean
|
||||
$(MAKE) -C sq clean
|
22
src/3rdparty/squirrel/README
vendored
22
src/3rdparty/squirrel/README
vendored
@@ -1,22 +0,0 @@
|
||||
The programming language SQUIRREL 2.2.5 stable
|
||||
|
||||
--------------------------------------------------
|
||||
The project has been compiled and run on Windows(Windows XP/2000 on Intel x86 Windows XP Pro on AMD x64) and
|
||||
Linux(Slackware 9.0 on Intel x86, Fedora Core 4 on AMD x64).
|
||||
|
||||
Has been tested with the following compilers:
|
||||
MS Visual C++ 6.0,7.0,7.1 and 8.0 (32 and 64bits)
|
||||
MinGW gcc 3.2 (mingw special 20020817-1)
|
||||
Cygnus gcc 3.2
|
||||
Linux gcc 3.2.3
|
||||
Linux gcc 4.0.0 (x86 64bits)
|
||||
|
||||
|
||||
Feedback and suggestions are appreciated
|
||||
project page - http://www.squirrel-lang.org
|
||||
community forums - http://www.squirrel-lang.org/Forums
|
||||
wiki - http://wiki.squirrel-lang.org
|
||||
author - alberto@demichelis.net
|
||||
|
||||
END OF README
|
||||
|
BIN
src/3rdparty/squirrel/doc/sqstdlib2.chm
vendored
BIN
src/3rdparty/squirrel/doc/sqstdlib2.chm
vendored
Binary file not shown.
1714
src/3rdparty/squirrel/doc/sqstdlib2.pdf
vendored
1714
src/3rdparty/squirrel/doc/sqstdlib2.pdf
vendored
File diff suppressed because it is too large
Load Diff
BIN
src/3rdparty/squirrel/doc/squirrel2.chm
vendored
BIN
src/3rdparty/squirrel/doc/squirrel2.chm
vendored
Binary file not shown.
6426
src/3rdparty/squirrel/doc/squirrel2.pdf
vendored
6426
src/3rdparty/squirrel/doc/squirrel2.pdf
vendored
File diff suppressed because it is too large
Load Diff
63
src/3rdparty/squirrel/etc/minimal.c
vendored
63
src/3rdparty/squirrel/etc/minimal.c
vendored
@@ -1,63 +0,0 @@
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <squirrel.h>
|
||||
#include <sqstdio.h>
|
||||
#include <sqstdaux.h>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma comment (lib ,"squirrel.lib")
|
||||
#pragma comment (lib ,"sqstdlib.lib")
|
||||
#endif
|
||||
|
||||
#ifdef SQUNICODE
|
||||
#define scvprintf vwprintf
|
||||
#else
|
||||
#define scvprintf vprintf
|
||||
#endif
|
||||
|
||||
void printfunc(HSQUIRRELVM v, const SQChar *s, ...)
|
||||
{
|
||||
va_list arglist;
|
||||
va_start(arglist, s);
|
||||
scvprintf(s, arglist);
|
||||
va_end(arglist);
|
||||
}
|
||||
|
||||
void call_foo(HSQUIRRELVM v, int n,float f,const SQChar *s)
|
||||
{
|
||||
SQInteger top = sq_gettop(v); //saves the stack size before the call
|
||||
sq_pushroottable(v); //pushes the global table
|
||||
sq_pushstring(v,_SC("foo"),-1);
|
||||
if(SQ_SUCCEEDED(sq_get(v,-2))) { //gets the field 'foo' from the global table
|
||||
sq_pushroottable(v); //push the 'this' (in this case is the global table)
|
||||
sq_pushinteger(v,n);
|
||||
sq_pushfloat(v,f);
|
||||
sq_pushstring(v,s,-1);
|
||||
sq_call(v,4,SQFalse,SQTrue); //calls the function
|
||||
}
|
||||
sq_settop(v,top); //restores the original stack size
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
HSQUIRRELVM v;
|
||||
v = sq_open(1024); // creates a VM with initial stack size 1024
|
||||
|
||||
//sq_pushroottable(v); //push the root table were to register the lib function
|
||||
//sqstd_register_iolib(v);
|
||||
sqstd_seterrorhandlers(v); //registers the default error handlers
|
||||
|
||||
sq_setprintfunc(v, printfunc); //sets the print function
|
||||
|
||||
sq_pushroottable(v); //push the root table(were the globals of the script will be stored)
|
||||
if(SQ_SUCCEEDED(sqstd_dofile(v, _SC("test.nut"), SQFalse, SQTrue))) // also prints syntax errors if any
|
||||
{
|
||||
call_foo(v,1,2.5,_SC("teststring"));
|
||||
}
|
||||
|
||||
sq_pop(v,1); //pops the root table
|
||||
sq_close(v);
|
||||
|
||||
return 0;
|
||||
}
|
4
src/3rdparty/squirrel/etc/test.nut
vendored
4
src/3rdparty/squirrel/etc/test.nut
vendored
@@ -1,4 +0,0 @@
|
||||
function foo(i, f, s)
|
||||
{
|
||||
print("Called foo(), i="+i+", f="+f+", s='"+s+"'\n");
|
||||
}
|
12
src/3rdparty/squirrel/include/sqstdaux.h
vendored
12
src/3rdparty/squirrel/include/sqstdaux.h
vendored
@@ -2,15 +2,7 @@
|
||||
#ifndef _SQSTD_AUXLIB_H_
|
||||
#define _SQSTD_AUXLIB_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
SQUIRREL_API void sqstd_seterrorhandlers(HSQUIRRELVM v);
|
||||
SQUIRREL_API void sqstd_printcallstack(HSQUIRRELVM v);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /*extern "C"*/
|
||||
#endif
|
||||
void sqstd_seterrorhandlers(HSQUIRRELVM v);
|
||||
void sqstd_printcallstack(HSQUIRRELVM v);
|
||||
|
||||
#endif /* _SQSTD_AUXLIB_H_ */
|
||||
|
20
src/3rdparty/squirrel/include/sqstdblob.h
vendored
20
src/3rdparty/squirrel/include/sqstdblob.h
vendored
@@ -1,20 +0,0 @@
|
||||
/* see copyright notice in squirrel.h */
|
||||
#ifndef _SQSTDBLOB_H_
|
||||
#define _SQSTDBLOB_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
SQUIRREL_API SQUserPointer sqstd_createblob(HSQUIRRELVM v, SQInteger size);
|
||||
SQUIRREL_API SQRESULT sqstd_getblob(HSQUIRRELVM v,SQInteger idx,SQUserPointer *ptr);
|
||||
SQUIRREL_API SQInteger sqstd_getblobsize(HSQUIRRELVM v,SQInteger idx);
|
||||
|
||||
SQUIRREL_API SQRESULT sqstd_register_bloblib(HSQUIRRELVM v);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /*extern "C"*/
|
||||
#endif
|
||||
|
||||
#endif /*_SQSTDBLOB_H_*/
|
||||
|
54
src/3rdparty/squirrel/include/sqstdio.h
vendored
54
src/3rdparty/squirrel/include/sqstdio.h
vendored
@@ -1,54 +0,0 @@
|
||||
/* see copyright notice in squirrel.h */
|
||||
#ifndef _SQSTDIO_H_
|
||||
#define _SQSTDIO_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
#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;
|
||||
virtual SQInteger Tell() = 0;
|
||||
virtual SQInteger Len() = 0;
|
||||
virtual SQInteger Seek(SQInteger offset, SQInteger origin) = 0;
|
||||
virtual bool IsValid() = 0;
|
||||
virtual bool EOS() = 0;
|
||||
};
|
||||
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define SQ_SEEK_CUR 0
|
||||
#define SQ_SEEK_END 1
|
||||
#define SQ_SEEK_SET 2
|
||||
|
||||
typedef void* SQFILE;
|
||||
|
||||
SQUIRREL_API SQFILE sqstd_fopen(const SQChar *,const SQChar *);
|
||||
SQUIRREL_API SQInteger sqstd_fread(SQUserPointer, SQInteger, SQInteger, SQFILE);
|
||||
SQUIRREL_API SQInteger sqstd_fwrite(const SQUserPointer, SQInteger, SQInteger, SQFILE);
|
||||
SQUIRREL_API SQInteger sqstd_fseek(SQFILE , SQInteger , SQInteger);
|
||||
SQUIRREL_API SQInteger sqstd_ftell(SQFILE);
|
||||
SQUIRREL_API SQInteger sqstd_fflush(SQFILE);
|
||||
SQUIRREL_API SQInteger sqstd_fclose(SQFILE);
|
||||
SQUIRREL_API SQInteger sqstd_feof(SQFILE);
|
||||
|
||||
SQUIRREL_API SQRESULT sqstd_createfile(HSQUIRRELVM v, SQFILE file,SQBool own);
|
||||
SQUIRREL_API SQRESULT sqstd_getfile(HSQUIRRELVM v, SQInteger idx, SQFILE *file);
|
||||
|
||||
//compiler helpers
|
||||
SQUIRREL_API SQRESULT sqstd_loadfile(HSQUIRRELVM v,const SQChar *filename,SQBool printerror);
|
||||
SQUIRREL_API SQRESULT sqstd_dofile(HSQUIRRELVM v,const SQChar *filename,SQBool retval,SQBool printerror);
|
||||
SQUIRREL_API SQRESULT sqstd_writeclosuretofile(HSQUIRRELVM v,const SQChar *filename);
|
||||
|
||||
SQUIRREL_API SQRESULT sqstd_register_iolib(HSQUIRRELVM v);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /*extern "C"*/
|
||||
#endif
|
||||
|
||||
#endif /*_SQSTDIO_H_*/
|
||||
|
10
src/3rdparty/squirrel/include/sqstdmath.h
vendored
10
src/3rdparty/squirrel/include/sqstdmath.h
vendored
@@ -2,14 +2,6 @@
|
||||
#ifndef _SQSTD_MATH_H_
|
||||
#define _SQSTD_MATH_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
SQUIRREL_API SQRESULT sqstd_register_mathlib(HSQUIRRELVM v);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /*extern "C"*/
|
||||
#endif
|
||||
SQRESULT sqstd_register_mathlib(HSQUIRRELVM v);
|
||||
|
||||
#endif /*_SQSTD_MATH_H_*/
|
||||
|
26
src/3rdparty/squirrel/include/sqstdstring.h
vendored
26
src/3rdparty/squirrel/include/sqstdstring.h
vendored
@@ -2,10 +2,6 @@
|
||||
#ifndef _SQSTD_STRING_H_
|
||||
#define _SQSTD_STRING_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef unsigned int SQRexBool;
|
||||
typedef struct SQRex SQRex;
|
||||
|
||||
@@ -14,20 +10,16 @@ typedef struct {
|
||||
SQInteger len;
|
||||
} SQRexMatch;
|
||||
|
||||
SQUIRREL_API SQRex *sqstd_rex_compile(const SQChar *pattern,const SQChar **error);
|
||||
SQUIRREL_API void sqstd_rex_free(SQRex *exp);
|
||||
SQUIRREL_API SQBool sqstd_rex_match(SQRex* exp,const SQChar* text);
|
||||
SQUIRREL_API SQBool sqstd_rex_search(SQRex* exp,const SQChar* text, const SQChar** out_begin, const SQChar** out_end);
|
||||
SQUIRREL_API SQBool sqstd_rex_searchrange(SQRex* exp,const SQChar* text_begin,const SQChar* text_end,const SQChar** out_begin, const SQChar** out_end);
|
||||
SQUIRREL_API SQInteger sqstd_rex_getsubexpcount(SQRex* exp);
|
||||
SQUIRREL_API SQBool sqstd_rex_getsubexp(SQRex* exp, SQInteger n, SQRexMatch *subexp);
|
||||
SQRex *sqstd_rex_compile(const SQChar *pattern,const SQChar **error);
|
||||
void sqstd_rex_free(SQRex *exp);
|
||||
SQBool sqstd_rex_match(SQRex* exp,const SQChar* text);
|
||||
SQBool sqstd_rex_search(SQRex* exp,const SQChar* text, const SQChar** out_begin, const SQChar** out_end);
|
||||
SQBool sqstd_rex_searchrange(SQRex* exp,const SQChar* text_begin,const SQChar* text_end,const SQChar** out_begin, const SQChar** out_end);
|
||||
SQInteger sqstd_rex_getsubexpcount(SQRex* exp);
|
||||
SQBool sqstd_rex_getsubexp(SQRex* exp, SQInteger n, SQRexMatch *subexp);
|
||||
|
||||
SQUIRREL_API SQRESULT sqstd_format(HSQUIRRELVM v,SQInteger nformatstringidx,SQInteger *outlen,SQChar **output);
|
||||
SQRESULT sqstd_format(HSQUIRRELVM v,SQInteger nformatstringidx,SQInteger *outlen,SQChar **output);
|
||||
|
||||
SQUIRREL_API SQRESULT sqstd_register_stringlib(HSQUIRRELVM v);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /*extern "C"*/
|
||||
#endif
|
||||
SQRESULT sqstd_register_stringlib(HSQUIRRELVM v);
|
||||
|
||||
#endif /*_SQSTD_STRING_H_*/
|
||||
|
15
src/3rdparty/squirrel/include/sqstdsystem.h
vendored
15
src/3rdparty/squirrel/include/sqstdsystem.h
vendored
@@ -1,15 +0,0 @@
|
||||
/* see copyright notice in squirrel.h */
|
||||
#ifndef _SQSTD_SYSTEMLIB_H_
|
||||
#define _SQSTD_SYSTEMLIB_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
SQUIRREL_API SQInteger sqstd_register_systemlib(HSQUIRRELVM v);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /*extern "C"*/
|
||||
#endif
|
||||
|
||||
#endif /* _SQSTD_SYSTEMLIB_H_ */
|
427
src/3rdparty/squirrel/include/squirrel.h
vendored
427
src/3rdparty/squirrel/include/squirrel.h
vendored
@@ -1,81 +1,41 @@
|
||||
/*
|
||||
Copyright (c) 2003-2011 Alberto Demichelis
|
||||
|
||||
This software is provided 'as-is', without any
|
||||
express or implied warranty. In no event will the
|
||||
authors be held liable for any damages arising from
|
||||
the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software
|
||||
for any purpose, including commercial applications,
|
||||
and to alter it and redistribute it freely, subject
|
||||
to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be
|
||||
misrepresented; you must not claim that
|
||||
you wrote the original software. If you
|
||||
use this software in a product, an
|
||||
acknowledgment in the product
|
||||
documentation would be appreciated but is
|
||||
not required.
|
||||
|
||||
2. Altered source versions must be plainly
|
||||
marked as such, and must not be
|
||||
misrepresented as being the original
|
||||
software.
|
||||
|
||||
3. This notice may not be removed or
|
||||
altered from any source distribution.
|
||||
|
||||
*/
|
||||
* Copyright (c) 2003-2011 Alberto Demichelis
|
||||
*
|
||||
* This software is provided 'as-is', without any
|
||||
* express or implied warranty. In no event will the
|
||||
* authors be held liable for any damages arising from
|
||||
* the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software
|
||||
* for any purpose, including commercial applications,
|
||||
* and to alter it and redistribute it freely, subject
|
||||
* to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be
|
||||
* misrepresented; you must not claim that
|
||||
* you wrote the original software. If you
|
||||
* use this software in a product, an
|
||||
* acknowledgment in the product
|
||||
* documentation would be appreciated but is
|
||||
* not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly
|
||||
* marked as such, and must not be
|
||||
* misrepresented as being the original
|
||||
* software.
|
||||
*
|
||||
* 3. This notice may not be removed or
|
||||
* altered from any source distribution.
|
||||
*/
|
||||
#ifndef _SQUIRREL_H_
|
||||
#define _SQUIRREL_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#include "../../../string_type.h"
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
# define inline __forceinline
|
||||
#endif /* _MSC_VER */
|
||||
|
||||
#if defined(_MSC_VER) && _MSC_VER >= 1400 // MSVC 2005 safety checks
|
||||
# pragma warning(disable: 4996) // '_wfopen' was declared deprecated
|
||||
# define _CRT_SECURE_NO_DEPRECATE // all deprecated 'unsafe string functions
|
||||
# define _CRT_NON_CONFORMING_SWPRINTFS // another deprecated stuff
|
||||
#endif /* _MSC_VER >= 1400 */
|
||||
|
||||
#ifndef SQUIRREL_API
|
||||
#define SQUIRREL_API extern
|
||||
#endif
|
||||
|
||||
#if (defined(_WIN64) || defined(_LP64))
|
||||
#ifndef _SQ64
|
||||
#define _SQ64
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef _SQ64
|
||||
#ifdef _MSC_VER
|
||||
typedef __int64 SQInteger;
|
||||
typedef unsigned __int64 SQUnsignedInteger;
|
||||
typedef unsigned __int64 SQHash; /*should be the same size of a pointer*/
|
||||
#elif defined(_WIN32)
|
||||
typedef long long SQInteger;
|
||||
typedef unsigned long long SQUnsignedInteger;
|
||||
typedef unsigned long long SQHash; /*should be the same size of a pointer*/
|
||||
#else
|
||||
typedef long SQInteger;
|
||||
typedef unsigned long SQUnsignedInteger;
|
||||
typedef unsigned long SQHash; /*should be the same size of a pointer*/
|
||||
#endif
|
||||
typedef int SQInt32;
|
||||
#else
|
||||
typedef int SQInteger;
|
||||
typedef int SQInt32; /*must be 32 bits(also on 64bits processors)*/
|
||||
typedef unsigned int SQUnsignedInteger;
|
||||
typedef unsigned int SQHash; /*should be the same size of a pointer*/
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef SQUSEDOUBLE
|
||||
@@ -84,17 +44,8 @@ typedef double SQFloat;
|
||||
typedef float SQFloat;
|
||||
#endif
|
||||
|
||||
#if defined(SQUSEDOUBLE) && !defined(_SQ64) || !defined(SQUSEDOUBLE) && defined(_SQ64)
|
||||
#ifdef _MSC_VER
|
||||
typedef __int64 SQRawObjectVal; //must be 64bits
|
||||
#else
|
||||
typedef long long SQRawObjectVal; //must be 64bits
|
||||
#endif
|
||||
#define SQ_OBJECT_RAWINIT() { _unVal.raw = 0; }
|
||||
#else
|
||||
typedef SQUnsignedInteger SQRawObjectVal; //is 32 bits on 32 bits builds and 64 bits otherwise
|
||||
#define SQ_OBJECT_RAWINIT()
|
||||
#endif
|
||||
|
||||
typedef void* SQUserPointer;
|
||||
typedef SQUnsignedInteger SQBool;
|
||||
@@ -117,78 +68,12 @@ struct SQClass;
|
||||
struct SQInstance;
|
||||
struct SQDelegable;
|
||||
|
||||
#ifdef _UNICODE
|
||||
#define SQUNICODE
|
||||
#endif
|
||||
|
||||
#ifdef SQUNICODE
|
||||
#if (defined(_MSC_VER) && _MSC_VER >= 1400) // 1400 = VS8
|
||||
|
||||
#ifndef _WCHAR_T_DEFINED //this is if the compiler considers wchar_t as native type
|
||||
typedef unsigned short wchar_t;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
typedef wchar_t SQChar;
|
||||
#define _SC(a) L##a
|
||||
#define scstrcmp wcscmp
|
||||
#define scsprintf swprintf
|
||||
#define scsnprintf _snwprintf
|
||||
#define scstrlen wcslen
|
||||
#define scstrtod wcstod
|
||||
#define scstrtol wcstol
|
||||
#define scatoi _wtoi
|
||||
#define scstrtoul wcstoul
|
||||
#define scvsprintf vswprintf
|
||||
#define scstrstr wcsstr
|
||||
#define scisspace iswspace
|
||||
#define scisdigit iswdigit
|
||||
#define scisxdigit iswxdigit
|
||||
#define scisalpha iswalpha
|
||||
#define sciscntrl iswcntrl
|
||||
#define scisalnum iswalnum
|
||||
#define scprintf wprintf
|
||||
#define scfprintf fwprintf
|
||||
#define scvprintf vwprintf
|
||||
#define scvfprintf vfwprintf
|
||||
#define scvsnprintf _vsnwprintf
|
||||
#define scstrdup _wcsdup
|
||||
#define scstrrchr wcsrchr
|
||||
#define scstrcat wcscat
|
||||
#define MAX_CHAR 0xFFFF
|
||||
#else
|
||||
typedef char SQChar;
|
||||
#define _SC(a) a
|
||||
#define scstrcmp strcmp
|
||||
#define scsprintf sprintf
|
||||
#define scsnprintf snprintf
|
||||
#define scstrlen strlen
|
||||
#define scstrtod strtod
|
||||
#define scstrtol strtol
|
||||
#define scatoi atoi
|
||||
#define scstrtoul strtoul
|
||||
#define scvsprintf vsprintf
|
||||
#define scstrstr strstr
|
||||
#define scisspace isspace
|
||||
#define scisdigit isdigit
|
||||
#define scisxdigit isxdigit
|
||||
#define sciscntrl iscntrl
|
||||
#define scisalpha isalpha
|
||||
#define scisalnum isalnum
|
||||
#define scprintf printf
|
||||
#define scfprintf fprintf
|
||||
#define scvprintf vprintf
|
||||
#define scvfprintf vfprintf
|
||||
#define scvsnprintf vsnprintf
|
||||
#define scstrdup strdup
|
||||
#define scstrrchr strrchr
|
||||
#define scstrcat strcat
|
||||
#define MAX_CHAR 0xFFFF
|
||||
#endif
|
||||
|
||||
#define SQUIRREL_VERSION _SC("Squirrel 2.2.5 stable - With custom OpenTTD modifications")
|
||||
#define SQUIRREL_COPYRIGHT _SC("Copyright (C) 2003-2010 Alberto Demichelis")
|
||||
#define SQUIRREL_AUTHOR _SC("Alberto Demichelis")
|
||||
#define SQUIRREL_VERSION "Squirrel 2.2.5 stable - With custom OpenTTD modifications"
|
||||
#define SQUIRREL_COPYRIGHT "Copyright (C) 2003-2010 Alberto Demichelis"
|
||||
#define SQUIRREL_AUTHOR "Alberto Demichelis"
|
||||
#define SQUIRREL_VERSION_NUMBER 225
|
||||
|
||||
#define SQ_VMSTATE_IDLE 0
|
||||
@@ -294,7 +179,7 @@ typedef void (*SQPRINTFUNCTION)(HSQUIRRELVM,const SQChar * ,...);
|
||||
typedef SQInteger (*SQWRITEFUNC)(SQUserPointer,SQUserPointer,SQInteger);
|
||||
typedef SQInteger (*SQREADFUNC)(SQUserPointer,SQUserPointer,SQInteger);
|
||||
|
||||
typedef SQInteger (*SQLEXREADFUNC)(SQUserPointer);
|
||||
typedef WChar (*SQLEXREADFUNC)(SQUserPointer);
|
||||
|
||||
typedef struct tagSQRegFunction{
|
||||
const SQChar *name;
|
||||
@@ -311,147 +196,147 @@ typedef struct tagSQFunctionInfo {
|
||||
|
||||
|
||||
/*vm*/
|
||||
SQUIRREL_API bool sq_can_suspend(HSQUIRRELVM v);
|
||||
SQUIRREL_API HSQUIRRELVM sq_open(SQInteger initialstacksize);
|
||||
SQUIRREL_API HSQUIRRELVM sq_newthread(HSQUIRRELVM friendvm, SQInteger initialstacksize);
|
||||
SQUIRREL_API void sq_seterrorhandler(HSQUIRRELVM v);
|
||||
SQUIRREL_API void sq_close(HSQUIRRELVM v);
|
||||
SQUIRREL_API void sq_setforeignptr(HSQUIRRELVM v,SQUserPointer p);
|
||||
SQUIRREL_API SQUserPointer sq_getforeignptr(HSQUIRRELVM v);
|
||||
SQUIRREL_API void sq_setprintfunc(HSQUIRRELVM v, SQPRINTFUNCTION printfunc);
|
||||
SQUIRREL_API SQPRINTFUNCTION sq_getprintfunc(HSQUIRRELVM v);
|
||||
SQUIRREL_API SQRESULT sq_suspendvm(HSQUIRRELVM v);
|
||||
SQUIRREL_API bool sq_resumecatch(HSQUIRRELVM v, int suspend = -1);
|
||||
SQUIRREL_API bool sq_resumeerror(HSQUIRRELVM v);
|
||||
SQUIRREL_API SQRESULT sq_wakeupvm(HSQUIRRELVM v,SQBool resumedret,SQBool retval,SQBool raiseerror,SQBool throwerror);
|
||||
SQUIRREL_API SQInteger sq_getvmstate(HSQUIRRELVM v);
|
||||
SQUIRREL_API void sq_decreaseops(HSQUIRRELVM v, int amount);
|
||||
bool sq_can_suspend(HSQUIRRELVM v);
|
||||
HSQUIRRELVM sq_open(SQInteger initialstacksize);
|
||||
HSQUIRRELVM sq_newthread(HSQUIRRELVM friendvm, SQInteger initialstacksize);
|
||||
void sq_seterrorhandler(HSQUIRRELVM v);
|
||||
void sq_close(HSQUIRRELVM v);
|
||||
void sq_setforeignptr(HSQUIRRELVM v,SQUserPointer p);
|
||||
SQUserPointer sq_getforeignptr(HSQUIRRELVM v);
|
||||
void sq_setprintfunc(HSQUIRRELVM v, SQPRINTFUNCTION printfunc);
|
||||
SQPRINTFUNCTION sq_getprintfunc(HSQUIRRELVM v);
|
||||
SQRESULT sq_suspendvm(HSQUIRRELVM v);
|
||||
bool sq_resumecatch(HSQUIRRELVM v, int suspend = -1);
|
||||
bool sq_resumeerror(HSQUIRRELVM v);
|
||||
SQRESULT sq_wakeupvm(HSQUIRRELVM v,SQBool resumedret,SQBool retval,SQBool raiseerror,SQBool throwerror);
|
||||
SQInteger sq_getvmstate(HSQUIRRELVM v);
|
||||
void sq_decreaseops(HSQUIRRELVM v, int amount);
|
||||
|
||||
/*compiler*/
|
||||
SQUIRREL_API SQRESULT sq_compile(HSQUIRRELVM v,SQLEXREADFUNC read,SQUserPointer p,const SQChar *sourcename,SQBool raiseerror);
|
||||
SQUIRREL_API SQRESULT sq_compilebuffer(HSQUIRRELVM v,const SQChar *s,SQInteger size,const SQChar *sourcename,SQBool raiseerror);
|
||||
SQUIRREL_API void sq_enabledebuginfo(HSQUIRRELVM v, SQBool enable);
|
||||
SQUIRREL_API void sq_notifyallexceptions(HSQUIRRELVM v, SQBool enable);
|
||||
SQUIRREL_API void sq_setcompilererrorhandler(HSQUIRRELVM v,SQCOMPILERERROR f);
|
||||
SQRESULT sq_compile(HSQUIRRELVM v,SQLEXREADFUNC read,SQUserPointer p,const SQChar *sourcename,SQBool raiseerror);
|
||||
SQRESULT sq_compilebuffer(HSQUIRRELVM v,const SQChar *s,SQInteger size,const SQChar *sourcename,SQBool raiseerror);
|
||||
void sq_enabledebuginfo(HSQUIRRELVM v, SQBool enable);
|
||||
void sq_notifyallexceptions(HSQUIRRELVM v, SQBool enable);
|
||||
void sq_setcompilererrorhandler(HSQUIRRELVM v,SQCOMPILERERROR f);
|
||||
|
||||
/*stack operations*/
|
||||
SQUIRREL_API void sq_push(HSQUIRRELVM v,SQInteger idx);
|
||||
SQUIRREL_API void sq_pop(HSQUIRRELVM v,SQInteger nelemstopop);
|
||||
SQUIRREL_API void sq_poptop(HSQUIRRELVM v);
|
||||
SQUIRREL_API void sq_remove(HSQUIRRELVM v,SQInteger idx);
|
||||
SQUIRREL_API SQInteger sq_gettop(HSQUIRRELVM v);
|
||||
SQUIRREL_API void sq_settop(HSQUIRRELVM v,SQInteger newtop);
|
||||
SQUIRREL_API void sq_reservestack(HSQUIRRELVM v,SQInteger nsize);
|
||||
SQUIRREL_API SQInteger sq_cmp(HSQUIRRELVM v);
|
||||
SQUIRREL_API void sq_move(HSQUIRRELVM dest,HSQUIRRELVM src,SQInteger idx);
|
||||
void sq_push(HSQUIRRELVM v,SQInteger idx);
|
||||
void sq_pop(HSQUIRRELVM v,SQInteger nelemstopop);
|
||||
void sq_poptop(HSQUIRRELVM v);
|
||||
void sq_remove(HSQUIRRELVM v,SQInteger idx);
|
||||
SQInteger sq_gettop(HSQUIRRELVM v);
|
||||
void sq_settop(HSQUIRRELVM v,SQInteger newtop);
|
||||
void sq_reservestack(HSQUIRRELVM v,SQInteger nsize);
|
||||
SQInteger sq_cmp(HSQUIRRELVM v);
|
||||
void sq_move(HSQUIRRELVM dest,HSQUIRRELVM src,SQInteger idx);
|
||||
|
||||
/*object creation handling*/
|
||||
SQUIRREL_API SQUserPointer sq_newuserdata(HSQUIRRELVM v,SQUnsignedInteger size);
|
||||
SQUIRREL_API void sq_newtable(HSQUIRRELVM v);
|
||||
SQUIRREL_API void sq_newarray(HSQUIRRELVM v,SQInteger size);
|
||||
SQUIRREL_API void sq_newclosure(HSQUIRRELVM v,SQFUNCTION func,SQUnsignedInteger nfreevars);
|
||||
SQUIRREL_API SQRESULT sq_setparamscheck(HSQUIRRELVM v,SQInteger nparamscheck,const SQChar *typemask);
|
||||
SQUIRREL_API SQRESULT sq_bindenv(HSQUIRRELVM v,SQInteger idx);
|
||||
SQUIRREL_API void sq_pushstring(HSQUIRRELVM v,const SQChar *s,SQInteger len);
|
||||
SQUIRREL_API void sq_pushfloat(HSQUIRRELVM v,SQFloat f);
|
||||
SQUIRREL_API void sq_pushinteger(HSQUIRRELVM v,SQInteger n);
|
||||
SQUIRREL_API void sq_pushbool(HSQUIRRELVM v,SQBool b);
|
||||
SQUIRREL_API void sq_pushuserpointer(HSQUIRRELVM v,SQUserPointer p);
|
||||
SQUIRREL_API void sq_pushnull(HSQUIRRELVM v);
|
||||
SQUIRREL_API SQObjectType sq_gettype(HSQUIRRELVM v,SQInteger idx);
|
||||
SQUIRREL_API SQInteger sq_getsize(HSQUIRRELVM v,SQInteger idx);
|
||||
SQUIRREL_API SQRESULT sq_getbase(HSQUIRRELVM v,SQInteger idx);
|
||||
SQUIRREL_API SQBool sq_instanceof(HSQUIRRELVM v);
|
||||
SQUIRREL_API void sq_tostring(HSQUIRRELVM v,SQInteger idx);
|
||||
SQUIRREL_API void sq_tobool(HSQUIRRELVM v, SQInteger idx, SQBool *b);
|
||||
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);
|
||||
SQUIRREL_API SQRESULT sq_getbool(HSQUIRRELVM v,SQInteger idx,SQBool *b);
|
||||
SQUIRREL_API SQRESULT sq_getthread(HSQUIRRELVM v,SQInteger idx,HSQUIRRELVM *thread);
|
||||
SQUIRREL_API SQRESULT sq_getuserpointer(HSQUIRRELVM v,SQInteger idx,SQUserPointer *p);
|
||||
SQUIRREL_API SQRESULT sq_getuserdata(HSQUIRRELVM v,SQInteger idx,SQUserPointer *p,SQUserPointer *typetag);
|
||||
SQUIRREL_API SQRESULT sq_settypetag(HSQUIRRELVM v,SQInteger idx,SQUserPointer typetag);
|
||||
SQUIRREL_API SQRESULT sq_gettypetag(HSQUIRRELVM v,SQInteger idx,SQUserPointer *typetag);
|
||||
SQUIRREL_API void sq_setreleasehook(HSQUIRRELVM v,SQInteger idx,SQRELEASEHOOK hook);
|
||||
SQUIRREL_API SQChar *sq_getscratchpad(HSQUIRRELVM v,SQInteger minsize);
|
||||
SQUIRREL_API SQRESULT sq_getfunctioninfo(HSQUIRRELVM v,SQInteger idx,SQFunctionInfo *fi);
|
||||
SQUIRREL_API SQRESULT sq_getclosureinfo(HSQUIRRELVM v,SQInteger idx,SQUnsignedInteger *nparams,SQUnsignedInteger *nfreevars);
|
||||
SQUIRREL_API SQRESULT sq_setnativeclosurename(HSQUIRRELVM v,SQInteger idx,const SQChar *name);
|
||||
SQUIRREL_API SQRESULT sq_setinstanceup(HSQUIRRELVM v, SQInteger idx, SQUserPointer p);
|
||||
SQUIRREL_API SQRESULT sq_getinstanceup(HSQUIRRELVM v, SQInteger idx, SQUserPointer *p,SQUserPointer typetag);
|
||||
SQUIRREL_API SQRESULT sq_setclassudsize(HSQUIRRELVM v, SQInteger idx, SQInteger udsize);
|
||||
SQUIRREL_API SQRESULT sq_newclass(HSQUIRRELVM v,SQBool hasbase);
|
||||
SQUIRREL_API SQRESULT sq_createinstance(HSQUIRRELVM v,SQInteger idx);
|
||||
SQUIRREL_API SQRESULT sq_setattributes(HSQUIRRELVM v,SQInteger idx);
|
||||
SQUIRREL_API SQRESULT sq_getattributes(HSQUIRRELVM v,SQInteger idx);
|
||||
SQUIRREL_API SQRESULT sq_getclass(HSQUIRRELVM v,SQInteger idx);
|
||||
SQUIRREL_API void sq_weakref(HSQUIRRELVM v,SQInteger idx);
|
||||
SQUIRREL_API SQRESULT sq_getdefaultdelegate(HSQUIRRELVM v,SQObjectType t);
|
||||
SQUserPointer sq_newuserdata(HSQUIRRELVM v,SQUnsignedInteger size);
|
||||
void sq_newtable(HSQUIRRELVM v);
|
||||
void sq_newarray(HSQUIRRELVM v,SQInteger size);
|
||||
void sq_newclosure(HSQUIRRELVM v,SQFUNCTION func,SQUnsignedInteger nfreevars);
|
||||
SQRESULT sq_setparamscheck(HSQUIRRELVM v,SQInteger nparamscheck,const SQChar *typemask);
|
||||
SQRESULT sq_bindenv(HSQUIRRELVM v,SQInteger idx);
|
||||
void sq_pushstring(HSQUIRRELVM v,const SQChar *s,SQInteger len);
|
||||
void sq_pushfloat(HSQUIRRELVM v,SQFloat f);
|
||||
void sq_pushinteger(HSQUIRRELVM v,SQInteger n);
|
||||
void sq_pushbool(HSQUIRRELVM v,SQBool b);
|
||||
void sq_pushuserpointer(HSQUIRRELVM v,SQUserPointer p);
|
||||
void sq_pushnull(HSQUIRRELVM v);
|
||||
SQObjectType sq_gettype(HSQUIRRELVM v,SQInteger idx);
|
||||
SQInteger sq_getsize(HSQUIRRELVM v,SQInteger idx);
|
||||
SQRESULT sq_getbase(HSQUIRRELVM v,SQInteger idx);
|
||||
SQBool sq_instanceof(HSQUIRRELVM v);
|
||||
void sq_tostring(HSQUIRRELVM v,SQInteger idx);
|
||||
void sq_tobool(HSQUIRRELVM v, SQInteger idx, SQBool *b);
|
||||
SQRESULT sq_getstring(HSQUIRRELVM v,SQInteger idx,const SQChar **c);
|
||||
SQRESULT sq_getinteger(HSQUIRRELVM v,SQInteger idx,SQInteger *i);
|
||||
SQRESULT sq_getfloat(HSQUIRRELVM v,SQInteger idx,SQFloat *f);
|
||||
SQRESULT sq_getbool(HSQUIRRELVM v,SQInteger idx,SQBool *b);
|
||||
SQRESULT sq_getthread(HSQUIRRELVM v,SQInteger idx,HSQUIRRELVM *thread);
|
||||
SQRESULT sq_getuserpointer(HSQUIRRELVM v,SQInteger idx,SQUserPointer *p);
|
||||
SQRESULT sq_getuserdata(HSQUIRRELVM v,SQInteger idx,SQUserPointer *p,SQUserPointer *typetag);
|
||||
SQRESULT sq_settypetag(HSQUIRRELVM v,SQInteger idx,SQUserPointer typetag);
|
||||
SQRESULT sq_gettypetag(HSQUIRRELVM v,SQInteger idx,SQUserPointer *typetag);
|
||||
void sq_setreleasehook(HSQUIRRELVM v,SQInteger idx,SQRELEASEHOOK hook);
|
||||
SQChar *sq_getscratchpad(HSQUIRRELVM v,SQInteger minsize);
|
||||
SQRESULT sq_getfunctioninfo(HSQUIRRELVM v,SQInteger idx,SQFunctionInfo *fi);
|
||||
SQRESULT sq_getclosureinfo(HSQUIRRELVM v,SQInteger idx,SQUnsignedInteger *nparams,SQUnsignedInteger *nfreevars);
|
||||
SQRESULT sq_setnativeclosurename(HSQUIRRELVM v,SQInteger idx,const SQChar *name);
|
||||
SQRESULT sq_setinstanceup(HSQUIRRELVM v, SQInteger idx, SQUserPointer p);
|
||||
SQRESULT sq_getinstanceup(HSQUIRRELVM v, SQInteger idx, SQUserPointer *p,SQUserPointer typetag);
|
||||
SQRESULT sq_setclassudsize(HSQUIRRELVM v, SQInteger idx, SQInteger udsize);
|
||||
SQRESULT sq_newclass(HSQUIRRELVM v,SQBool hasbase);
|
||||
SQRESULT sq_createinstance(HSQUIRRELVM v,SQInteger idx);
|
||||
SQRESULT sq_setattributes(HSQUIRRELVM v,SQInteger idx);
|
||||
SQRESULT sq_getattributes(HSQUIRRELVM v,SQInteger idx);
|
||||
SQRESULT sq_getclass(HSQUIRRELVM v,SQInteger idx);
|
||||
void sq_weakref(HSQUIRRELVM v,SQInteger idx);
|
||||
SQRESULT sq_getdefaultdelegate(HSQUIRRELVM v,SQObjectType t);
|
||||
|
||||
/*object manipulation*/
|
||||
SQUIRREL_API void sq_pushroottable(HSQUIRRELVM v);
|
||||
SQUIRREL_API void sq_pushregistrytable(HSQUIRRELVM v);
|
||||
SQUIRREL_API void sq_pushconsttable(HSQUIRRELVM v);
|
||||
SQUIRREL_API SQRESULT sq_setroottable(HSQUIRRELVM v);
|
||||
SQUIRREL_API SQRESULT sq_setconsttable(HSQUIRRELVM v);
|
||||
SQUIRREL_API SQRESULT sq_newslot(HSQUIRRELVM v, SQInteger idx, SQBool bstatic);
|
||||
SQUIRREL_API SQRESULT sq_deleteslot(HSQUIRRELVM v,SQInteger idx,SQBool pushval);
|
||||
SQUIRREL_API SQRESULT sq_set(HSQUIRRELVM v,SQInteger idx);
|
||||
SQUIRREL_API SQRESULT sq_get(HSQUIRRELVM v,SQInteger idx);
|
||||
SQUIRREL_API SQRESULT sq_rawget(HSQUIRRELVM v,SQInteger idx);
|
||||
SQUIRREL_API SQRESULT sq_rawset(HSQUIRRELVM v,SQInteger idx);
|
||||
SQUIRREL_API SQRESULT sq_rawdeleteslot(HSQUIRRELVM v,SQInteger idx,SQBool pushval);
|
||||
SQUIRREL_API SQRESULT sq_arrayappend(HSQUIRRELVM v,SQInteger idx);
|
||||
SQUIRREL_API SQRESULT sq_arraypop(HSQUIRRELVM v,SQInteger idx,SQBool pushval);
|
||||
SQUIRREL_API SQRESULT sq_arrayresize(HSQUIRRELVM v,SQInteger idx,SQInteger newsize);
|
||||
SQUIRREL_API SQRESULT sq_arrayreverse(HSQUIRRELVM v,SQInteger idx);
|
||||
SQUIRREL_API SQRESULT sq_arrayremove(HSQUIRRELVM v,SQInteger idx,SQInteger itemidx);
|
||||
SQUIRREL_API SQRESULT sq_arrayinsert(HSQUIRRELVM v,SQInteger idx,SQInteger destpos);
|
||||
SQUIRREL_API SQRESULT sq_setdelegate(HSQUIRRELVM v,SQInteger idx);
|
||||
SQUIRREL_API SQRESULT sq_getdelegate(HSQUIRRELVM v,SQInteger idx);
|
||||
SQUIRREL_API SQRESULT sq_clone(HSQUIRRELVM v,SQInteger idx);
|
||||
SQUIRREL_API SQRESULT sq_setfreevariable(HSQUIRRELVM v,SQInteger idx,SQUnsignedInteger nval);
|
||||
SQUIRREL_API SQRESULT sq_next(HSQUIRRELVM v,SQInteger idx);
|
||||
SQUIRREL_API SQRESULT sq_getweakrefval(HSQUIRRELVM v,SQInteger idx);
|
||||
SQUIRREL_API SQRESULT sq_clear(HSQUIRRELVM v,SQInteger idx);
|
||||
void sq_pushroottable(HSQUIRRELVM v);
|
||||
void sq_pushregistrytable(HSQUIRRELVM v);
|
||||
void sq_pushconsttable(HSQUIRRELVM v);
|
||||
SQRESULT sq_setroottable(HSQUIRRELVM v);
|
||||
SQRESULT sq_setconsttable(HSQUIRRELVM v);
|
||||
SQRESULT sq_newslot(HSQUIRRELVM v, SQInteger idx, SQBool bstatic);
|
||||
SQRESULT sq_deleteslot(HSQUIRRELVM v,SQInteger idx,SQBool pushval);
|
||||
SQRESULT sq_set(HSQUIRRELVM v,SQInteger idx);
|
||||
SQRESULT sq_get(HSQUIRRELVM v,SQInteger idx);
|
||||
SQRESULT sq_rawget(HSQUIRRELVM v,SQInteger idx);
|
||||
SQRESULT sq_rawset(HSQUIRRELVM v,SQInteger idx);
|
||||
SQRESULT sq_rawdeleteslot(HSQUIRRELVM v,SQInteger idx,SQBool pushval);
|
||||
SQRESULT sq_arrayappend(HSQUIRRELVM v,SQInteger idx);
|
||||
SQRESULT sq_arraypop(HSQUIRRELVM v,SQInteger idx,SQBool pushval);
|
||||
SQRESULT sq_arrayresize(HSQUIRRELVM v,SQInteger idx,SQInteger newsize);
|
||||
SQRESULT sq_arrayreverse(HSQUIRRELVM v,SQInteger idx);
|
||||
SQRESULT sq_arrayremove(HSQUIRRELVM v,SQInteger idx,SQInteger itemidx);
|
||||
SQRESULT sq_arrayinsert(HSQUIRRELVM v,SQInteger idx,SQInteger destpos);
|
||||
SQRESULT sq_setdelegate(HSQUIRRELVM v,SQInteger idx);
|
||||
SQRESULT sq_getdelegate(HSQUIRRELVM v,SQInteger idx);
|
||||
SQRESULT sq_clone(HSQUIRRELVM v,SQInteger idx);
|
||||
SQRESULT sq_setfreevariable(HSQUIRRELVM v,SQInteger idx,SQUnsignedInteger nval);
|
||||
SQRESULT sq_next(HSQUIRRELVM v,SQInteger idx);
|
||||
SQRESULT sq_getweakrefval(HSQUIRRELVM v,SQInteger idx);
|
||||
SQRESULT sq_clear(HSQUIRRELVM v,SQInteger idx);
|
||||
|
||||
/*calls*/
|
||||
SQUIRREL_API SQRESULT sq_call(HSQUIRRELVM v,SQInteger params,SQBool retval,SQBool raiseerror, int suspend = -1);
|
||||
SQUIRREL_API SQRESULT sq_resume(HSQUIRRELVM v,SQBool retval,SQBool raiseerror);
|
||||
SQUIRREL_API const SQChar *sq_getlocal(HSQUIRRELVM v,SQUnsignedInteger level,SQUnsignedInteger idx);
|
||||
SQUIRREL_API const SQChar *sq_getfreevariable(HSQUIRRELVM v,SQInteger idx,SQUnsignedInteger nval);
|
||||
SQUIRREL_API SQRESULT sq_throwerror(HSQUIRRELVM v,const SQChar *err);
|
||||
SQUIRREL_API void sq_reseterror(HSQUIRRELVM v);
|
||||
SQUIRREL_API void sq_getlasterror(HSQUIRRELVM v);
|
||||
SQRESULT sq_call(HSQUIRRELVM v,SQInteger params,SQBool retval,SQBool raiseerror, int suspend = -1);
|
||||
SQRESULT sq_resume(HSQUIRRELVM v,SQBool retval,SQBool raiseerror);
|
||||
const SQChar *sq_getlocal(HSQUIRRELVM v,SQUnsignedInteger level,SQUnsignedInteger idx);
|
||||
const SQChar *sq_getfreevariable(HSQUIRRELVM v,SQInteger idx,SQUnsignedInteger nval);
|
||||
SQRESULT sq_throwerror(HSQUIRRELVM v,const SQChar *err);
|
||||
void sq_reseterror(HSQUIRRELVM v);
|
||||
void sq_getlasterror(HSQUIRRELVM v);
|
||||
|
||||
/*raw object handling*/
|
||||
SQUIRREL_API SQRESULT sq_getstackobj(HSQUIRRELVM v,SQInteger idx,HSQOBJECT *po);
|
||||
SQUIRREL_API void sq_pushobject(HSQUIRRELVM v,HSQOBJECT obj);
|
||||
SQUIRREL_API void sq_addref(HSQUIRRELVM v,HSQOBJECT *po);
|
||||
SQUIRREL_API SQBool sq_release(HSQUIRRELVM v,HSQOBJECT *po);
|
||||
SQUIRREL_API void sq_resetobject(HSQOBJECT *po);
|
||||
SQUIRREL_API const SQChar *sq_objtostring(HSQOBJECT *o);
|
||||
SQUIRREL_API SQBool sq_objtobool(HSQOBJECT *o);
|
||||
SQUIRREL_API SQInteger sq_objtointeger(HSQOBJECT *o);
|
||||
SQUIRREL_API SQFloat sq_objtofloat(HSQOBJECT *o);
|
||||
SQUIRREL_API SQRESULT sq_getobjtypetag(HSQOBJECT *o,SQUserPointer * typetag);
|
||||
SQRESULT sq_getstackobj(HSQUIRRELVM v,SQInteger idx,HSQOBJECT *po);
|
||||
void sq_pushobject(HSQUIRRELVM v,HSQOBJECT obj);
|
||||
void sq_addref(HSQUIRRELVM v,HSQOBJECT *po);
|
||||
SQBool sq_release(HSQUIRRELVM v,HSQOBJECT *po);
|
||||
void sq_resetobject(HSQOBJECT *po);
|
||||
const SQChar *sq_objtostring(HSQOBJECT *o);
|
||||
SQBool sq_objtobool(HSQOBJECT *o);
|
||||
SQInteger sq_objtointeger(HSQOBJECT *o);
|
||||
SQFloat sq_objtofloat(HSQOBJECT *o);
|
||||
SQRESULT sq_getobjtypetag(HSQOBJECT *o,SQUserPointer * typetag);
|
||||
|
||||
/*GC*/
|
||||
SQUIRREL_API SQInteger sq_collectgarbage(HSQUIRRELVM v);
|
||||
SQInteger sq_collectgarbage(HSQUIRRELVM v);
|
||||
|
||||
/*serialization*/
|
||||
SQUIRREL_API SQRESULT sq_writeclosure(HSQUIRRELVM vm,SQWRITEFUNC writef,SQUserPointer up);
|
||||
SQUIRREL_API SQRESULT sq_readclosure(HSQUIRRELVM vm,SQREADFUNC readf,SQUserPointer up);
|
||||
SQRESULT sq_writeclosure(HSQUIRRELVM vm,SQWRITEFUNC writef,SQUserPointer up);
|
||||
SQRESULT sq_readclosure(HSQUIRRELVM vm,SQREADFUNC readf,SQUserPointer up);
|
||||
|
||||
/*mem allocation*/
|
||||
SQUIRREL_API void *sq_malloc(SQUnsignedInteger size);
|
||||
SQUIRREL_API void *sq_realloc(void* p,SQUnsignedInteger oldsize,SQUnsignedInteger newsize);
|
||||
SQUIRREL_API void sq_free(void *p,SQUnsignedInteger size);
|
||||
void *sq_malloc(SQUnsignedInteger size);
|
||||
void *sq_realloc(void* p,SQUnsignedInteger oldsize,SQUnsignedInteger newsize);
|
||||
void sq_free(void *p,SQUnsignedInteger size);
|
||||
|
||||
/*debug*/
|
||||
SQUIRREL_API SQRESULT sq_stackinfos(HSQUIRRELVM v,SQInteger level,SQStackInfos *si);
|
||||
SQUIRREL_API void sq_setdebughook(HSQUIRRELVM v);
|
||||
SQRESULT sq_stackinfos(HSQUIRRELVM v,SQInteger level,SQStackInfos *si);
|
||||
void sq_setdebughook(HSQUIRRELVM v);
|
||||
|
||||
/*UTILITY MACRO*/
|
||||
#define sq_isnumeric(o) ((o)._type&SQOBJECT_NUMERIC)
|
||||
@@ -483,8 +368,4 @@ SQUIRREL_API void sq_setdebughook(HSQUIRRELVM v);
|
||||
#define SQ_FAILED(res) (res<0)
|
||||
#define SQ_SUCCEEDED(res) (res>=0)
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /*extern "C"*/
|
||||
#endif
|
||||
|
||||
#endif /*_SQUIRREL_H_*/
|
||||
|
23
src/3rdparty/squirrel/samples/ackermann.nut
vendored
23
src/3rdparty/squirrel/samples/ackermann.nut
vendored
@@ -1,23 +0,0 @@
|
||||
/*
|
||||
*
|
||||
* Original Javascript version by David Hedbor(http://www.bagley.org/~doug/shootout/)
|
||||
*
|
||||
*/
|
||||
|
||||
function Ack(M, N) {
|
||||
if (M == 0) return( N + 1 );
|
||||
if (N == 0) return( Ack(M - 1, 1) );
|
||||
return( Ack(M - 1, Ack(M, (N - 1))) );
|
||||
}
|
||||
|
||||
local n;
|
||||
|
||||
if(ARGS.len()!=0) {
|
||||
n = ARGS[0].tointeger();
|
||||
if(n < 1) n = 1;
|
||||
} else {
|
||||
n = 1;
|
||||
}
|
||||
print("n="+n+"\n");
|
||||
print("Ack(3,"+ n+ "):"+ Ack(3, n));
|
||||
|
28
src/3rdparty/squirrel/samples/array.nut
vendored
28
src/3rdparty/squirrel/samples/array.nut
vendored
@@ -1,28 +0,0 @@
|
||||
/*
|
||||
*
|
||||
* Original Javascript version by David Hedbor(http://www.bagley.org/~doug/shootout/)
|
||||
*
|
||||
*/
|
||||
local n, i, k;
|
||||
|
||||
if(ARGS.len()!=0) {
|
||||
n = ARGS[0].tointeger();
|
||||
if(n < 1) n = 1;
|
||||
} else {
|
||||
n = 1;
|
||||
}
|
||||
|
||||
local x = []; x.resize(n);
|
||||
local y = []; y.resize(n);
|
||||
|
||||
for (i = 0; i < n; i+=1) {
|
||||
x[i] = i + 1;
|
||||
y[i] = 0;
|
||||
}
|
||||
|
||||
for (k = 0 ; k < n; k+=1) {
|
||||
for (i = n-1; i >= 0; i-=1) {
|
||||
y[i] = y[i]+ x[i];
|
||||
}
|
||||
}
|
||||
print(y[0].tostring()+" "+y[n-1]);
|
49
src/3rdparty/squirrel/samples/class.nut
vendored
49
src/3rdparty/squirrel/samples/class.nut
vendored
@@ -1,49 +0,0 @@
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
class BaseVector {
|
||||
constructor(...)
|
||||
{
|
||||
if(vargc >= 3) {
|
||||
x = vargv[0];
|
||||
y = vargv[1];
|
||||
z = vargv[2];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
x = 0;
|
||||
y = 0;
|
||||
z = 0;
|
||||
}
|
||||
|
||||
class Vector3 extends BaseVector {
|
||||
function _add(other)
|
||||
{
|
||||
if(other instanceof this.getclass())
|
||||
return ::Vector3(x+other.x,y+other.y,z+other.z);
|
||||
else
|
||||
throw "wrong parameter";
|
||||
}
|
||||
function Print()
|
||||
{
|
||||
::print(x+","+y+","+z+"\n");
|
||||
}
|
||||
}
|
||||
|
||||
local v0 = Vector3(1,2,3)
|
||||
local v1 = Vector3(11,12,13)
|
||||
local v2 = v0 + v1;
|
||||
v2.Print();
|
||||
|
||||
FakeNamespace <- {
|
||||
Utils = {}
|
||||
}
|
||||
|
||||
class FakeNamespace.Utils.SuperClass {
|
||||
constructor()
|
||||
{
|
||||
::print("FakeNamespace.Utils.SuperClass")
|
||||
}
|
||||
}
|
||||
|
||||
local testy = FakeNamespace.Utils.SuperClass();
|
@@ -1,35 +0,0 @@
|
||||
class Foo {
|
||||
//constructor
|
||||
constructor(a)
|
||||
{
|
||||
testy = ["stuff",1,2,3];
|
||||
}
|
||||
//attributes of PrintTesty
|
||||
</ test = "freakin attribute"/>
|
||||
function PrintTesty()
|
||||
{
|
||||
foreach(i,val in testy)
|
||||
{
|
||||
::print("idx = "+i+" = "+val+" \n");
|
||||
}
|
||||
}
|
||||
//attributes of testy
|
||||
</ flippy = 10 , second = [1,2,3] />
|
||||
testy = null;
|
||||
|
||||
}
|
||||
|
||||
foreach(member,val in Foo)
|
||||
{
|
||||
::print(member+"\n");
|
||||
local attr;
|
||||
if((attr = Foo.getattributes(member)) != null) {
|
||||
foreach(i,v in attr)
|
||||
{
|
||||
::print("\t"+i+" = "+(typeof v)+"\n");
|
||||
}
|
||||
}
|
||||
else {
|
||||
::print("\t<no attributes>\n")
|
||||
}
|
||||
}
|
25
src/3rdparty/squirrel/samples/coroutines.nut
vendored
25
src/3rdparty/squirrel/samples/coroutines.nut
vendored
@@ -1,25 +0,0 @@
|
||||
function coroutine_test(a,b)
|
||||
{
|
||||
::print(a+" "+b+"\n");
|
||||
local ret = ::suspend("suspend 1");
|
||||
::print("the coroutine says "+ret+"\n");
|
||||
ret = ::suspend("suspend 2");
|
||||
::print("the coroutine says "+ret+"\n");
|
||||
ret = ::suspend("suspend 3");
|
||||
::print("the coroutine says "+ret+"\n");
|
||||
return "I'm done"
|
||||
}
|
||||
|
||||
local coro = ::newthread(coroutine_test);
|
||||
|
||||
local susparam = coro.call("test","coroutine"); //starts the coroutine
|
||||
|
||||
local i = 1;
|
||||
do
|
||||
{
|
||||
::print("suspend passed ["+susparam+"]\n")
|
||||
susparam = coro.wakeup("ciao "+i);
|
||||
++i;
|
||||
}while(coro.getstatus()=="suspended")
|
||||
|
||||
::print("return passed ["+susparam+"]\n")
|
52
src/3rdparty/squirrel/samples/delegation.nut
vendored
52
src/3rdparty/squirrel/samples/delegation.nut
vendored
@@ -1,52 +0,0 @@
|
||||
|
||||
PEntity <- {
|
||||
name="noname"
|
||||
pos={x=0,y=0,z=0}
|
||||
type="entity"
|
||||
//methamethod
|
||||
_typeof=function()
|
||||
{
|
||||
return type;
|
||||
}
|
||||
}
|
||||
|
||||
function PEntity::PrintPos()
|
||||
{
|
||||
::print("x="+pos.x+" y="+pos.y+" z="+pos.z+"\n");
|
||||
}
|
||||
|
||||
function PEntity::new(name,pos)
|
||||
{
|
||||
local newentity=clone ::PEntity;
|
||||
if(name)
|
||||
newentity.name=name;
|
||||
if(pos)
|
||||
newentity.pos=pos;
|
||||
return newentity;
|
||||
}
|
||||
|
||||
PPlayer <- {
|
||||
model="warrior.mdl"
|
||||
weapon="fist"
|
||||
health=100
|
||||
armor=0
|
||||
//overrides the parent type
|
||||
type="player"
|
||||
}
|
||||
|
||||
function PPlayer::new(name,pos)
|
||||
{
|
||||
local newplayer=delegate ::PEntity.new(name,pos) : clone ::PPlayer;
|
||||
return newplayer;
|
||||
}
|
||||
|
||||
local player=PPlayer.new("godzilla",{x=10,y=20,z=30});
|
||||
|
||||
::print("PLAYER NAME"+player.name+"\n");
|
||||
::print("ENTITY TYPE"+typeof player+"\n");
|
||||
|
||||
player.PrintPos();
|
||||
|
||||
player.pos.x=123;
|
||||
|
||||
player.PrintPos();
|
15
src/3rdparty/squirrel/samples/fibonacci.nut
vendored
15
src/3rdparty/squirrel/samples/fibonacci.nut
vendored
@@ -1,15 +0,0 @@
|
||||
/*
|
||||
*
|
||||
* Original Javascript version by David Hedbor(http://www.bagley.org/~doug/shootout/)
|
||||
*
|
||||
*/
|
||||
|
||||
function fib(n)
|
||||
{
|
||||
if (n < 2) return 1
|
||||
return fib(n-2) + fib(n-1)
|
||||
}
|
||||
|
||||
local n = ARGS.len()!=0?ARGS[0].tointeger():1
|
||||
|
||||
print(fib(n)+"\n")
|
33
src/3rdparty/squirrel/samples/flow.nut
vendored
33
src/3rdparty/squirrel/samples/flow.nut
vendored
@@ -1,33 +0,0 @@
|
||||
function min(x,y)
|
||||
return x<y?x:y;
|
||||
|
||||
function max(x,y)
|
||||
return x>y?x:y;
|
||||
|
||||
if(min(100,200)>max(50,20))
|
||||
print("I'm useless statement just to show up the if/else\n");
|
||||
else
|
||||
print("squirrel!!\n");
|
||||
|
||||
print("\n")
|
||||
|
||||
function typy(obj)
|
||||
{
|
||||
switch(typeof obj)
|
||||
{
|
||||
case "integer":
|
||||
case "float":
|
||||
return "is a number";
|
||||
case "table":
|
||||
case "array":
|
||||
return "is a container";
|
||||
default:
|
||||
return "is other stuff"
|
||||
}
|
||||
}
|
||||
|
||||
local a=1,b={},c=function(a,b){return a+b;}
|
||||
|
||||
print("a "+typy(a)+"\n");
|
||||
print("b "+typy(b)+"\n");
|
||||
print("c "+typy(c)+"\n");
|
42
src/3rdparty/squirrel/samples/generators.nut
vendored
42
src/3rdparty/squirrel/samples/generators.nut
vendored
@@ -1,42 +0,0 @@
|
||||
/*
|
||||
*Random number function from The Great Computer Language shootout
|
||||
*converted to a generator func
|
||||
*/
|
||||
|
||||
function gen_random(max) {
|
||||
local last=42
|
||||
local IM = 139968;
|
||||
local IA = 3877;
|
||||
local IC = 29573;
|
||||
for(;;){ //loops forever
|
||||
yield (max * (last = (last * IA + IC) % IM) / IM);
|
||||
}
|
||||
}
|
||||
|
||||
local randtor=gen_random(100);
|
||||
|
||||
print("RAND NUMBERS \n")
|
||||
|
||||
for(local i=0;i<10;i+=1)
|
||||
print(">"+resume randtor+"\n");
|
||||
|
||||
print("FIBONACCI \n")
|
||||
function fiboz(n)
|
||||
{
|
||||
local prev=0;
|
||||
local curr=1;
|
||||
yield 1;
|
||||
|
||||
for(local i=0;i<n-1;i+=1)
|
||||
{
|
||||
local res=prev+curr;
|
||||
prev=curr;
|
||||
yield curr=res;
|
||||
}
|
||||
return prev+curr;
|
||||
}
|
||||
|
||||
foreach(val in fiboz(10))
|
||||
{
|
||||
::print(">"+val+"\n");
|
||||
}
|
1
src/3rdparty/squirrel/samples/hello.nut
vendored
1
src/3rdparty/squirrel/samples/hello.nut
vendored
@@ -1 +0,0 @@
|
||||
print("Hello World!")
|
39
src/3rdparty/squirrel/samples/list.nut
vendored
39
src/3rdparty/squirrel/samples/list.nut
vendored
@@ -1,39 +0,0 @@
|
||||
/*translation of the list test from The Great Computer Language Shootout
|
||||
*/
|
||||
|
||||
function compare_arr(a1,a2)
|
||||
{
|
||||
foreach(i,val in a1)
|
||||
if(val!=a2[i])return null;
|
||||
return 1;
|
||||
}
|
||||
|
||||
function test()
|
||||
{
|
||||
local size=10000
|
||||
local l1=[]; l1.resize(size);
|
||||
for(local i=0;i<size;i+=1) l1[i]=i;
|
||||
local l2=clone l1;
|
||||
local l3=[]
|
||||
|
||||
l2.reverse();
|
||||
while(l2.len()>0)
|
||||
l3.append(l2.pop());
|
||||
while(l3.len()>0)
|
||||
l2.append(l3.pop());
|
||||
l1.reverse();
|
||||
|
||||
if(compare_arr(l1,l2))
|
||||
return l1.len();
|
||||
return null;
|
||||
}
|
||||
|
||||
local n = ARGS.len()!=0?ARGS[0].tointeger():1
|
||||
for(local i=0;i<n;i+=1)
|
||||
if(!test())
|
||||
{
|
||||
print("failed");
|
||||
return;
|
||||
}
|
||||
|
||||
print("oki doki");
|
32
src/3rdparty/squirrel/samples/loops.nut
vendored
32
src/3rdparty/squirrel/samples/loops.nut
vendored
@@ -1,32 +0,0 @@
|
||||
local arr=["one","two","three"]
|
||||
|
||||
::print("FOREACH\n");
|
||||
|
||||
foreach(i,val in arr)
|
||||
{
|
||||
::print("index ["+i+"]="+val+"\n");
|
||||
}
|
||||
|
||||
::print("FOR\n");
|
||||
|
||||
for(local i=0;i<arr.len();i+=1)
|
||||
{
|
||||
::print("index ["+i+"]="+arr[i]+"\n");
|
||||
}
|
||||
|
||||
::print("WHILE\n");
|
||||
|
||||
local i=0;
|
||||
while(i<arr.len())
|
||||
{
|
||||
::print("index ["+i+"]="+arr[i]+"\n");
|
||||
i+=1;
|
||||
}
|
||||
::print("DO WHILE\n");
|
||||
|
||||
local i=0;
|
||||
do
|
||||
{
|
||||
::print("index ["+i+"]="+arr[i]+"\n");
|
||||
i+=1;
|
||||
}while(i<arr.len());
|
44
src/3rdparty/squirrel/samples/matrix.nut
vendored
44
src/3rdparty/squirrel/samples/matrix.nut
vendored
@@ -1,44 +0,0 @@
|
||||
/*
|
||||
*
|
||||
* Original Javascript version by David Hedbor(http://www.bagley.org/~doug/shootout/)
|
||||
*
|
||||
*/
|
||||
local SIZE=30;
|
||||
|
||||
function mkmatrix(rows, cols) {
|
||||
local i, j, count = 1;
|
||||
local m = []; m.resize(rows);
|
||||
for (i = 0; i < rows; i+=1) {
|
||||
m[i] = [];m[i].resize(cols)
|
||||
for (j = 0; j < cols; j+=1) {
|
||||
m[i][j] = count+=1;
|
||||
}
|
||||
}
|
||||
return m;
|
||||
}
|
||||
|
||||
function mmult(rows, cols, m1, m2, m3) {
|
||||
local i, j, k, val;
|
||||
for (i = 0; i < rows; i+=1) {
|
||||
for (j = 0; j < cols; j+=1) {
|
||||
val = 0;
|
||||
for (k = 0; k < cols; k+=1) {
|
||||
val += m1[i][k] * m2[k][j];
|
||||
}
|
||||
m3[i][j] = val;
|
||||
}
|
||||
}
|
||||
return m3;
|
||||
}
|
||||
|
||||
local n = ARGS.len()!=0?ARGS[0].tointeger():1
|
||||
|
||||
local m1 = mkmatrix(SIZE, SIZE);
|
||||
local m2 = mkmatrix(SIZE, SIZE);
|
||||
local mm = mkmatrix(SIZE, SIZE);
|
||||
|
||||
for (local i = 0; i < n; i+=1) {
|
||||
mmult(SIZE, SIZE, m1, m2, mm);
|
||||
}
|
||||
|
||||
print(mm[0][0]+" "+mm[2][3]+" "+mm[3][2]+" "+mm[4][4]);
|
115
src/3rdparty/squirrel/samples/metamethods.nut
vendored
115
src/3rdparty/squirrel/samples/metamethods.nut
vendored
@@ -1,115 +0,0 @@
|
||||
|
||||
local base_vec={
|
||||
function _add(n)
|
||||
{
|
||||
return {
|
||||
x=x+n.x,
|
||||
y=y+n.y,
|
||||
z=z+n.z,
|
||||
}
|
||||
}
|
||||
function _sub(n)
|
||||
{
|
||||
return {
|
||||
x=x-n.x,
|
||||
y=y-n.y,
|
||||
z=z-n.z,
|
||||
}
|
||||
}
|
||||
function _div(n)
|
||||
{
|
||||
return {
|
||||
x=x/n.x,
|
||||
y=y/n.y,
|
||||
z=z/n.z,
|
||||
}
|
||||
}
|
||||
function _mul(n)
|
||||
{
|
||||
return {
|
||||
x=x*n.x,
|
||||
y=y*n.y,
|
||||
z=z*n.z,
|
||||
}
|
||||
}
|
||||
function _modulo(n)
|
||||
{
|
||||
return {
|
||||
x=x%n,
|
||||
y=y%n,
|
||||
z=z%n,
|
||||
}
|
||||
}
|
||||
function _typeof() {return "vector";}
|
||||
function _get(key)
|
||||
{
|
||||
if(key==100)
|
||||
{
|
||||
return test_field;
|
||||
}
|
||||
},
|
||||
function _set(key,val)
|
||||
{
|
||||
::print("key = "+key+"\n");
|
||||
::print("val = "+val+"\n")
|
||||
if(key==100)
|
||||
{
|
||||
return test_field=val;
|
||||
}
|
||||
}
|
||||
test_field="nothing"
|
||||
}
|
||||
|
||||
function vector(_x,_y,_z):(base_vec)
|
||||
{
|
||||
return delegate base_vec : {x=_x,y=_y,z=_z }
|
||||
}
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
local v1=vector(1.5,2.5,3.5);
|
||||
local v2=vector(1.5,2.5,3.5);
|
||||
|
||||
local r=v1+v2;
|
||||
|
||||
|
||||
foreach(i,val in r)
|
||||
{
|
||||
print(i+" = "+val+"\n");
|
||||
}
|
||||
|
||||
r=v1*v2;
|
||||
|
||||
foreach(i,val in r)
|
||||
{
|
||||
print(i+" = "+val+"\n");
|
||||
}
|
||||
|
||||
r=v1/v2;
|
||||
|
||||
foreach(i,val in r)
|
||||
{
|
||||
print(i+" = "+val+"\n");
|
||||
}
|
||||
|
||||
r=v1-v2;
|
||||
|
||||
foreach(i,val in r)
|
||||
{
|
||||
print(i+" = "+val+"\n");
|
||||
}
|
||||
|
||||
r=v1%2;
|
||||
|
||||
foreach(i,val in r)
|
||||
{
|
||||
print(i+" = "+val+"\n");
|
||||
}
|
||||
|
||||
print(v1[100]+"\n");
|
||||
v1[100]="set SUCCEEDED";
|
||||
print(v1[100]+"\n");
|
||||
|
||||
if(typeof v1=="vector")
|
||||
print("<SUCCEEDED>\n");
|
||||
else
|
||||
print("<FAILED>\n");
|
61
src/3rdparty/squirrel/samples/methcall.nut
vendored
61
src/3rdparty/squirrel/samples/methcall.nut
vendored
@@ -1,61 +0,0 @@
|
||||
/*translation of the methcall test from The Great Computer Language Shootout
|
||||
*/
|
||||
|
||||
Toggle <- {
|
||||
bool=null
|
||||
}
|
||||
|
||||
function Toggle::value() {
|
||||
return bool;
|
||||
}
|
||||
|
||||
function Toggle::activate() {
|
||||
bool = !bool;
|
||||
return this;
|
||||
}
|
||||
|
||||
function Toggle::new(startstate) {
|
||||
local newo=clone this;
|
||||
newo.bool = startstate;
|
||||
return newo;
|
||||
}
|
||||
|
||||
NthToggle <- {
|
||||
count_max=null
|
||||
count=0
|
||||
}
|
||||
|
||||
function NthToggle::new(start_state,max_counter)
|
||||
{
|
||||
local newo=delegate ::Toggle.new(start_state) : clone this;
|
||||
newo.count_max <- max_counter
|
||||
return newo;
|
||||
}
|
||||
|
||||
function NthToggle::activate ()
|
||||
{
|
||||
count+=1
|
||||
if (count >= count_max) {
|
||||
bool = !bool;
|
||||
count = 0;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
local n = ARGS.len()!=0?ARGS[0].tointeger():1
|
||||
|
||||
local val = 1;
|
||||
local toggle = Toggle.new(val);
|
||||
for (local i=0; i<n; i+=1) {
|
||||
val = toggle.activate().value();
|
||||
|
||||
}
|
||||
print(toggle.value() ? "true\n" : "false\n");
|
||||
|
||||
val = 1;
|
||||
local ntoggle = NthToggle.new(val, 3);
|
||||
for (local i=0; i<n; i+=1) {
|
||||
val = ntoggle.activate().value();
|
||||
}
|
||||
print(ntoggle.value() ? "true\n" : "false\n");
|
24
src/3rdparty/squirrel/samples/tailstate.nut
vendored
24
src/3rdparty/squirrel/samples/tailstate.nut
vendored
@@ -1,24 +0,0 @@
|
||||
function state1()
|
||||
{
|
||||
::suspend("state1");
|
||||
return state2();
|
||||
}
|
||||
|
||||
function state2()
|
||||
{
|
||||
::suspend("state2");
|
||||
return state3();
|
||||
}
|
||||
|
||||
function state3()
|
||||
{
|
||||
::suspend("state3");
|
||||
return state1();
|
||||
}
|
||||
|
||||
local statethread = ::newthread(state1)
|
||||
|
||||
::print(statethread.call()+"\n");
|
||||
|
||||
for(local i = 0; i < 10000; i++)
|
||||
::print(statethread.wakeup()+"\n");
|
24
src/3rdparty/squirrel/sq/Makefile
vendored
24
src/3rdparty/squirrel/sq/Makefile
vendored
@@ -1,24 +0,0 @@
|
||||
SQUIRREL= ..
|
||||
|
||||
|
||||
OUT= $(SQUIRREL)/bin/sq
|
||||
INCZ= -I$(SQUIRREL)/include -I. -I$(SQUIRREL)/sqlibs
|
||||
LIBZ= -L$(SQUIRREL)/lib
|
||||
LIB= -lsquirrel -lsqstdlib
|
||||
|
||||
OBJS= sq.o
|
||||
|
||||
SRCS= sq.c
|
||||
|
||||
|
||||
sq32:
|
||||
g++ -O2 -fno-rtti -o $(OUT) $(SRCS) $(INCZ) $(LIBZ) $(LIB)
|
||||
|
||||
sqprof:
|
||||
g++ -O2 -pg -fno-rtti -pie -gstabs -g3 -o $(OUT) $(SRCS) $(INCZ) $(LIBZ) $(LIB)
|
||||
|
||||
sq64:
|
||||
g++ -O2 -fno-rtti -D_SQ64 -o $(OUT) $(SRCS) $(INCZ) $(LIBZ) $(LIB)
|
||||
|
||||
clean:
|
||||
rm -f $(OUT)
|
324
src/3rdparty/squirrel/sq/sq.c
vendored
324
src/3rdparty/squirrel/sq/sq.c
vendored
@@ -1,324 +0,0 @@
|
||||
/* see copyright notice in squirrel.h */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#if defined(_MSC_VER) && defined(_DEBUG)
|
||||
#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>
|
||||
|
||||
#ifdef SQUNICODE
|
||||
#define scfprintf fwprintf
|
||||
#define scfopen _wfopen
|
||||
#define scvprintf vwprintf
|
||||
#else
|
||||
#define scfprintf fprintf
|
||||
#define scfopen fopen
|
||||
#define scvprintf vprintf
|
||||
#endif
|
||||
|
||||
|
||||
void PrintVersionInfos();
|
||||
|
||||
#if defined(_MSC_VER) && defined(_DEBUG)
|
||||
int MemAllocHook( int allocType, void *userData, size_t size, int blockType,
|
||||
long requestNumber, const unsigned char *filename, int lineNumber)
|
||||
{
|
||||
// if(requestNumber==585)_asm int 3;
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
SQInteger quit(HSQUIRRELVM v)
|
||||
{
|
||||
int *done;
|
||||
sq_getuserpointer(v,-1,(SQUserPointer*)&done);
|
||||
*done=1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void printfunc(HSQUIRRELVM v,const SQChar *s,...)
|
||||
{
|
||||
va_list vl;
|
||||
va_start(vl, s);
|
||||
scvprintf( s, vl);
|
||||
va_end(vl);
|
||||
}
|
||||
|
||||
void PrintVersionInfos()
|
||||
{
|
||||
scfprintf(stdout,_SC("%s %s (%d bits)\n"),SQUIRREL_VERSION,SQUIRREL_COPYRIGHT,sizeof(SQInteger)*8);
|
||||
if(sizeof(SQFloat) != sizeof(float)) {
|
||||
scfprintf(stdout,_SC("[%d bits floats]\n"),sizeof(SQFloat)*8);
|
||||
}
|
||||
}
|
||||
|
||||
void PrintUsage()
|
||||
{
|
||||
scfprintf(stderr,_SC("usage: sq <options> <scriptpath [args]>.\n")
|
||||
_SC("Available options are:\n")
|
||||
_SC(" -c compiles the file to bytecode(default output 'out.cnut')\n")
|
||||
_SC(" -o specifies output file for the -c option\n")
|
||||
_SC(" -c compiles only\n")
|
||||
_SC(" -d generates debug infos\n")
|
||||
_SC(" -v displays version infos\n")
|
||||
_SC(" -h prints help\n"));
|
||||
}
|
||||
|
||||
#define _INTERACTIVE 0
|
||||
#define _DONE 2
|
||||
//<<FIXME>> this func is a mess
|
||||
int getargs(HSQUIRRELVM v,int argc, char* argv[])
|
||||
{
|
||||
int i;
|
||||
int compiles_only = 0;
|
||||
static SQChar temp[500];
|
||||
const SQChar *ret=NULL;
|
||||
char * output = NULL;
|
||||
int lineinfo=0;
|
||||
if(argc>1)
|
||||
{
|
||||
int arg=1,exitloop=0;
|
||||
while(arg < argc && !exitloop)
|
||||
{
|
||||
|
||||
if(argv[arg][0]=='-')
|
||||
{
|
||||
switch(argv[arg][1])
|
||||
{
|
||||
case 'd': //DEBUG(debug infos)
|
||||
sq_enabledebuginfo(v,1);
|
||||
break;
|
||||
case 'c':
|
||||
compiles_only = 1;
|
||||
break;
|
||||
case 'o':
|
||||
if(arg < argc) {
|
||||
arg++;
|
||||
output = argv[arg];
|
||||
}
|
||||
break;
|
||||
case 'v':
|
||||
PrintVersionInfos();
|
||||
return _DONE;
|
||||
|
||||
case 'h':
|
||||
PrintVersionInfos();
|
||||
PrintUsage();
|
||||
return _DONE;
|
||||
default:
|
||||
PrintVersionInfos();
|
||||
scprintf(_SC("unknown prameter '-%c'\n"),argv[arg][1]);
|
||||
PrintUsage();
|
||||
return _DONE;
|
||||
}
|
||||
}else break;
|
||||
arg++;
|
||||
}
|
||||
|
||||
// src file
|
||||
|
||||
if(arg<argc) {
|
||||
const SQChar *filename=NULL;
|
||||
#ifdef SQUNICODE
|
||||
mbstowcs(temp,argv[arg],strlen(argv[arg]));
|
||||
filename=temp;
|
||||
#else
|
||||
filename=argv[arg];
|
||||
#endif
|
||||
|
||||
arg++;
|
||||
sq_pushroottable(v);
|
||||
sq_pushstring(v,_SC("ARGS"),-1);
|
||||
sq_newarray(v,0);
|
||||
for(i=arg;i<argc;i++)
|
||||
{
|
||||
const SQChar *a;
|
||||
#ifdef SQUNICODE
|
||||
int alen=(int)strlen(argv[i]);
|
||||
a=sq_getscratchpad(v,(int)(alen*sizeof(SQChar)));
|
||||
mbstowcs(sq_getscratchpad(v,-1),argv[i],alen);
|
||||
sq_getscratchpad(v,-1)[alen] = _SC('\0');
|
||||
#else
|
||||
a=argv[i];
|
||||
#endif
|
||||
sq_pushstring(v,a,-1);
|
||||
|
||||
sq_arrayappend(v,-2);
|
||||
}
|
||||
sq_createslot(v,-3);
|
||||
sq_pop(v,1);
|
||||
if(compiles_only) {
|
||||
if(SQ_SUCCEEDED(sqstd_loadfile(v,filename,SQTrue))){
|
||||
SQChar *outfile = _SC("out.cnut");
|
||||
if(output) {
|
||||
#ifdef SQUNICODE
|
||||
int len = (int)(strlen(output)+1);
|
||||
mbstowcs(sq_getscratchpad(v,len*sizeof(SQChar)),output,len);
|
||||
outfile = sq_getscratchpad(v,-1);
|
||||
#else
|
||||
outfile = output;
|
||||
#endif
|
||||
}
|
||||
if(SQ_SUCCEEDED(sqstd_writeclosuretofile(v,outfile)))
|
||||
return _DONE;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(SQ_SUCCEEDED(sqstd_dofile(v,filename,SQFalse,SQTrue))) {
|
||||
return _DONE;
|
||||
}
|
||||
}
|
||||
//if this point is reached an error occured
|
||||
{
|
||||
const SQChar *err;
|
||||
sq_getlasterror(v);
|
||||
if(SQ_SUCCEEDED(sq_getstring(v,-1,&err))) {
|
||||
scprintf(_SC("Error [%s]\n"),err);
|
||||
return _DONE;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return _INTERACTIVE;
|
||||
}
|
||||
|
||||
void Interactive(HSQUIRRELVM v)
|
||||
{
|
||||
|
||||
#define MAXINPUT 1024
|
||||
SQChar buffer[MAXINPUT];
|
||||
SQInteger blocks =0;
|
||||
SQInteger string=0;
|
||||
SQInteger retval=0;
|
||||
SQInteger done=0;
|
||||
PrintVersionInfos();
|
||||
|
||||
sq_pushroottable(v);
|
||||
sq_pushstring(v,_SC("quit"),-1);
|
||||
sq_pushuserpointer(v,&done);
|
||||
sq_newclosure(v,quit,1);
|
||||
sq_setparamscheck(v,1,NULL);
|
||||
sq_createslot(v,-3);
|
||||
sq_pop(v,1);
|
||||
|
||||
while (!done)
|
||||
{
|
||||
SQInteger i = 0;
|
||||
scprintf(_SC("\nsq>"));
|
||||
for(;;) {
|
||||
int c;
|
||||
if(done)return;
|
||||
c = getchar();
|
||||
if (c == _SC('\n')) {
|
||||
if (i>0 && buffer[i-1] == _SC('\\'))
|
||||
{
|
||||
buffer[i-1] = _SC('\n');
|
||||
}
|
||||
else if(blocks==0)break;
|
||||
buffer[i++] = _SC('\n');
|
||||
}
|
||||
else if (c==_SC('}')) {blocks--; buffer[i++] = (SQChar)c;}
|
||||
else if(c==_SC('{') && !string){
|
||||
blocks++;
|
||||
buffer[i++] = (SQChar)c;
|
||||
}
|
||||
else if(c==_SC('"') || c==_SC('\'')){
|
||||
string=!string;
|
||||
buffer[i++] = (SQChar)c;
|
||||
}
|
||||
else if (i >= MAXINPUT-1) {
|
||||
scfprintf(stderr, _SC("sq : input line too long\n"));
|
||||
break;
|
||||
}
|
||||
else{
|
||||
buffer[i++] = (SQChar)c;
|
||||
}
|
||||
}
|
||||
buffer[i] = _SC('\0');
|
||||
|
||||
if(buffer[0]==_SC('=')){
|
||||
scsprintf(sq_getscratchpad(v,MAXINPUT),_SC("return (%s)"),&buffer[1]);
|
||||
memcpy(buffer,sq_getscratchpad(v,-1),(scstrlen(sq_getscratchpad(v,-1))+1)*sizeof(SQChar));
|
||||
retval=1;
|
||||
}
|
||||
i=scstrlen(buffer);
|
||||
if(i>0){
|
||||
SQInteger oldtop=sq_gettop(v);
|
||||
if(SQ_SUCCEEDED(sq_compilebuffer(v,buffer,i,_SC("interactive console"),SQTrue))){
|
||||
sq_pushroottable(v);
|
||||
if(SQ_SUCCEEDED(sq_call(v,1,retval,SQTrue)) && retval){
|
||||
scprintf(_SC("\n"));
|
||||
sq_pushroottable(v);
|
||||
sq_pushstring(v,_SC("print"),-1);
|
||||
sq_get(v,-2);
|
||||
sq_pushroottable(v);
|
||||
sq_push(v,-4);
|
||||
sq_call(v,2,SQFalse,SQTrue);
|
||||
retval=0;
|
||||
scprintf(_SC("\n"));
|
||||
}
|
||||
}
|
||||
|
||||
sq_settop(v,oldtop);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
HSQUIRRELVM v;
|
||||
|
||||
const SQChar *filename=NULL;
|
||||
#if defined(_MSC_VER) && defined(_DEBUG)
|
||||
_CrtSetAllocHook(MemAllocHook);
|
||||
#endif
|
||||
|
||||
v=sq_open(1024);
|
||||
sq_setprintfunc(v,printfunc);
|
||||
|
||||
sq_pushroottable(v);
|
||||
|
||||
sqstd_register_bloblib(v);
|
||||
sqstd_register_iolib(v);
|
||||
sqstd_register_systemlib(v);
|
||||
sqstd_register_mathlib(v);
|
||||
sqstd_register_stringlib(v);
|
||||
|
||||
//aux library
|
||||
//sets error handlers
|
||||
sqstd_seterrorhandlers(v);
|
||||
|
||||
//gets arguments
|
||||
switch(getargs(v,argc,argv))
|
||||
{
|
||||
case _INTERACTIVE:
|
||||
Interactive(v);
|
||||
break;
|
||||
case _DONE:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
sq_close(v);
|
||||
|
||||
#if defined(_MSC_VER) && defined(_DEBUG)
|
||||
_getch();
|
||||
_CrtMemDumpAllObjectsSince( NULL );
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
101
src/3rdparty/squirrel/sq/sq.dsp
vendored
101
src/3rdparty/squirrel/sq/sq.dsp
vendored
@@ -1,101 +0,0 @@
|
||||
# Microsoft Developer Studio Project File - Name="sq" - Package Owner=<4>
|
||||
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||
# ** DO NOT EDIT **
|
||||
|
||||
# TARGTYPE "Win32 (x86) Console Application" 0x0103
|
||||
|
||||
CFG=sq - Win32 Debug
|
||||
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||
!MESSAGE use the Export Makefile command and run
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "sq.mak".
|
||||
!MESSAGE
|
||||
!MESSAGE You can specify a configuration when running NMAKE
|
||||
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "sq.mak" CFG="sq - Win32 Debug"
|
||||
!MESSAGE
|
||||
!MESSAGE Possible choices for configuration are:
|
||||
!MESSAGE
|
||||
!MESSAGE "sq - Win32 Release" (based on "Win32 (x86) Console Application")
|
||||
!MESSAGE "sq - Win32 Debug" (based on "Win32 (x86) Console Application")
|
||||
!MESSAGE
|
||||
|
||||
# Begin Project
|
||||
# PROP AllowPerConfigDependencies 0
|
||||
# PROP Scc_LocalPath ".."
|
||||
CPP=cl.exe
|
||||
RSC=rc.exe
|
||||
|
||||
!IF "$(CFG)" == "sq - Win32 Release"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "Release"
|
||||
# PROP BASE Intermediate_Dir "Release"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "Release"
|
||||
# PROP Intermediate_Dir "Release"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||
# ADD CPP /nologo /W3 /GX /O2 /I "..\include" /I "..\sqstdlib" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||
# ADD BASE RSC /l 0x410 /d "NDEBUG"
|
||||
# ADD RSC /l 0x410 /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
|
||||
# ADD LINK32 squirrel.lib sqstdlib.lib /nologo /subsystem:console /machine:I386 /out:"../bin/sq.exe" /libpath:"../lib"
|
||||
|
||||
!ELSEIF "$(CFG)" == "sq - Win32 Debug"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 1
|
||||
# PROP BASE Output_Dir "Debug"
|
||||
# PROP BASE Intermediate_Dir "Debug"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 1
|
||||
# PROP Output_Dir "Debug"
|
||||
# PROP Intermediate_Dir "Debug"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
|
||||
# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I "..\include" /I "..\sqstdlib" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
|
||||
# ADD BASE RSC /l 0x410 /d "_DEBUG"
|
||||
# ADD RSC /l 0x410 /d "_DEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
|
||||
# ADD LINK32 squirrel.lib sqstdlib.lib /nologo /subsystem:console /debug /machine:I386 /out:"../bin/sq.exe" /pdbtype:sept /libpath:"../lib"
|
||||
|
||||
!ENDIF
|
||||
|
||||
# Begin Target
|
||||
|
||||
# Name "sq - Win32 Release"
|
||||
# Name "sq - Win32 Debug"
|
||||
# Begin Group "Source Files"
|
||||
|
||||
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\sq.c
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Header Files"
|
||||
|
||||
# PROP Default_Filter "h;hpp;hxx;hm;inl"
|
||||
# End Group
|
||||
# Begin Group "Resource Files"
|
||||
|
||||
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
|
||||
# End Group
|
||||
# End Target
|
||||
# End Project
|
31
src/3rdparty/squirrel/sqstdlib/Makefile
vendored
31
src/3rdparty/squirrel/sqstdlib/Makefile
vendored
@@ -1,31 +0,0 @@
|
||||
SQUIRREL= ..
|
||||
|
||||
|
||||
OUT= $(SQUIRREL)/lib/libsqstdlib.a
|
||||
INCZ= -I$(SQUIRREL)/include -I. -Iinclude
|
||||
|
||||
SRCS= \
|
||||
sqstdblob.cpp \
|
||||
sqstdio.cpp \
|
||||
sqstdstream.cpp \
|
||||
sqstdmath.cpp \
|
||||
sqstdsystem.cpp \
|
||||
sqstdstring.cpp \
|
||||
sqstdaux.cpp \
|
||||
sqstdrex.cpp
|
||||
|
||||
|
||||
sq32:
|
||||
gcc -O2 -fno-rtti -Wall -c $(SRCS) $(INCZ)
|
||||
ar rc $(OUT) *.o
|
||||
|
||||
sqprof:
|
||||
gcc -O2 -pg -fno-rtti -pie -gstabs -g3 -Wall -c $(SRCS) $(INCZ)
|
||||
ar rc $(OUT) *.o
|
||||
|
||||
sq64:
|
||||
gcc -O2 -D_SQ64 -fno-rtti -Wall -c $(SRCS) $(INCZ)
|
||||
ar rc $(OUT) *.o
|
||||
|
||||
clean:
|
||||
rm -f $(OUT) $(SRCS:%.cpp=%.o)
|
59
src/3rdparty/squirrel/sqstdlib/sqstdaux.cpp
vendored
59
src/3rdparty/squirrel/sqstdlib/sqstdaux.cpp
vendored
@@ -1,8 +1,11 @@
|
||||
/* see copyright notice in squirrel.h */
|
||||
|
||||
#include "../../../stdafx.h"
|
||||
|
||||
#include <squirrel.h>
|
||||
#include <sqstdaux.h>
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "../../../safeguards.h"
|
||||
|
||||
void sqstd_printcallstack(HSQUIRRELVM v)
|
||||
{
|
||||
@@ -16,30 +19,30 @@ void sqstd_printcallstack(HSQUIRRELVM v)
|
||||
SQInteger level=1; //1 is to skip this function that is level 0
|
||||
const SQChar *name=0;
|
||||
SQInteger seq=0;
|
||||
pf(v,_SC("\nCALLSTACK\n"));
|
||||
pf(v,"\nCALLSTACK\n");
|
||||
while(SQ_SUCCEEDED(sq_stackinfos(v,level,&si)))
|
||||
{
|
||||
const SQChar *fn=_SC("unknown");
|
||||
const SQChar *src=_SC("unknown");
|
||||
const SQChar *fn="unknown";
|
||||
const SQChar *src="unknown";
|
||||
if(si.funcname)fn=si.funcname;
|
||||
if(si.source) {
|
||||
/* We don't want to bother users with absolute paths to all AI files.
|
||||
* Since the path only reaches NoAI code in a formatted string we have
|
||||
* to strip it here. Let's hope nobody installs openttd in a subdirectory
|
||||
* of a directory named /ai/. */
|
||||
src = scstrstr(si.source, _SC("\\ai\\"));
|
||||
if (!src) src = scstrstr(si.source, _SC("/ai/"));
|
||||
src = strstr(si.source, "\\ai\\");
|
||||
if (!src) src = strstr(si.source, "/ai/");
|
||||
if (src) {
|
||||
src += 4;
|
||||
} else {
|
||||
src = si.source;
|
||||
}
|
||||
}
|
||||
pf(v,_SC("*FUNCTION [%s()] %s line [%d]\n"),fn,src,si.line);
|
||||
pf(v,"*FUNCTION [%s()] %s line [%d]\n",fn,src,si.line);
|
||||
level++;
|
||||
}
|
||||
level=0;
|
||||
pf(v,_SC("\nLOCALS\n"));
|
||||
pf(v,"\nLOCALS\n");
|
||||
|
||||
for(level=0;level<10;level++){
|
||||
seq=0;
|
||||
@@ -49,56 +52,56 @@ void sqstd_printcallstack(HSQUIRRELVM v)
|
||||
switch(sq_gettype(v,-1))
|
||||
{
|
||||
case OT_NULL:
|
||||
pf(v,_SC("[%s] NULL\n"),name);
|
||||
pf(v,"[%s] NULL\n",name);
|
||||
break;
|
||||
case OT_INTEGER:
|
||||
sq_getinteger(v,-1,&i);
|
||||
pf(v,_SC("[%s] %d\n"),name,i);
|
||||
pf(v,"[%s] %d\n",name,i);
|
||||
break;
|
||||
case OT_FLOAT:
|
||||
sq_getfloat(v,-1,&f);
|
||||
pf(v,_SC("[%s] %.14g\n"),name,f);
|
||||
pf(v,"[%s] %.14g\n",name,f);
|
||||
break;
|
||||
case OT_USERPOINTER:
|
||||
pf(v,_SC("[%s] USERPOINTER\n"),name);
|
||||
pf(v,"[%s] USERPOINTER\n",name);
|
||||
break;
|
||||
case OT_STRING:
|
||||
sq_getstring(v,-1,&s);
|
||||
pf(v,_SC("[%s] \"%s\"\n"),name,s);
|
||||
pf(v,"[%s] \"%s\"\n",name,s);
|
||||
break;
|
||||
case OT_TABLE:
|
||||
pf(v,_SC("[%s] TABLE\n"),name);
|
||||
pf(v,"[%s] TABLE\n",name);
|
||||
break;
|
||||
case OT_ARRAY:
|
||||
pf(v,_SC("[%s] ARRAY\n"),name);
|
||||
pf(v,"[%s] ARRAY\n",name);
|
||||
break;
|
||||
case OT_CLOSURE:
|
||||
pf(v,_SC("[%s] CLOSURE\n"),name);
|
||||
pf(v,"[%s] CLOSURE\n",name);
|
||||
break;
|
||||
case OT_NATIVECLOSURE:
|
||||
pf(v,_SC("[%s] NATIVECLOSURE\n"),name);
|
||||
pf(v,"[%s] NATIVECLOSURE\n",name);
|
||||
break;
|
||||
case OT_GENERATOR:
|
||||
pf(v,_SC("[%s] GENERATOR\n"),name);
|
||||
pf(v,"[%s] GENERATOR\n",name);
|
||||
break;
|
||||
case OT_USERDATA:
|
||||
pf(v,_SC("[%s] USERDATA\n"),name);
|
||||
pf(v,"[%s] USERDATA\n",name);
|
||||
break;
|
||||
case OT_THREAD:
|
||||
pf(v,_SC("[%s] THREAD\n"),name);
|
||||
pf(v,"[%s] THREAD\n",name);
|
||||
break;
|
||||
case OT_CLASS:
|
||||
pf(v,_SC("[%s] CLASS\n"),name);
|
||||
pf(v,"[%s] CLASS\n",name);
|
||||
break;
|
||||
case OT_INSTANCE:
|
||||
pf(v,_SC("[%s] INSTANCE\n"),name);
|
||||
pf(v,"[%s] INSTANCE\n",name);
|
||||
break;
|
||||
case OT_WEAKREF:
|
||||
pf(v,_SC("[%s] WEAKREF\n"),name);
|
||||
pf(v,"[%s] WEAKREF\n",name);
|
||||
break;
|
||||
case OT_BOOL:{
|
||||
sq_getbool(v,-1,&b);
|
||||
pf(v,_SC("[%s] %s\n"),name,b?_SC("true"):_SC("false"));
|
||||
pf(v,"[%s] %s\n",name,b?"true":"false");
|
||||
}
|
||||
break;
|
||||
default: assert(0); break;
|
||||
@@ -116,10 +119,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,"\nAN ERROR HAS OCCURED [%s]\n",sErr);
|
||||
}
|
||||
else{
|
||||
pf(v,_SC("\nAN ERROR HAS OCCURED [unknown]\n"));
|
||||
pf(v,"\nAN ERROR HAS OCCURED [unknown]\n");
|
||||
}
|
||||
sqstd_printcallstack(v);
|
||||
}
|
||||
@@ -131,7 +134,7 @@ void _sqstd_compiler_error(HSQUIRRELVM v,const SQChar *sErr,const SQChar *sSourc
|
||||
{
|
||||
SQPRINTFUNCTION pf = sq_getprintfunc(v);
|
||||
if(pf) {
|
||||
pf(v,_SC("%s line = (%d) column = (%d) : error %s\n"),sSource,line,column,sErr);
|
||||
pf(v,"%s line = (%d) column = (%d) : error %s\n",sSource,line,column,sErr);
|
||||
}
|
||||
}
|
||||
|
||||
|
251
src/3rdparty/squirrel/sqstdlib/sqstdblob.cpp
vendored
251
src/3rdparty/squirrel/sqstdlib/sqstdblob.cpp
vendored
@@ -1,251 +0,0 @@
|
||||
/* see copyright notice in squirrel.h */
|
||||
#include <new>
|
||||
#include <squirrel.h>
|
||||
#include <sqstdio.h>
|
||||
#include <string.h>
|
||||
#include <sqstdblob.h>
|
||||
#include "sqstdstream.h"
|
||||
#include "sqstdblobimpl.h"
|
||||
|
||||
#define SQSTD_BLOB_TYPE_TAG (SQSTD_STREAM_TYPE_TAG | 0x00000002)
|
||||
|
||||
//Blob
|
||||
|
||||
|
||||
#define SETUP_BLOB(v) \
|
||||
SQBlob *self = NULL; \
|
||||
{ if(SQ_FAILED(sq_getinstanceup(v,1,(SQUserPointer*)&self,(SQUserPointer)SQSTD_BLOB_TYPE_TAG))) \
|
||||
return SQ_ERROR; }
|
||||
|
||||
|
||||
static SQInteger _blob_resize(HSQUIRRELVM v)
|
||||
{
|
||||
SETUP_BLOB(v);
|
||||
SQInteger size;
|
||||
sq_getinteger(v,2,&size);
|
||||
if(!self->Resize(size))
|
||||
return sq_throwerror(v,_SC("resize failed"));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void __swap_dword(unsigned int *n)
|
||||
{
|
||||
*n=(unsigned int)(((*n&0xFF000000)>>24) |
|
||||
((*n&0x00FF0000)>>8) |
|
||||
((*n&0x0000FF00)<<8) |
|
||||
((*n&0x000000FF)<<24));
|
||||
}
|
||||
|
||||
static void __swap_word(unsigned short *n)
|
||||
{
|
||||
*n=(unsigned short)((*n>>8)&0x00FF)| ((*n<<8)&0xFF00);
|
||||
}
|
||||
|
||||
static SQInteger _blob_swap4(HSQUIRRELVM v)
|
||||
{
|
||||
SETUP_BLOB(v);
|
||||
SQInteger num=(self->Len()-(self->Len()%4))>>2;
|
||||
unsigned int *t=(unsigned int *)self->GetBuf();
|
||||
for(SQInteger i = 0; i < num; i++) {
|
||||
__swap_dword(&t[i]);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static SQInteger _blob_swap2(HSQUIRRELVM v)
|
||||
{
|
||||
SETUP_BLOB(v);
|
||||
SQInteger num=(self->Len()-(self->Len()%2))>>1;
|
||||
unsigned short *t = (unsigned short *)self->GetBuf();
|
||||
for(SQInteger i = 0; i < num; i++) {
|
||||
__swap_word(&t[i]);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static SQInteger _blob__set(HSQUIRRELVM v)
|
||||
{
|
||||
SETUP_BLOB(v);
|
||||
SQInteger idx,val;
|
||||
sq_getinteger(v,2,&idx);
|
||||
sq_getinteger(v,3,&val);
|
||||
if(idx < 0 || idx >= self->Len())
|
||||
return sq_throwerror(v,_SC("index out of range"));
|
||||
((unsigned char *)self->GetBuf())[idx] = (unsigned char) val;
|
||||
sq_push(v,3);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static SQInteger _blob__get(HSQUIRRELVM v)
|
||||
{
|
||||
SETUP_BLOB(v);
|
||||
SQInteger idx;
|
||||
sq_getinteger(v,2,&idx);
|
||||
if(idx < 0 || idx >= self->Len())
|
||||
return sq_throwerror(v,_SC("index out of range"));
|
||||
sq_pushinteger(v,((unsigned char *)self->GetBuf())[idx]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static SQInteger _blob__nexti(HSQUIRRELVM v)
|
||||
{
|
||||
SETUP_BLOB(v);
|
||||
if(sq_gettype(v,2) == OT_NULL) {
|
||||
sq_pushinteger(v, 0);
|
||||
return 1;
|
||||
}
|
||||
SQInteger idx;
|
||||
if(SQ_SUCCEEDED(sq_getinteger(v, 2, &idx))) {
|
||||
if(idx+1 < self->Len()) {
|
||||
sq_pushinteger(v, idx+1);
|
||||
return 1;
|
||||
}
|
||||
sq_pushnull(v);
|
||||
return 1;
|
||||
}
|
||||
return sq_throwerror(v,_SC("internal error (_nexti) wrong argument type"));
|
||||
}
|
||||
|
||||
static SQInteger _blob__typeof(HSQUIRRELVM v)
|
||||
{
|
||||
sq_pushstring(v,_SC("blob"),-1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static SQInteger _blob_releasehook(SQUserPointer p, SQInteger size)
|
||||
{
|
||||
SQBlob *self = (SQBlob*)p;
|
||||
delete self;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static SQInteger _blob_constructor(HSQUIRRELVM v)
|
||||
{
|
||||
SQInteger nparam = sq_gettop(v);
|
||||
SQInteger size = 0;
|
||||
if(nparam == 2) {
|
||||
sq_getinteger(v, 2, &size);
|
||||
}
|
||||
if(size < 0) return sq_throwerror(v, _SC("cannot create blob with negative size"));
|
||||
SQBlob *b = new SQBlob(size);
|
||||
if(SQ_FAILED(sq_setinstanceup(v,1,b))) {
|
||||
delete b;
|
||||
return sq_throwerror(v, _SC("cannot create blob with negative size"));
|
||||
}
|
||||
sq_setreleasehook(v,1,_blob_releasehook);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define _DECL_BLOB_FUNC(name,nparams,typecheck) {_SC(#name),_blob_##name,nparams,typecheck}
|
||||
static SQRegFunction _blob_methods[] = {
|
||||
_DECL_BLOB_FUNC(constructor,-1,_SC("xn")),
|
||||
_DECL_BLOB_FUNC(resize,2,_SC("xn")),
|
||||
_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(_typeof,1,_SC("x")),
|
||||
_DECL_BLOB_FUNC(_nexti,2,_SC("x")),
|
||||
{0,0,0,0}
|
||||
};
|
||||
|
||||
|
||||
|
||||
//GLOBAL FUNCTIONS
|
||||
|
||||
static SQInteger _g_blob_casti2f(HSQUIRRELVM v)
|
||||
{
|
||||
SQInteger i;
|
||||
sq_getinteger(v,2,&i);
|
||||
sq_pushfloat(v,*((SQFloat *)&i));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static SQInteger _g_blob_castf2i(HSQUIRRELVM v)
|
||||
{
|
||||
SQFloat f;
|
||||
sq_getfloat(v,2,&f);
|
||||
sq_pushinteger(v,*((SQInteger *)&f));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static SQInteger _g_blob_swap2(HSQUIRRELVM v)
|
||||
{
|
||||
SQInteger i;
|
||||
sq_getinteger(v,2,&i);
|
||||
short s=(short)i;
|
||||
sq_pushinteger(v,(s<<8)|((s>>8)&0x00FF));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static SQInteger _g_blob_swap4(HSQUIRRELVM v)
|
||||
{
|
||||
SQInteger i;
|
||||
sq_getinteger(v,2,&i);
|
||||
unsigned int t4 = (unsigned int)i;
|
||||
__swap_dword(&t4);
|
||||
sq_pushinteger(v,(SQInteger)t4);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static SQInteger _g_blob_swapfloat(HSQUIRRELVM v)
|
||||
{
|
||||
SQFloat f;
|
||||
sq_getfloat(v,2,&f);
|
||||
__swap_dword((unsigned int *)&f);
|
||||
sq_pushfloat(v,f);
|
||||
return 1;
|
||||
}
|
||||
|
||||
#define _DECL_GLOBALBLOB_FUNC(name,nparams,typecheck) {_SC(#name),_g_blob_##name,nparams,typecheck}
|
||||
static SQRegFunction bloblib_funcs[]={
|
||||
_DECL_GLOBALBLOB_FUNC(casti2f,2,_SC(".n")),
|
||||
_DECL_GLOBALBLOB_FUNC(castf2i,2,_SC(".n")),
|
||||
_DECL_GLOBALBLOB_FUNC(swap2,2,_SC(".n")),
|
||||
_DECL_GLOBALBLOB_FUNC(swap4,2,_SC(".n")),
|
||||
_DECL_GLOBALBLOB_FUNC(swapfloat,2,_SC(".n")),
|
||||
{0,0,0,0}
|
||||
};
|
||||
|
||||
SQRESULT sqstd_getblob(HSQUIRRELVM v,SQInteger idx,SQUserPointer *ptr)
|
||||
{
|
||||
SQBlob *blob;
|
||||
if(SQ_FAILED(sq_getinstanceup(v,idx,(SQUserPointer *)&blob,(SQUserPointer)SQSTD_BLOB_TYPE_TAG)))
|
||||
return -1;
|
||||
*ptr = blob->GetBuf();
|
||||
return SQ_OK;
|
||||
}
|
||||
|
||||
SQInteger sqstd_getblobsize(HSQUIRRELVM v,SQInteger idx)
|
||||
{
|
||||
SQBlob *blob;
|
||||
if(SQ_FAILED(sq_getinstanceup(v,idx,(SQUserPointer *)&blob,(SQUserPointer)SQSTD_BLOB_TYPE_TAG)))
|
||||
return -1;
|
||||
return blob->Len();
|
||||
}
|
||||
|
||||
SQUserPointer sqstd_createblob(HSQUIRRELVM v, SQInteger size)
|
||||
{
|
||||
SQInteger top = sq_gettop(v);
|
||||
sq_pushregistrytable(v);
|
||||
sq_pushstring(v,_SC("std_blob"),-1);
|
||||
if(SQ_SUCCEEDED(sq_get(v,-2))) {
|
||||
sq_remove(v,-2); //removes the registry
|
||||
sq_push(v,1); // push the this
|
||||
sq_pushinteger(v,size); //size
|
||||
SQBlob *blob = NULL;
|
||||
if(SQ_SUCCEEDED(sq_call(v,2,SQTrue,SQFalse))
|
||||
&& SQ_SUCCEEDED(sq_getinstanceup(v,-1,(SQUserPointer *)&blob,(SQUserPointer)SQSTD_BLOB_TYPE_TAG))) {
|
||||
sq_remove(v,-2);
|
||||
return blob->GetBuf();
|
||||
}
|
||||
}
|
||||
sq_settop(v,top);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SQRESULT sqstd_register_bloblib(HSQUIRRELVM v)
|
||||
{
|
||||
return declare_stream(v,_SC("blob"),(SQUserPointer)SQSTD_BLOB_TYPE_TAG,_SC("std_blob"),_blob_methods,bloblib_funcs);
|
||||
}
|
||||
|
108
src/3rdparty/squirrel/sqstdlib/sqstdblobimpl.h
vendored
108
src/3rdparty/squirrel/sqstdlib/sqstdblobimpl.h
vendored
@@ -1,108 +0,0 @@
|
||||
/* see copyright notice in squirrel.h */
|
||||
#ifndef _SQSTD_BLOBIMPL_H_
|
||||
#define _SQSTD_BLOBIMPL_H_
|
||||
|
||||
struct SQBlob : public SQStream
|
||||
{
|
||||
SQBlob(SQInteger size) {
|
||||
_size = size;
|
||||
_allocated = size;
|
||||
_buf = (unsigned char *)sq_malloc(size);
|
||||
memset(_buf, 0, _size);
|
||||
_ptr = 0;
|
||||
_owns = true;
|
||||
}
|
||||
virtual ~SQBlob() {
|
||||
sq_free(_buf, _allocated);
|
||||
}
|
||||
SQInteger Write(void *buffer, SQInteger size) {
|
||||
if(!CanAdvance(size)) {
|
||||
GrowBufOf(_ptr + size - _size);
|
||||
}
|
||||
memcpy(&_buf[_ptr], buffer, size);
|
||||
_ptr += size;
|
||||
return size;
|
||||
}
|
||||
SQInteger Read(void *buffer,SQInteger size) {
|
||||
SQInteger n = size;
|
||||
if(!CanAdvance(size)) {
|
||||
if((_size - _ptr) > 0)
|
||||
n = _size - _ptr;
|
||||
else return 0;
|
||||
}
|
||||
memcpy(buffer, &_buf[_ptr], n);
|
||||
_ptr += n;
|
||||
return n;
|
||||
}
|
||||
bool Resize(SQInteger n) {
|
||||
if(!_owns) return false;
|
||||
if(n != _allocated) {
|
||||
unsigned char *newbuf = (unsigned char *)sq_malloc(n);
|
||||
memset(newbuf,0,n);
|
||||
if(_size > n)
|
||||
memcpy(newbuf,_buf,n);
|
||||
else
|
||||
memcpy(newbuf,_buf,_size);
|
||||
sq_free(_buf,_allocated);
|
||||
_buf=newbuf;
|
||||
_allocated = n;
|
||||
if(_size > _allocated)
|
||||
_size = _allocated;
|
||||
if(_ptr > _allocated)
|
||||
_ptr = _allocated;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
bool GrowBufOf(SQInteger n)
|
||||
{
|
||||
bool ret = true;
|
||||
if(_size + n > _allocated) {
|
||||
if(_size + n > _size * 2)
|
||||
ret = Resize(_size + n);
|
||||
else
|
||||
ret = Resize(_size * 2);
|
||||
}
|
||||
_size = _size + n;
|
||||
return ret;
|
||||
}
|
||||
bool CanAdvance(SQInteger n) {
|
||||
if(_ptr+n>_size)return false;
|
||||
return true;
|
||||
}
|
||||
SQInteger Seek(SQInteger offset, SQInteger origin) {
|
||||
switch(origin) {
|
||||
case SQ_SEEK_SET:
|
||||
if(offset > _size || offset < 0) return -1;
|
||||
_ptr = offset;
|
||||
break;
|
||||
case SQ_SEEK_CUR:
|
||||
if(_ptr + offset > _size || _ptr + offset < 0) return -1;
|
||||
_ptr += offset;
|
||||
break;
|
||||
case SQ_SEEK_END:
|
||||
if(_size + offset > _size || _size + offset < 0) return -1;
|
||||
_ptr = _size + offset;
|
||||
break;
|
||||
default: return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
bool IsValid() {
|
||||
return _buf?true:false;
|
||||
}
|
||||
bool EOS() {
|
||||
return _ptr == _size;
|
||||
}
|
||||
SQInteger Flush() { return 0; }
|
||||
SQInteger Tell() { return _ptr; }
|
||||
SQInteger Len() { return _size; }
|
||||
SQUserPointer GetBuf(){ return _buf; }
|
||||
private:
|
||||
SQInteger _size;
|
||||
SQInteger _allocated;
|
||||
SQInteger _ptr;
|
||||
unsigned char *_buf;
|
||||
bool _owns;
|
||||
};
|
||||
|
||||
#endif //_SQSTD_BLOBIMPL_H_
|
410
src/3rdparty/squirrel/sqstdlib/sqstdio.cpp
vendored
410
src/3rdparty/squirrel/sqstdlib/sqstdio.cpp
vendored
@@ -1,410 +0,0 @@
|
||||
/* see copyright notice in squirrel.h */
|
||||
#include <stdio.h>
|
||||
#include <squirrel.h>
|
||||
#include <new>
|
||||
#include <sqstdio.h>
|
||||
#include "sqstdstream.h"
|
||||
|
||||
#define SQSTD_FILE_TYPE_TAG (SQSTD_STREAM_TYPE_TAG | 0x00000001)
|
||||
//basic API
|
||||
SQFILE sqstd_fopen(const SQChar *filename ,const SQChar *mode)
|
||||
{
|
||||
#ifndef SQUNICODE
|
||||
return (SQFILE)fopen(filename,mode);
|
||||
#else
|
||||
return (SQFILE)_wfopen(filename,mode);
|
||||
#endif
|
||||
}
|
||||
|
||||
SQInteger sqstd_fread(void* buffer, SQInteger size, SQInteger count, SQFILE file)
|
||||
{
|
||||
return (SQInteger)fread(buffer,size,count,(FILE *)file);
|
||||
}
|
||||
|
||||
SQInteger sqstd_fwrite(const SQUserPointer buffer, SQInteger size, SQInteger count, SQFILE file)
|
||||
{
|
||||
return (SQInteger)fwrite(buffer,size,count,(FILE *)file);
|
||||
}
|
||||
|
||||
SQInteger sqstd_fseek(SQFILE file, SQInteger offset, SQInteger origin)
|
||||
{
|
||||
SQInteger realorigin;
|
||||
switch(origin) {
|
||||
case SQ_SEEK_CUR: realorigin = SEEK_CUR; break;
|
||||
case SQ_SEEK_END: realorigin = SEEK_END; break;
|
||||
case SQ_SEEK_SET: realorigin = SEEK_SET; break;
|
||||
default: return -1; //failed
|
||||
}
|
||||
return fseek((FILE *)file,(long)offset,(int)realorigin);
|
||||
}
|
||||
|
||||
SQInteger sqstd_ftell(SQFILE file)
|
||||
{
|
||||
return ftell((FILE *)file);
|
||||
}
|
||||
|
||||
SQInteger sqstd_fflush(SQFILE file)
|
||||
{
|
||||
return fflush((FILE *)file);
|
||||
}
|
||||
|
||||
SQInteger sqstd_fclose(SQFILE file)
|
||||
{
|
||||
return fclose((FILE *)file);
|
||||
}
|
||||
|
||||
SQInteger sqstd_feof(SQFILE file)
|
||||
{
|
||||
return feof((FILE *)file);
|
||||
}
|
||||
|
||||
//File
|
||||
struct SQFile : public SQStream {
|
||||
SQFile() { _handle = NULL; _owns = false;}
|
||||
SQFile(SQFILE file, bool owns) { _handle = file; _owns = owns;}
|
||||
virtual ~SQFile() { Close(); }
|
||||
bool Open(const SQChar *filename ,const SQChar *mode) {
|
||||
Close();
|
||||
if( (_handle = sqstd_fopen(filename,mode)) ) {
|
||||
_owns = true;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
void Close() {
|
||||
if(_handle && _owns) {
|
||||
sqstd_fclose(_handle);
|
||||
_handle = NULL;
|
||||
_owns = false;
|
||||
}
|
||||
}
|
||||
SQInteger Read(void *buffer,SQInteger size) {
|
||||
return sqstd_fread(buffer,1,size,_handle);
|
||||
}
|
||||
SQInteger Write(void *buffer,SQInteger size) {
|
||||
return sqstd_fwrite(buffer,1,size,_handle);
|
||||
}
|
||||
SQInteger Flush() {
|
||||
return sqstd_fflush(_handle);
|
||||
}
|
||||
SQInteger Tell() {
|
||||
return sqstd_ftell(_handle);
|
||||
}
|
||||
SQInteger Len() {
|
||||
SQInteger prevpos=Tell();
|
||||
Seek(0,SQ_SEEK_END);
|
||||
SQInteger size=Tell();
|
||||
Seek(prevpos,SQ_SEEK_SET);
|
||||
return size;
|
||||
}
|
||||
SQInteger Seek(SQInteger offset, SQInteger origin) {
|
||||
return sqstd_fseek(_handle,offset,origin);
|
||||
}
|
||||
bool IsValid() { return _handle?true:false; }
|
||||
bool EOS() { return Tell()==Len()?true:false;}
|
||||
SQFILE GetHandle() {return _handle;}
|
||||
private:
|
||||
SQFILE _handle;
|
||||
bool _owns;
|
||||
};
|
||||
|
||||
static SQInteger _file__typeof(HSQUIRRELVM v)
|
||||
{
|
||||
sq_pushstring(v,_SC("file"),-1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static SQInteger _file_releasehook(SQUserPointer p, SQInteger size)
|
||||
{
|
||||
SQFile *self = (SQFile*)p;
|
||||
delete self;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static SQInteger _file_constructor(HSQUIRRELVM v)
|
||||
{
|
||||
const SQChar *filename,*mode;
|
||||
bool owns = true;
|
||||
SQFile *f;
|
||||
SQFILE newf;
|
||||
if(sq_gettype(v,2) == OT_STRING && sq_gettype(v,3) == OT_STRING) {
|
||||
sq_getstring(v, 2, &filename);
|
||||
sq_getstring(v, 3, &mode);
|
||||
newf = sqstd_fopen(filename, mode);
|
||||
if(!newf) return sq_throwerror(v, _SC("cannot open file"));
|
||||
} else if(sq_gettype(v,2) == OT_USERPOINTER) {
|
||||
owns = !(sq_gettype(v,3) == OT_NULL);
|
||||
sq_getuserpointer(v,2,&newf);
|
||||
} else {
|
||||
return sq_throwerror(v,_SC("wrong parameter"));
|
||||
}
|
||||
f = new SQFile(newf,owns);
|
||||
if(SQ_FAILED(sq_setinstanceup(v,1,f))) {
|
||||
delete f;
|
||||
return sq_throwerror(v, _SC("cannot create blob with negative size"));
|
||||
}
|
||||
sq_setreleasehook(v,1,_file_releasehook);
|
||||
return 0;
|
||||
}
|
||||
|
||||
//bindings
|
||||
#define _DECL_FILE_FUNC(name,nparams,typecheck) {_SC(#name),_file_##name,nparams,typecheck}
|
||||
static SQRegFunction _file_methods[] = {
|
||||
_DECL_FILE_FUNC(constructor,3,_SC("x")),
|
||||
_DECL_FILE_FUNC(_typeof,1,_SC("x")),
|
||||
{0,0,0,0},
|
||||
};
|
||||
|
||||
|
||||
|
||||
SQRESULT sqstd_createfile(HSQUIRRELVM v, SQFILE file,SQBool own)
|
||||
{
|
||||
SQInteger top = sq_gettop(v);
|
||||
sq_pushregistrytable(v);
|
||||
sq_pushstring(v,_SC("std_file"),-1);
|
||||
if(SQ_SUCCEEDED(sq_get(v,-2))) {
|
||||
sq_remove(v,-2); //removes the registry
|
||||
sq_pushroottable(v); // push the this
|
||||
sq_pushuserpointer(v,file); //file
|
||||
if(own){
|
||||
sq_pushinteger(v,1); //true
|
||||
}
|
||||
else{
|
||||
sq_pushnull(v); //false
|
||||
}
|
||||
if(SQ_SUCCEEDED( sq_call(v,3,SQTrue,SQFalse) )) {
|
||||
sq_remove(v,-2);
|
||||
return SQ_OK;
|
||||
}
|
||||
}
|
||||
sq_settop(v,top);
|
||||
return SQ_OK;
|
||||
}
|
||||
|
||||
SQRESULT sqstd_getfile(HSQUIRRELVM v, SQInteger idx, SQFILE *file)
|
||||
{
|
||||
SQFile *fileobj = NULL;
|
||||
if(SQ_SUCCEEDED(sq_getinstanceup(v,idx,(SQUserPointer*)&fileobj,(SQUserPointer)SQSTD_FILE_TYPE_TAG))) {
|
||||
*file = fileobj->GetHandle();
|
||||
return SQ_OK;
|
||||
}
|
||||
return sq_throwerror(v,_SC("not a file"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
static SQInteger _io_file_lexfeed_ASCII(SQUserPointer file)
|
||||
{
|
||||
SQInteger ret;
|
||||
char c;
|
||||
if( ( ret=sqstd_fread(&c,sizeof(c),1,(FILE *)file )>0) )
|
||||
return c;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static SQInteger _io_file_lexfeed_UTF8(SQUserPointer file)
|
||||
{
|
||||
#define READ() \
|
||||
if(sqstd_fread(&inchar,sizeof(inchar),1,(FILE *)file) != 1) \
|
||||
return 0;
|
||||
|
||||
static const SQInteger utf8_lengths[16] =
|
||||
{
|
||||
1,1,1,1,1,1,1,1, /* 0000 to 0111 : 1 byte (plain ASCII) */
|
||||
0,0,0,0, /* 1000 to 1011 : not valid */
|
||||
2,2, /* 1100, 1101 : 2 bytes */
|
||||
3, /* 1110 : 3 bytes */
|
||||
4 /* 1111 :4 bytes */
|
||||
};
|
||||
static unsigned char byte_masks[5] = {0,0,0x1f,0x0f,0x07};
|
||||
unsigned char inchar;
|
||||
SQInteger c = 0;
|
||||
READ();
|
||||
c = inchar;
|
||||
//
|
||||
if(c >= 0x80) {
|
||||
SQInteger tmp;
|
||||
SQInteger codelen = utf8_lengths[c>>4];
|
||||
if(codelen == 0)
|
||||
return 0;
|
||||
//"invalid UTF-8 stream";
|
||||
tmp = c&byte_masks[codelen];
|
||||
for(SQInteger n = 0; n < codelen-1; n++) {
|
||||
tmp<<=6;
|
||||
READ();
|
||||
tmp |= inchar & 0x3F;
|
||||
}
|
||||
c = tmp;
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
static SQInteger _io_file_lexfeed_UCS2_LE(SQUserPointer file)
|
||||
{
|
||||
SQInteger ret;
|
||||
wchar_t c;
|
||||
if( ( ret=sqstd_fread(&c,sizeof(c),1,(FILE *)file )>0) )
|
||||
return (SQChar)c;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static SQInteger _io_file_lexfeed_UCS2_BE(SQUserPointer file)
|
||||
{
|
||||
SQInteger ret;
|
||||
unsigned short c;
|
||||
if( ( ret=sqstd_fread(&c,sizeof(c),1,(FILE *)file )>0) ) {
|
||||
c = ((c>>8)&0x00FF)| ((c<<8)&0xFF00);
|
||||
return (SQChar)c;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
SQInteger file_read(SQUserPointer file,SQUserPointer buf,SQInteger size)
|
||||
{
|
||||
SQInteger ret;
|
||||
if( ( ret = sqstd_fread(buf,1,size,(SQFILE)file ))!=0 )return ret;
|
||||
return -1;
|
||||
}
|
||||
|
||||
SQInteger file_write(SQUserPointer file,SQUserPointer p,SQInteger size)
|
||||
{
|
||||
return sqstd_fwrite(p,1,size,(SQFILE)file);
|
||||
}
|
||||
|
||||
SQRESULT sqstd_loadfile(HSQUIRRELVM v,const SQChar *filename,SQBool printerror)
|
||||
{
|
||||
SQFILE file = sqstd_fopen(filename,_SC("rb"));
|
||||
SQInteger ret;
|
||||
unsigned short us;
|
||||
unsigned char uc;
|
||||
SQLEXREADFUNC func = _io_file_lexfeed_ASCII;
|
||||
if(file){
|
||||
ret = sqstd_fread(&us,1,2,file);
|
||||
if(ret != 2) {
|
||||
//probably an empty file
|
||||
us = 0;
|
||||
}
|
||||
if(us == SQ_BYTECODE_STREAM_TAG) { //BYTECODE
|
||||
sqstd_fseek(file,0,SQ_SEEK_SET);
|
||||
if(SQ_SUCCEEDED(sq_readclosure(v,file_read,file))) {
|
||||
sqstd_fclose(file);
|
||||
return SQ_OK;
|
||||
}
|
||||
}
|
||||
else { //SCRIPT
|
||||
switch(us)
|
||||
{
|
||||
//gotta swap the next 2 lines on BIG endian machines
|
||||
case 0xFFFE: func = _io_file_lexfeed_UCS2_BE; break;//UTF-16 little endian;
|
||||
case 0xFEFF: func = _io_file_lexfeed_UCS2_LE; break;//UTF-16 big endian;
|
||||
case 0xBBEF:
|
||||
if(sqstd_fread(&uc,1,sizeof(uc),file) == 0) {
|
||||
sqstd_fclose(file);
|
||||
return sq_throwerror(v,_SC("io error"));
|
||||
}
|
||||
if(uc != 0xBF) {
|
||||
sqstd_fclose(file);
|
||||
return sq_throwerror(v,_SC("Unrecognozed ecoding"));
|
||||
}
|
||||
func = _io_file_lexfeed_UTF8;
|
||||
break;//UTF-8 ;
|
||||
default: sqstd_fseek(file,0,SQ_SEEK_SET); break; // ascii
|
||||
}
|
||||
|
||||
if(SQ_SUCCEEDED(sq_compile(v,func,file,filename,printerror))){
|
||||
sqstd_fclose(file);
|
||||
return SQ_OK;
|
||||
}
|
||||
}
|
||||
sqstd_fclose(file);
|
||||
return SQ_ERROR;
|
||||
}
|
||||
return sq_throwerror(v,_SC("cannot open the file"));
|
||||
}
|
||||
|
||||
SQRESULT sqstd_dofile(HSQUIRRELVM v,const SQChar *filename,SQBool retval,SQBool printerror)
|
||||
{
|
||||
if(SQ_SUCCEEDED(sqstd_loadfile(v,filename,printerror))) {
|
||||
sq_push(v,-2);
|
||||
if(SQ_SUCCEEDED(sq_call(v,1,retval,SQTrue))) {
|
||||
sq_remove(v,retval?-2:-1); //removes the closure
|
||||
return 1;
|
||||
}
|
||||
sq_pop(v,1); //removes the closure
|
||||
}
|
||||
return SQ_ERROR;
|
||||
}
|
||||
|
||||
SQRESULT sqstd_writeclosuretofile(HSQUIRRELVM v,const SQChar *filename)
|
||||
{
|
||||
SQFILE file = sqstd_fopen(filename,_SC("wb+"));
|
||||
if(!file) return sq_throwerror(v,_SC("cannot open the file"));
|
||||
if(SQ_SUCCEEDED(sq_writeclosure(v,file_write,file))) {
|
||||
sqstd_fclose(file);
|
||||
return SQ_OK;
|
||||
}
|
||||
sqstd_fclose(file);
|
||||
return SQ_ERROR; //forward the error
|
||||
}
|
||||
|
||||
SQInteger _g_io_loadfile(HSQUIRRELVM v)
|
||||
{
|
||||
const SQChar *filename;
|
||||
SQBool printerror = SQFalse;
|
||||
sq_getstring(v,2,&filename);
|
||||
if(sq_gettop(v) >= 3) {
|
||||
sq_getbool(v,3,&printerror);
|
||||
}
|
||||
if(SQ_SUCCEEDED(sqstd_loadfile(v,filename,printerror)))
|
||||
return 1;
|
||||
return SQ_ERROR; //propagates the error
|
||||
}
|
||||
|
||||
SQInteger _g_io_writeclosuretofile(HSQUIRRELVM v)
|
||||
{
|
||||
const SQChar *filename;
|
||||
sq_getstring(v,2,&filename);
|
||||
if(SQ_SUCCEEDED(sqstd_writeclosuretofile(v,filename)))
|
||||
return 1;
|
||||
return SQ_ERROR; //propagates the error
|
||||
}
|
||||
|
||||
SQInteger _g_io_dofile(HSQUIRRELVM v)
|
||||
{
|
||||
const SQChar *filename;
|
||||
SQBool printerror = SQFalse;
|
||||
sq_getstring(v,2,&filename);
|
||||
if(sq_gettop(v) >= 3) {
|
||||
sq_getbool(v,3,&printerror);
|
||||
}
|
||||
sq_push(v,1); //repush the this
|
||||
if(SQ_SUCCEEDED(sqstd_dofile(v,filename,SQTrue,printerror)))
|
||||
return 1;
|
||||
return SQ_ERROR; //propagates the error
|
||||
}
|
||||
|
||||
#define _DECL_GLOBALIO_FUNC(name,nparams,typecheck) {_SC(#name),_g_io_##name,nparams,typecheck}
|
||||
static SQRegFunction iolib_funcs[]={
|
||||
_DECL_GLOBALIO_FUNC(loadfile,-2,_SC(".sb")),
|
||||
_DECL_GLOBALIO_FUNC(dofile,-2,_SC(".sb")),
|
||||
_DECL_GLOBALIO_FUNC(writeclosuretofile,3,_SC(".sc")),
|
||||
{0,0,0,0}
|
||||
};
|
||||
|
||||
SQRESULT sqstd_register_iolib(HSQUIRRELVM v)
|
||||
{
|
||||
SQInteger top = sq_gettop(v);
|
||||
//create delegate
|
||||
declare_stream(v,_SC("file"),(SQUserPointer)SQSTD_FILE_TYPE_TAG,_SC("std_file"),_file_methods,iolib_funcs);
|
||||
sq_pushstring(v,_SC("stdout"),-1);
|
||||
sqstd_createfile(v,stdout,SQFalse);
|
||||
sq_createslot(v,-3);
|
||||
sq_pushstring(v,_SC("stdin"),-1);
|
||||
sqstd_createfile(v,stdin,SQFalse);
|
||||
sq_createslot(v,-3);
|
||||
sq_pushstring(v,_SC("stderr"),-1);
|
||||
sqstd_createfile(v,stderr,SQFalse);
|
||||
sq_createslot(v,-3);
|
||||
sq_settop(v,top);
|
||||
return SQ_OK;
|
||||
}
|
131
src/3rdparty/squirrel/sqstdlib/sqstdlib.dsp
vendored
131
src/3rdparty/squirrel/sqstdlib/sqstdlib.dsp
vendored
@@ -1,131 +0,0 @@
|
||||
# Microsoft Developer Studio Project File - Name="sqstdlib" - Package Owner=<4>
|
||||
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||
# ** DO NOT EDIT **
|
||||
|
||||
# TARGTYPE "Win32 (x86) Static Library" 0x0104
|
||||
|
||||
CFG=sqstdlib - Win32 Release
|
||||
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||
!MESSAGE use the Export Makefile command and run
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "sqstdlib.mak".
|
||||
!MESSAGE
|
||||
!MESSAGE You can specify a configuration when running NMAKE
|
||||
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "sqstdlib.mak" CFG="sqstdlib - Win32 Release"
|
||||
!MESSAGE
|
||||
!MESSAGE Possible choices for configuration are:
|
||||
!MESSAGE
|
||||
!MESSAGE "sqstdlib - Win32 Release" (based on "Win32 (x86) Static Library")
|
||||
!MESSAGE "sqstdlib - Win32 Debug" (based on "Win32 (x86) Static Library")
|
||||
!MESSAGE
|
||||
|
||||
# Begin Project
|
||||
# PROP AllowPerConfigDependencies 0
|
||||
# PROP Scc_LocalPath ".."
|
||||
CPP=cl.exe
|
||||
RSC=rc.exe
|
||||
|
||||
!IF "$(CFG)" == "sqstdlib - Win32 Release"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "Release"
|
||||
# PROP BASE Intermediate_Dir "Release"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "Release"
|
||||
# PROP Intermediate_Dir "Release"
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c
|
||||
# ADD CPP /nologo /W3 /GX /O2 /I "..\include" /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c
|
||||
# ADD BASE RSC /l 0x410 /d "NDEBUG"
|
||||
# ADD RSC /l 0x410 /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LIB32=link.exe -lib
|
||||
# ADD BASE LIB32 /nologo
|
||||
# ADD LIB32 /nologo /out:"..\lib\sqstdlib.lib"
|
||||
|
||||
!ELSEIF "$(CFG)" == "sqstdlib - Win32 Debug"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 1
|
||||
# PROP BASE Output_Dir "Debug"
|
||||
# PROP BASE Intermediate_Dir "Debug"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 1
|
||||
# PROP Output_Dir "Debug"
|
||||
# PROP Intermediate_Dir "Debug"
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c
|
||||
# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I "..\include" /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c
|
||||
# ADD BASE RSC /l 0x410 /d "_DEBUG"
|
||||
# ADD RSC /l 0x410 /d "_DEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LIB32=link.exe -lib
|
||||
# ADD BASE LIB32 /nologo
|
||||
# ADD LIB32 /nologo /out:"..\lib\sqstdlib.lib"
|
||||
|
||||
!ENDIF
|
||||
|
||||
# Begin Target
|
||||
|
||||
# Name "sqstdlib - Win32 Release"
|
||||
# Name "sqstdlib - Win32 Debug"
|
||||
# Begin Group "Source Files"
|
||||
|
||||
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\sqstdblob.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\sqstdio.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\sqstdmath.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\sqstdrex.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\sqstdstream.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\sqstdstring.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\sqstdaux.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\sqstdsystem.cpp
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Header Files"
|
||||
|
||||
# PROP Default_Filter "h;hpp;hxx;hm;inl"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\sqstdblobimpl.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\sqstdstream.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# End Target
|
||||
# End Project
|
48
src/3rdparty/squirrel/sqstdlib/sqstdmath.cpp
vendored
48
src/3rdparty/squirrel/sqstdlib/sqstdmath.cpp
vendored
@@ -1,9 +1,13 @@
|
||||
/* see copyright notice in squirrel.h */
|
||||
|
||||
#include "../../../stdafx.h"
|
||||
|
||||
#include <squirrel.h>
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
#include <sqstdmath.h>
|
||||
|
||||
#include "../../../safeguards.h"
|
||||
|
||||
#define SINGLE_ARG_FUNC(_funcname, num_ops) static SQInteger math_##_funcname(HSQUIRRELVM v){ \
|
||||
SQFloat f; \
|
||||
sq_decreaseops(v,num_ops); \
|
||||
@@ -26,7 +30,7 @@ static SQInteger math_srand(HSQUIRRELVM v)
|
||||
{
|
||||
SQInteger i;
|
||||
if(SQ_FAILED(sq_getinteger(v,2,&i)))
|
||||
return sq_throwerror(v,_SC("invalid param"));
|
||||
return sq_throwerror(v,"invalid param");
|
||||
srand((unsigned int)i);
|
||||
return 0;
|
||||
}
|
||||
@@ -62,28 +66,28 @@ SINGLE_ARG_FUNC(floor, 1)
|
||||
SINGLE_ARG_FUNC(ceil, 1)
|
||||
SINGLE_ARG_FUNC(exp, 100)
|
||||
|
||||
#define _DECL_FUNC(name,nparams,tycheck) {_SC(#name),math_##name,nparams,tycheck}
|
||||
#define _DECL_FUNC(name,nparams,tycheck) {#name,math_##name,nparams,tycheck}
|
||||
static SQRegFunction mathlib_funcs[] = {
|
||||
_DECL_FUNC(sqrt,2,_SC(".n")),
|
||||
_DECL_FUNC(sin,2,_SC(".n")),
|
||||
_DECL_FUNC(cos,2,_SC(".n")),
|
||||
_DECL_FUNC(asin,2,_SC(".n")),
|
||||
_DECL_FUNC(acos,2,_SC(".n")),
|
||||
_DECL_FUNC(log,2,_SC(".n")),
|
||||
_DECL_FUNC(log10,2,_SC(".n")),
|
||||
_DECL_FUNC(tan,2,_SC(".n")),
|
||||
_DECL_FUNC(atan,2,_SC(".n")),
|
||||
_DECL_FUNC(atan2,3,_SC(".nn")),
|
||||
_DECL_FUNC(pow,3,_SC(".nn")),
|
||||
_DECL_FUNC(floor,2,_SC(".n")),
|
||||
_DECL_FUNC(ceil,2,_SC(".n")),
|
||||
_DECL_FUNC(exp,2,_SC(".n")),
|
||||
_DECL_FUNC(sqrt,2,".n"),
|
||||
_DECL_FUNC(sin,2,".n"),
|
||||
_DECL_FUNC(cos,2,".n"),
|
||||
_DECL_FUNC(asin,2,".n"),
|
||||
_DECL_FUNC(acos,2,".n"),
|
||||
_DECL_FUNC(log,2,".n"),
|
||||
_DECL_FUNC(log10,2,".n"),
|
||||
_DECL_FUNC(tan,2,".n"),
|
||||
_DECL_FUNC(atan,2,".n"),
|
||||
_DECL_FUNC(atan2,3,".nn"),
|
||||
_DECL_FUNC(pow,3,".nn"),
|
||||
_DECL_FUNC(floor,2,".n"),
|
||||
_DECL_FUNC(ceil,2,".n"),
|
||||
_DECL_FUNC(exp,2,".n"),
|
||||
#ifdef EXPORT_DEFAULT_SQUIRREL_FUNCTIONS
|
||||
_DECL_FUNC(srand,2,_SC(".n")),
|
||||
_DECL_FUNC(srand,2,".n"),
|
||||
_DECL_FUNC(rand,1,NULL),
|
||||
#endif /* EXPORT_DEFAULT_SQUIRREL_FUNCTIONS */
|
||||
_DECL_FUNC(fabs,2,_SC(".n")),
|
||||
_DECL_FUNC(abs,2,_SC(".n")),
|
||||
_DECL_FUNC(fabs,2,".n"),
|
||||
_DECL_FUNC(abs,2,".n"),
|
||||
{0,0,0,0},
|
||||
};
|
||||
|
||||
@@ -103,11 +107,11 @@ SQRESULT sqstd_register_mathlib(HSQUIRRELVM v)
|
||||
i++;
|
||||
}
|
||||
#ifdef EXPORT_DEFAULT_SQUIRREL_FUNCTIONS
|
||||
sq_pushstring(v,_SC("RAND_MAX"),-1);
|
||||
sq_pushstring(v,"RAND_MAX",-1);
|
||||
sq_pushinteger(v,RAND_MAX);
|
||||
sq_createslot(v,-3);
|
||||
#endif /* EXPORT_DEFAULT_SQUIRREL_FUNCTIONS */
|
||||
sq_pushstring(v,_SC("PI"),-1);
|
||||
sq_pushstring(v,"PI",-1);
|
||||
sq_pushfloat(v,(SQFloat)M_PI);
|
||||
sq_createslot(v,-3);
|
||||
return SQ_OK;
|
||||
|
57
src/3rdparty/squirrel/sqstdlib/sqstdrex.cpp
vendored
57
src/3rdparty/squirrel/sqstdlib/sqstdrex.cpp
vendored
@@ -1,7 +1,5 @@
|
||||
/* see copyright notice in squirrel.h */
|
||||
#include <squirrel.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <exception>
|
||||
#include "sqstdstring.h"
|
||||
|
||||
@@ -12,14 +10,13 @@
|
||||
#endif
|
||||
|
||||
#ifdef _DEBUG
|
||||
#include <stdio.h>
|
||||
|
||||
static const SQChar *g_nnames[] =
|
||||
{
|
||||
_SC("NONE"),_SC("OP_GREEDY"), _SC("OP_OR"),
|
||||
_SC("OP_EXPR"),_SC("OP_NOCAPEXPR"),_SC("OP_DOT"), _SC("OP_CLASS"),
|
||||
_SC("OP_CCLASS"),_SC("OP_NCLASS"),_SC("OP_RANGE"),_SC("OP_CHAR"),
|
||||
_SC("OP_EOL"),_SC("OP_BOL"),_SC("OP_WB")
|
||||
"NONE","OP_GREEDY", "OP_OR",
|
||||
"OP_EXPR","OP_NOCAPEXPR","OP_DOT", "OP_CLASS",
|
||||
"OP_CCLASS","OP_NCLASS","OP_RANGE","OP_CHAR",
|
||||
"OP_EOL","OP_BOL","OP_WB"
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -99,7 +96,7 @@ static void sqstd_rex_error(SQRex *exp,const SQChar *error)
|
||||
|
||||
static void sqstd_rex_expect(SQRex *exp, SQChar n){
|
||||
if((*exp->_p) != n)
|
||||
sqstd_rex_error(exp, _SC("expected paren"));
|
||||
sqstd_rex_error(exp, "expected paren");
|
||||
exp->_p++;
|
||||
}
|
||||
|
||||
@@ -115,7 +112,7 @@ static SQChar sqstd_rex_escapechar(SQRex *exp)
|
||||
case 'f': exp->_p++; return '\f';
|
||||
default: return (*exp->_p++);
|
||||
}
|
||||
} else if(!scisprint(*exp->_p)) sqstd_rex_error(exp,_SC("letter expected"));
|
||||
} else if(!scisprint(*exp->_p)) sqstd_rex_error(exp,"letter expected");
|
||||
return (*exp->_p++);
|
||||
}
|
||||
|
||||
@@ -159,7 +156,7 @@ static SQInteger sqstd_rex_charnode(SQRex *exp,SQBool isclass)
|
||||
}
|
||||
else if(!scisprint(*exp->_p)) {
|
||||
|
||||
sqstd_rex_error(exp,_SC("letter expected"));
|
||||
sqstd_rex_error(exp,"letter expected");
|
||||
}
|
||||
t = *exp->_p; exp->_p++;
|
||||
return sqstd_rex_newnode(exp,t);
|
||||
@@ -173,15 +170,15 @@ static SQInteger sqstd_rex_class(SQRex *exp)
|
||||
exp->_p++;
|
||||
}else ret = sqstd_rex_newnode(exp,OP_CLASS);
|
||||
|
||||
if(*exp->_p == ']') sqstd_rex_error(exp,_SC("empty class"));
|
||||
if(*exp->_p == ']') sqstd_rex_error(exp,"empty class");
|
||||
chain = ret;
|
||||
while(*exp->_p != ']' && exp->_p != exp->_eol) {
|
||||
if(*exp->_p == '-' && first != -1){
|
||||
SQInteger r;
|
||||
if(*exp->_p++ == ']') sqstd_rex_error(exp,_SC("unfinished range"));
|
||||
if(*exp->_p++ == ']') sqstd_rex_error(exp,"unfinished range");
|
||||
r = sqstd_rex_newnode(exp,OP_RANGE);
|
||||
if(exp->_nodes[first].type>*exp->_p) sqstd_rex_error(exp,_SC("invalid range"));
|
||||
if(exp->_nodes[first].type == OP_CCLASS) sqstd_rex_error(exp,_SC("cannot use character classes in ranges"));
|
||||
if(exp->_nodes[first].type>*exp->_p) sqstd_rex_error(exp,"invalid range");
|
||||
if(exp->_nodes[first].type == OP_CCLASS) sqstd_rex_error(exp,"cannot use character classes in ranges");
|
||||
exp->_nodes[r].left = exp->_nodes[first].type;
|
||||
SQInteger t = sqstd_rex_escapechar(exp);
|
||||
exp->_nodes[r].right = t;
|
||||
@@ -220,7 +217,7 @@ static SQInteger sqstd_rex_parsenumber(SQRex *exp)
|
||||
exp->_p++;
|
||||
while(isdigit(*exp->_p)) {
|
||||
ret = ret*10+(*exp->_p++-'0');
|
||||
if(positions==1000000000) sqstd_rex_error(exp,_SC("overflow in numeric constant"));
|
||||
if(positions==1000000000) sqstd_rex_error(exp,"overflow in numeric constant");
|
||||
positions *= 10;
|
||||
};
|
||||
return ret;
|
||||
@@ -238,7 +235,7 @@ static SQInteger sqstd_rex_element(SQRex *exp)
|
||||
|
||||
if(*exp->_p =='?') {
|
||||
exp->_p++;
|
||||
sqstd_rex_expect(exp,_SC(':'));
|
||||
sqstd_rex_expect(exp,':');
|
||||
expr = sqstd_rex_newnode(exp,OP_NOCAPEXPR);
|
||||
}
|
||||
else
|
||||
@@ -246,13 +243,13 @@ static SQInteger sqstd_rex_element(SQRex *exp)
|
||||
SQInteger newn = sqstd_rex_list(exp);
|
||||
exp->_nodes[expr].left = newn;
|
||||
ret = expr;
|
||||
sqstd_rex_expect(exp,_SC(')'));
|
||||
sqstd_rex_expect(exp,')');
|
||||
}
|
||||
break;
|
||||
case '[':
|
||||
exp->_p++;
|
||||
ret = sqstd_rex_class(exp);
|
||||
sqstd_rex_expect(exp,_SC(']'));
|
||||
sqstd_rex_expect(exp,']');
|
||||
break;
|
||||
case SQREX_SYMBOL_END_OF_STRING: exp->_p++; ret = sqstd_rex_newnode(exp,OP_EOL);break;
|
||||
case SQREX_SYMBOL_ANY_CHAR: exp->_p++; ret = sqstd_rex_newnode(exp,OP_DOT);break;
|
||||
@@ -271,7 +268,7 @@ static SQInteger sqstd_rex_element(SQRex *exp)
|
||||
case SQREX_SYMBOL_GREEDY_ZERO_OR_ONE: p0 = 0; p1 = 1; exp->_p++; isgreedy = SQTrue; break;
|
||||
case '{':
|
||||
exp->_p++;
|
||||
if(!isdigit(*exp->_p)) sqstd_rex_error(exp,_SC("number expected"));
|
||||
if(!isdigit(*exp->_p)) sqstd_rex_error(exp,"number expected");
|
||||
p0 = (unsigned short)sqstd_rex_parsenumber(exp);
|
||||
/*******************************/
|
||||
switch(*exp->_p) {
|
||||
@@ -284,10 +281,10 @@ static SQInteger sqstd_rex_element(SQRex *exp)
|
||||
if(isdigit(*exp->_p)){
|
||||
p1 = (unsigned short)sqstd_rex_parsenumber(exp);
|
||||
}
|
||||
sqstd_rex_expect(exp,_SC('}'));
|
||||
sqstd_rex_expect(exp,'}');
|
||||
break;
|
||||
default:
|
||||
sqstd_rex_error(exp,_SC(", or } expected"));
|
||||
sqstd_rex_error(exp,", or } expected");
|
||||
}
|
||||
/*******************************/
|
||||
isgreedy = SQTrue;
|
||||
@@ -526,7 +523,7 @@ SQRex *sqstd_rex_compile(const SQChar *pattern,const SQChar **error)
|
||||
SQRex *exp = (SQRex *)sq_malloc(sizeof(SQRex));
|
||||
exp->_eol = exp->_bol = NULL;
|
||||
exp->_p = pattern;
|
||||
exp->_nallocated = (SQInteger)scstrlen(pattern) * sizeof(SQChar);
|
||||
exp->_nallocated = (SQInteger)strlen(pattern) * sizeof(SQChar);
|
||||
exp->_nodes = (SQRexNode *)sq_malloc(exp->_nallocated * sizeof(SQRexNode));
|
||||
exp->_nsize = 0;
|
||||
exp->_matches = 0;
|
||||
@@ -537,23 +534,23 @@ SQRex *sqstd_rex_compile(const SQChar *pattern,const SQChar **error)
|
||||
SQInteger res = sqstd_rex_list(exp);
|
||||
exp->_nodes[exp->_first].left = res;
|
||||
if(*exp->_p!='\0')
|
||||
sqstd_rex_error(exp,_SC("unexpected character"));
|
||||
sqstd_rex_error(exp,"unexpected character");
|
||||
#ifdef _DEBUG
|
||||
{
|
||||
SQInteger nsize,i;
|
||||
SQRexNode *t;
|
||||
nsize = exp->_nsize;
|
||||
t = &exp->_nodes[0];
|
||||
scprintf(_SC("\n"));
|
||||
printf("\n");
|
||||
/* XXX -- The (int) casts are needed to silent warnings on 64bit systems (SQInteger is 64bit, %d assumes 32bit, (int) is 32bit) */
|
||||
for(i = 0;i < nsize; i++) {
|
||||
if(exp->_nodes[i].type>MAX_CHAR)
|
||||
scprintf(_SC("[%02d] %10s "),(int)i,g_nnames[exp->_nodes[i].type-MAX_CHAR]);
|
||||
printf("[%02d] %10s ",(int)i,g_nnames[exp->_nodes[i].type-MAX_CHAR]);
|
||||
else
|
||||
scprintf(_SC("[%02d] %10c "),(int)i,exp->_nodes[i].type);
|
||||
scprintf(_SC("left %02d right %02d next %02d\n"),(int)exp->_nodes[i].left,(int)exp->_nodes[i].right,(int)exp->_nodes[i].next);
|
||||
printf("[%02d] %10c ",(int)i,exp->_nodes[i].type);
|
||||
printf("left %02d right %02d next %02d\n",(int)exp->_nodes[i].left,(int)exp->_nodes[i].right,(int)exp->_nodes[i].next);
|
||||
}
|
||||
scprintf(_SC("\n"));
|
||||
printf("\n");
|
||||
}
|
||||
#endif
|
||||
exp->_matches = (SQRexMatch *) sq_malloc(exp->_nsubexpr * sizeof(SQRexMatch));
|
||||
@@ -579,7 +576,7 @@ SQBool sqstd_rex_match(SQRex* exp,const SQChar* text)
|
||||
{
|
||||
const SQChar* res = NULL;
|
||||
exp->_bol = text;
|
||||
exp->_eol = text + scstrlen(text);
|
||||
exp->_eol = text + strlen(text);
|
||||
exp->_currsubexp = 0;
|
||||
res = sqstd_rex_matchnode(exp,exp->_nodes,text,NULL);
|
||||
if(res == NULL || res != exp->_eol)
|
||||
@@ -618,7 +615,7 @@ SQBool sqstd_rex_searchrange(SQRex* exp,const SQChar* text_begin,const SQChar* t
|
||||
|
||||
SQBool sqstd_rex_search(SQRex* exp,const SQChar* text, const SQChar** out_begin, const SQChar** out_end)
|
||||
{
|
||||
return sqstd_rex_searchrange(exp,text,text + scstrlen(text),out_begin,out_end);
|
||||
return sqstd_rex_searchrange(exp,text,text + strlen(text),out_begin,out_end);
|
||||
}
|
||||
|
||||
SQInteger sqstd_rex_getsubexpcount(SQRex* exp)
|
||||
|
330
src/3rdparty/squirrel/sqstdlib/sqstdstream.cpp
vendored
330
src/3rdparty/squirrel/sqstdlib/sqstdstream.cpp
vendored
@@ -1,330 +0,0 @@
|
||||
/* see copyright notice in squirrel.h */
|
||||
#include <stdio.h>
|
||||
#include <new>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <squirrel.h>
|
||||
#include <sqstdio.h>
|
||||
#include <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))) \
|
||||
return sq_throwerror(v,_SC("invalid type tag")); \
|
||||
if(!self->IsValid()) \
|
||||
return sq_throwerror(v,_SC("the stream is invalid"));
|
||||
|
||||
SQInteger _stream_readblob(HSQUIRRELVM v)
|
||||
{
|
||||
SETUP_STREAM(v);
|
||||
SQUserPointer data,blobp;
|
||||
SQInteger size,res;
|
||||
sq_getinteger(v,2,&size);
|
||||
if(size > self->Len()) {
|
||||
size = self->Len();
|
||||
}
|
||||
data = sq_getscratchpad(v,size);
|
||||
res = self->Read(data,size);
|
||||
if(res <= 0)
|
||||
return sq_throwerror(v,_SC("no data left to read"));
|
||||
blobp = sqstd_createblob(v,res);
|
||||
memcpy(blobp,data,res);
|
||||
return 1;
|
||||
}
|
||||
|
||||
#define SAFE_READN(ptr,len) { \
|
||||
if(self->Read(ptr,len) != len) return sq_throwerror(v,_SC("io error")); \
|
||||
}
|
||||
SQInteger _stream_readn(HSQUIRRELVM v)
|
||||
{
|
||||
SETUP_STREAM(v);
|
||||
SQInteger format;
|
||||
sq_getinteger(v, 2, &format);
|
||||
switch(format) {
|
||||
case 'l': {
|
||||
SQInteger i;
|
||||
SAFE_READN(&i, sizeof(i));
|
||||
sq_pushinteger(v, i);
|
||||
}
|
||||
break;
|
||||
case 'i': {
|
||||
SQInt32 i;
|
||||
SAFE_READN(&i, sizeof(i));
|
||||
sq_pushinteger(v, i);
|
||||
}
|
||||
break;
|
||||
case 's': {
|
||||
short s;
|
||||
SAFE_READN(&s, sizeof(short));
|
||||
sq_pushinteger(v, s);
|
||||
}
|
||||
break;
|
||||
case 'w': {
|
||||
unsigned short w;
|
||||
SAFE_READN(&w, sizeof(unsigned short));
|
||||
sq_pushinteger(v, w);
|
||||
}
|
||||
break;
|
||||
case 'c': {
|
||||
char c;
|
||||
SAFE_READN(&c, sizeof(char));
|
||||
sq_pushinteger(v, c);
|
||||
}
|
||||
break;
|
||||
case 'b': {
|
||||
unsigned char c;
|
||||
SAFE_READN(&c, sizeof(unsigned char));
|
||||
sq_pushinteger(v, c);
|
||||
}
|
||||
break;
|
||||
case 'f': {
|
||||
float f;
|
||||
SAFE_READN(&f, sizeof(float));
|
||||
sq_pushfloat(v, f);
|
||||
}
|
||||
break;
|
||||
case 'd': {
|
||||
double d;
|
||||
SAFE_READN(&d, sizeof(double));
|
||||
sq_pushfloat(v, (SQFloat)d);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return sq_throwerror(v, _SC("invalid format"));
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
SQInteger _stream_writeblob(HSQUIRRELVM v)
|
||||
{
|
||||
SQUserPointer data;
|
||||
SQInteger size;
|
||||
SETUP_STREAM(v);
|
||||
if(SQ_FAILED(sqstd_getblob(v,2,&data)))
|
||||
return sq_throwerror(v,_SC("invalid parameter"));
|
||||
size = sqstd_getblobsize(v,2);
|
||||
if(self->Write(data,size) != size)
|
||||
return sq_throwerror(v,_SC("io error"));
|
||||
sq_pushinteger(v,size);
|
||||
return 1;
|
||||
}
|
||||
|
||||
SQInteger _stream_writen(HSQUIRRELVM v)
|
||||
{
|
||||
SETUP_STREAM(v);
|
||||
SQInteger format, ti;
|
||||
SQFloat tf;
|
||||
sq_getinteger(v, 3, &format);
|
||||
switch(format) {
|
||||
case 'l': {
|
||||
SQInteger i;
|
||||
sq_getinteger(v, 2, &ti);
|
||||
i = ti;
|
||||
self->Write(&i, sizeof(SQInteger));
|
||||
}
|
||||
break;
|
||||
case 'i': {
|
||||
SQInt32 i;
|
||||
sq_getinteger(v, 2, &ti);
|
||||
i = (SQInt32)ti;
|
||||
self->Write(&i, sizeof(SQInt32));
|
||||
}
|
||||
break;
|
||||
case 's': {
|
||||
short s;
|
||||
sq_getinteger(v, 2, &ti);
|
||||
s = (short)ti;
|
||||
self->Write(&s, sizeof(short));
|
||||
}
|
||||
break;
|
||||
case 'w': {
|
||||
unsigned short w;
|
||||
sq_getinteger(v, 2, &ti);
|
||||
w = (unsigned short)ti;
|
||||
self->Write(&w, sizeof(unsigned short));
|
||||
}
|
||||
break;
|
||||
case 'c': {
|
||||
char c;
|
||||
sq_getinteger(v, 2, &ti);
|
||||
c = (char)ti;
|
||||
self->Write(&c, sizeof(char));
|
||||
}
|
||||
break;
|
||||
case 'b': {
|
||||
unsigned char b;
|
||||
sq_getinteger(v, 2, &ti);
|
||||
b = (unsigned char)ti;
|
||||
self->Write(&b, sizeof(unsigned char));
|
||||
}
|
||||
break;
|
||||
case 'f': {
|
||||
float f;
|
||||
sq_getfloat(v, 2, &tf);
|
||||
f = (float)tf;
|
||||
self->Write(&f, sizeof(float));
|
||||
}
|
||||
break;
|
||||
case 'd': {
|
||||
double d;
|
||||
sq_getfloat(v, 2, &tf);
|
||||
d = tf;
|
||||
self->Write(&d, sizeof(double));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return sq_throwerror(v, _SC("invalid format"));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
SQInteger _stream_seek(HSQUIRRELVM v)
|
||||
{
|
||||
SETUP_STREAM(v);
|
||||
SQInteger offset, origin = SQ_SEEK_SET;
|
||||
sq_getinteger(v, 2, &offset);
|
||||
if(sq_gettop(v) > 2) {
|
||||
SQInteger t;
|
||||
sq_getinteger(v, 3, &t);
|
||||
switch(t) {
|
||||
case 'b': origin = SQ_SEEK_SET; break;
|
||||
case 'c': origin = SQ_SEEK_CUR; break;
|
||||
case 'e': origin = SQ_SEEK_END; break;
|
||||
default: return sq_throwerror(v,_SC("invalid origin"));
|
||||
}
|
||||
}
|
||||
sq_pushinteger(v, self->Seek(offset, origin));
|
||||
return 1;
|
||||
}
|
||||
|
||||
SQInteger _stream_tell(HSQUIRRELVM v)
|
||||
{
|
||||
SETUP_STREAM(v);
|
||||
sq_pushinteger(v, self->Tell());
|
||||
return 1;
|
||||
}
|
||||
|
||||
SQInteger _stream_len(HSQUIRRELVM v)
|
||||
{
|
||||
SETUP_STREAM(v);
|
||||
sq_pushinteger(v, self->Len());
|
||||
return 1;
|
||||
}
|
||||
|
||||
SQInteger _stream_flush(HSQUIRRELVM v)
|
||||
{
|
||||
SETUP_STREAM(v);
|
||||
if(!self->Flush())
|
||||
sq_pushinteger(v, 1);
|
||||
else
|
||||
sq_pushnull(v);
|
||||
return 1;
|
||||
}
|
||||
|
||||
SQInteger _stream_eos(HSQUIRRELVM v)
|
||||
{
|
||||
SETUP_STREAM(v);
|
||||
if(self->EOS())
|
||||
sq_pushinteger(v, 1);
|
||||
else
|
||||
sq_pushnull(v);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static SQRegFunction _stream_methods[] = {
|
||||
_DECL_STREAM_FUNC(readblob,2,_SC("xn")),
|
||||
_DECL_STREAM_FUNC(readn,2,_SC("xn")),
|
||||
_DECL_STREAM_FUNC(writeblob,-2,_SC("xx")),
|
||||
_DECL_STREAM_FUNC(writen,3,_SC("xnn")),
|
||||
_DECL_STREAM_FUNC(seek,-2,_SC("xnn")),
|
||||
_DECL_STREAM_FUNC(tell,1,_SC("x")),
|
||||
_DECL_STREAM_FUNC(len,1,_SC("x")),
|
||||
_DECL_STREAM_FUNC(eos,1,_SC("x")),
|
||||
_DECL_STREAM_FUNC(flush,1,_SC("x")),
|
||||
{0,0,0,0}
|
||||
};
|
||||
|
||||
void init_streamclass(HSQUIRRELVM v)
|
||||
{
|
||||
sq_pushregistrytable(v);
|
||||
sq_pushstring(v,_SC("std_stream"),-1);
|
||||
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);
|
||||
SQInteger i = 0;
|
||||
while(_stream_methods[i].name != 0) {
|
||||
SQRegFunction &f = _stream_methods[i];
|
||||
sq_pushstring(v,f.name,-1);
|
||||
sq_newclosure(v,f.f,0);
|
||||
sq_setparamscheck(v,f.nparamscheck,f.typemask);
|
||||
sq_createslot(v,-3);
|
||||
i++;
|
||||
}
|
||||
sq_createslot(v,-3);
|
||||
sq_pushroottable(v);
|
||||
sq_pushstring(v,_SC("stream"),-1);
|
||||
sq_pushstring(v,_SC("std_stream"),-1);
|
||||
sq_get(v,-4);
|
||||
sq_createslot(v,-3);
|
||||
sq_pop(v,1);
|
||||
}
|
||||
else {
|
||||
sq_pop(v,1); //result
|
||||
}
|
||||
sq_pop(v,1);
|
||||
}
|
||||
|
||||
SQRESULT declare_stream(HSQUIRRELVM v,const SQChar* name,SQUserPointer typetag,const SQChar* reg_name,SQRegFunction *methods,SQRegFunction *globals)
|
||||
{
|
||||
if(sq_gettype(v,-1) != OT_TABLE)
|
||||
return sq_throwerror(v,_SC("table expected"));
|
||||
SQInteger top = sq_gettop(v);
|
||||
//create delegate
|
||||
init_streamclass(v);
|
||||
sq_pushregistrytable(v);
|
||||
sq_pushstring(v,reg_name,-1);
|
||||
sq_pushstring(v,_SC("std_stream"),-1);
|
||||
if(SQ_SUCCEEDED(sq_get(v,-3))) {
|
||||
sq_newclass(v,SQTrue);
|
||||
sq_settypetag(v,-1,typetag);
|
||||
SQInteger i = 0;
|
||||
while(methods[i].name != 0) {
|
||||
SQRegFunction &f = methods[i];
|
||||
sq_pushstring(v,f.name,-1);
|
||||
sq_newclosure(v,f.f,0);
|
||||
sq_setparamscheck(v,f.nparamscheck,f.typemask);
|
||||
sq_setnativeclosurename(v,-1,f.name);
|
||||
sq_createslot(v,-3);
|
||||
i++;
|
||||
}
|
||||
sq_createslot(v,-3);
|
||||
sq_pop(v,1);
|
||||
|
||||
i = 0;
|
||||
while(globals[i].name!=0)
|
||||
{
|
||||
SQRegFunction &f = globals[i];
|
||||
sq_pushstring(v,f.name,-1);
|
||||
sq_newclosure(v,f.f,0);
|
||||
sq_setparamscheck(v,f.nparamscheck,f.typemask);
|
||||
sq_setnativeclosurename(v,-1,f.name);
|
||||
sq_createslot(v,-3);
|
||||
i++;
|
||||
}
|
||||
//register the class in the target table
|
||||
sq_pushstring(v,name,-1);
|
||||
sq_pushregistrytable(v);
|
||||
sq_pushstring(v,reg_name,-1);
|
||||
sq_get(v,-2);
|
||||
sq_remove(v,-2);
|
||||
sq_createslot(v,-3);
|
||||
|
||||
sq_settop(v,top);
|
||||
return SQ_OK;
|
||||
}
|
||||
sq_settop(v,top);
|
||||
return SQ_ERROR;
|
||||
}
|
18
src/3rdparty/squirrel/sqstdlib/sqstdstream.h
vendored
18
src/3rdparty/squirrel/sqstdlib/sqstdstream.h
vendored
@@ -1,18 +0,0 @@
|
||||
/* see copyright notice in squirrel.h */
|
||||
#ifndef _SQSTD_STREAM_H_
|
||||
#define _SQSTD_STREAM_H_
|
||||
|
||||
SQInteger _stream_readblob(HSQUIRRELVM v);
|
||||
SQInteger _stream_readline(HSQUIRRELVM v);
|
||||
SQInteger _stream_readn(HSQUIRRELVM v);
|
||||
SQInteger _stream_writeblob(HSQUIRRELVM v);
|
||||
SQInteger _stream_writen(HSQUIRRELVM v);
|
||||
SQInteger _stream_seek(HSQUIRRELVM v);
|
||||
SQInteger _stream_tell(HSQUIRRELVM v);
|
||||
SQInteger _stream_len(HSQUIRRELVM v);
|
||||
SQInteger _stream_eos(HSQUIRRELVM v);
|
||||
SQInteger _stream_flush(HSQUIRRELVM v);
|
||||
|
||||
#define _DECL_STREAM_FUNC(name,nparams,typecheck) {_SC(#name),_stream_##name,nparams,typecheck}
|
||||
SQRESULT declare_stream(HSQUIRRELVM v,const SQChar* name,SQUserPointer typetag,const SQChar* reg_name,SQRegFunction *methods,SQRegFunction *globals);
|
||||
#endif /*_SQSTD_STREAM_H_*/
|
79
src/3rdparty/squirrel/sqstdlib/sqstdstring.cpp
vendored
79
src/3rdparty/squirrel/sqstdlib/sqstdstring.cpp
vendored
@@ -1,22 +1,11 @@
|
||||
/* see copyright notice in squirrel.h */
|
||||
#include <squirrel.h>
|
||||
#include <sqstdstring.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include <assert.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#ifdef SQUNICODE
|
||||
#define scstrchr wcschr
|
||||
#define scatoi _wtoi
|
||||
#define scstrtok wcstok
|
||||
#else
|
||||
#define scstrchr strchr
|
||||
#define scatoi atoi
|
||||
#define scstrtok strtok
|
||||
#endif
|
||||
#define MAX_FORMAT_LEN 20
|
||||
#define MAX_WFORMAT_LEN 3
|
||||
#define ADDITIONAL_FORMAT_SPACE (100*sizeof(SQChar))
|
||||
@@ -27,17 +16,17 @@ static SQInteger validate_format(HSQUIRRELVM v, SQChar *fmt, const SQChar *src,
|
||||
SQInteger wc = 0;
|
||||
SQInteger start = n;
|
||||
fmt[0] = '%';
|
||||
while (scstrchr(_SC("-+ #0"), src[n])) n++;
|
||||
while (scisdigit(src[n])) {
|
||||
while (scstrchr("-+ #0", src[n])) n++;
|
||||
while (isdigit(src[n])) {
|
||||
swidth[wc] = src[n];
|
||||
n++;
|
||||
wc++;
|
||||
if(wc>=MAX_WFORMAT_LEN)
|
||||
return sq_throwerror(v,_SC("width format too long"));
|
||||
return sq_throwerror(v,"width format too long");
|
||||
}
|
||||
swidth[wc] = '\0';
|
||||
if(wc > 0) {
|
||||
width = scatoi(swidth);
|
||||
width = atoi(swidth);
|
||||
}
|
||||
else
|
||||
width = 0;
|
||||
@@ -45,20 +34,20 @@ static SQInteger validate_format(HSQUIRRELVM v, SQChar *fmt, const SQChar *src,
|
||||
n++;
|
||||
|
||||
wc = 0;
|
||||
while (scisdigit(src[n])) {
|
||||
while (isdigit(src[n])) {
|
||||
swidth[wc] = src[n];
|
||||
n++;
|
||||
wc++;
|
||||
if(wc>=MAX_WFORMAT_LEN)
|
||||
return sq_throwerror(v,_SC("precision format too long"));
|
||||
return sq_throwerror(v,"precision format too long");
|
||||
}
|
||||
swidth[wc] = '\0';
|
||||
if(wc > 0) {
|
||||
width += scatoi(swidth);
|
||||
width += atoi(swidth);
|
||||
}
|
||||
}
|
||||
if (n-start > MAX_FORMAT_LEN )
|
||||
return sq_throwerror(v,_SC("format too long"));
|
||||
return sq_throwerror(v,"format too long");
|
||||
memcpy(&fmt[1],&src[start],((n-start)+1)*sizeof(SQChar));
|
||||
fmt[(n-start)+2] = '\0';
|
||||
return n;
|
||||
@@ -75,7 +64,7 @@ static void _append_string(SQInteger &i, SQChar *dest, SQInteger allocated, cons
|
||||
{
|
||||
va_list va;
|
||||
va_start(va, fmt);
|
||||
i += scvsnprintf(&dest[i],allocated-i,fmt,va);
|
||||
i += vsnprintf(&dest[i],allocated-i,fmt,va);
|
||||
va_end(va);
|
||||
}
|
||||
|
||||
@@ -102,7 +91,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,"not enough paramters for the given format string");
|
||||
n = validate_format(v,fmt,format,n,w);
|
||||
if(n < 0) return -1;
|
||||
SQInteger addlen = 0;
|
||||
@@ -113,24 +102,24 @@ SQRESULT sqstd_format(HSQUIRRELVM v,SQInteger nformatstringidx,SQInteger *outlen
|
||||
switch(format[n]) {
|
||||
case 's':
|
||||
if(SQ_FAILED(sq_getstring(v,nparam,&ts)))
|
||||
return sq_throwerror(v,_SC("string expected for the specified format"));
|
||||
return sq_throwerror(v,"string expected for the specified format");
|
||||
addlen = (sq_getsize(v,nparam)*sizeof(SQChar))+((w+1)*sizeof(SQChar));
|
||||
valtype = 's';
|
||||
break;
|
||||
case 'i': case 'd': case 'c':case 'o': case 'u': case 'x': case 'X':
|
||||
if(SQ_FAILED(sq_getinteger(v,nparam,&ti)))
|
||||
return sq_throwerror(v,_SC("integer expected for the specified format"));
|
||||
return sq_throwerror(v,"integer expected for the specified format");
|
||||
addlen = (ADDITIONAL_FORMAT_SPACE)+((w+1)*sizeof(SQChar));
|
||||
valtype = 'i';
|
||||
break;
|
||||
case 'f': case 'g': case 'G': case 'e': case 'E':
|
||||
if(SQ_FAILED(sq_getfloat(v,nparam,&tf)))
|
||||
return sq_throwerror(v,_SC("float expected for the specified format"));
|
||||
return sq_throwerror(v,"float expected for the specified format");
|
||||
addlen = (ADDITIONAL_FORMAT_SPACE)+((w+1)*sizeof(SQChar));
|
||||
valtype = 'f';
|
||||
break;
|
||||
default:
|
||||
return sq_throwerror(v,_SC("invalid format"));
|
||||
return sq_throwerror(v,"invalid format");
|
||||
}
|
||||
n++;
|
||||
allocated += addlen + sizeof(SQChar);
|
||||
@@ -162,7 +151,7 @@ static SQInteger _string_format(HSQUIRRELVM v)
|
||||
static void __strip_l(const SQChar *str,const SQChar **start)
|
||||
{
|
||||
const SQChar *t = str;
|
||||
while(((*t) != '\0') && scisspace(*t)){ t++; }
|
||||
while(((*t) != '\0') && isspace(*t)){ t++; }
|
||||
*start = t;
|
||||
}
|
||||
|
||||
@@ -173,7 +162,7 @@ static void __strip_r(const SQChar *str,SQInteger len,const SQChar **end)
|
||||
return;
|
||||
}
|
||||
const SQChar *t = &str[len-1];
|
||||
while(t != str && scisspace(*t)) { t--; }
|
||||
while(t != str && isspace(*t)) { t--; }
|
||||
*end = t+1;
|
||||
}
|
||||
|
||||
@@ -213,7 +202,7 @@ static SQInteger _string_split(HSQUIRRELVM v)
|
||||
SQChar *stemp,*tok;
|
||||
sq_getstring(v,2,&str);
|
||||
sq_getstring(v,3,&seps);
|
||||
if(sq_getsize(v,3) == 0) return sq_throwerror(v,_SC("empty separators string"));
|
||||
if(sq_getsize(v,3) == 0) return sq_throwerror(v,"empty separators string");
|
||||
SQInteger memsize = (sq_getsize(v,2)+1)*sizeof(SQChar);
|
||||
stemp = sq_getscratchpad(v,memsize);
|
||||
memcpy(stemp,str,memsize);
|
||||
@@ -255,10 +244,10 @@ static SQInteger _regexp_match(HSQUIRRELVM v)
|
||||
static void _addrexmatch(HSQUIRRELVM v,const SQChar *str,const SQChar *begin,const SQChar *end)
|
||||
{
|
||||
sq_newtable(v);
|
||||
sq_pushstring(v,_SC("begin"),-1);
|
||||
sq_pushstring(v,"begin",-1);
|
||||
sq_pushinteger(v,begin - str);
|
||||
sq_rawset(v,-3);
|
||||
sq_pushstring(v,_SC("end"),-1);
|
||||
sq_pushstring(v,"end",-1);
|
||||
sq_pushinteger(v,end - str);
|
||||
sq_rawset(v,-3);
|
||||
}
|
||||
@@ -321,35 +310,35 @@ static SQInteger _regexp_constructor(HSQUIRRELVM v)
|
||||
|
||||
static SQInteger _regexp__typeof(HSQUIRRELVM v)
|
||||
{
|
||||
sq_pushstring(v,_SC("regexp"),-1);
|
||||
sq_pushstring(v,"regexp",-1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
#define _DECL_REX_FUNC(name,nparams,pmask) {_SC(#name),_regexp_##name,nparams,pmask}
|
||||
#define _DECL_REX_FUNC(name,nparams,pmask) {#name,_regexp_##name,nparams,pmask}
|
||||
static SQRegFunction rexobj_funcs[]={
|
||||
_DECL_REX_FUNC(constructor,2,_SC(".s")),
|
||||
_DECL_REX_FUNC(search,-2,_SC("xsn")),
|
||||
_DECL_REX_FUNC(match,2,_SC("xs")),
|
||||
_DECL_REX_FUNC(capture,-2,_SC("xsn")),
|
||||
_DECL_REX_FUNC(subexpcount,1,_SC("x")),
|
||||
_DECL_REX_FUNC(_typeof,1,_SC("x")),
|
||||
_DECL_REX_FUNC(constructor,2,".s"),
|
||||
_DECL_REX_FUNC(search,-2,"xsn"),
|
||||
_DECL_REX_FUNC(match,2,"xs"),
|
||||
_DECL_REX_FUNC(capture,-2,"xsn"),
|
||||
_DECL_REX_FUNC(subexpcount,1,"x"),
|
||||
_DECL_REX_FUNC(_typeof,1,"x"),
|
||||
{0,0,0,0}
|
||||
};
|
||||
|
||||
#define _DECL_FUNC(name,nparams,pmask) {_SC(#name),_string_##name,nparams,pmask}
|
||||
#define _DECL_FUNC(name,nparams,pmask) {#name,_string_##name,nparams,pmask}
|
||||
static SQRegFunction stringlib_funcs[]={
|
||||
_DECL_FUNC(format,-2,_SC(".s")),
|
||||
_DECL_FUNC(strip,2,_SC(".s")),
|
||||
_DECL_FUNC(lstrip,2,_SC(".s")),
|
||||
_DECL_FUNC(rstrip,2,_SC(".s")),
|
||||
_DECL_FUNC(split,3,_SC(".ss")),
|
||||
_DECL_FUNC(format,-2,".s"),
|
||||
_DECL_FUNC(strip,2,".s"),
|
||||
_DECL_FUNC(lstrip,2,".s"),
|
||||
_DECL_FUNC(rstrip,2,".s"),
|
||||
_DECL_FUNC(split,3,".ss"),
|
||||
{0,0,0,0}
|
||||
};
|
||||
|
||||
|
||||
SQInteger sqstd_register_stringlib(HSQUIRRELVM v)
|
||||
{
|
||||
sq_pushstring(v,_SC("regexp"),-1);
|
||||
sq_pushstring(v,"regexp",-1);
|
||||
sq_newclass(v,SQFalse);
|
||||
SQInteger i = 0;
|
||||
while(rexobj_funcs[i].name != 0) {
|
||||
|
147
src/3rdparty/squirrel/sqstdlib/sqstdsystem.cpp
vendored
147
src/3rdparty/squirrel/sqstdlib/sqstdsystem.cpp
vendored
@@ -1,147 +0,0 @@
|
||||
/* see copyright notice in squirrel.h */
|
||||
#include <squirrel.h>
|
||||
#include <time.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <sqstdsystem.h>
|
||||
|
||||
#ifdef SQUNICODE
|
||||
#include <wchar.h>
|
||||
#define scgetenv _wgetenv
|
||||
#define scsystem _wsystem
|
||||
#define scasctime _wasctime
|
||||
#define scremove _wremove
|
||||
#define screname _wrename
|
||||
#else
|
||||
#define scgetenv getenv
|
||||
#define scsystem system
|
||||
#define scasctime asctime
|
||||
#define scremove remove
|
||||
#define screname rename
|
||||
#endif
|
||||
|
||||
static SQInteger _system_getenv(HSQUIRRELVM v)
|
||||
{
|
||||
const SQChar *s;
|
||||
if(SQ_SUCCEEDED(sq_getstring(v,2,&s))){
|
||||
sq_pushstring(v,scgetenv(s),-1);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static SQInteger _system_system(HSQUIRRELVM v)
|
||||
{
|
||||
const SQChar *s;
|
||||
if(SQ_SUCCEEDED(sq_getstring(v,2,&s))){
|
||||
sq_pushinteger(v,scsystem(s));
|
||||
return 1;
|
||||
}
|
||||
return sq_throwerror(v,_SC("wrong param"));
|
||||
}
|
||||
|
||||
|
||||
static SQInteger _system_clock(HSQUIRRELVM v)
|
||||
{
|
||||
sq_pushfloat(v,((SQFloat)clock())/(SQFloat)CLOCKS_PER_SEC);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static SQInteger _system_time(HSQUIRRELVM v)
|
||||
{
|
||||
time_t t;
|
||||
time(&t);
|
||||
sq_pushinteger(v,*((SQInteger *)&t));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static SQInteger _system_remove(HSQUIRRELVM v)
|
||||
{
|
||||
const SQChar *s;
|
||||
sq_getstring(v,2,&s);
|
||||
if(scremove(s)==-1)
|
||||
return sq_throwerror(v,_SC("remove() failed"));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static SQInteger _system_rename(HSQUIRRELVM v)
|
||||
{
|
||||
const SQChar *oldn,*newn;
|
||||
sq_getstring(v,2,&oldn);
|
||||
sq_getstring(v,3,&newn);
|
||||
if(screname(oldn,newn)==-1)
|
||||
return sq_throwerror(v,_SC("rename() failed"));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void _set_integer_slot(HSQUIRRELVM v,const SQChar *name,SQInteger val)
|
||||
{
|
||||
sq_pushstring(v,name,-1);
|
||||
sq_pushinteger(v,val);
|
||||
sq_rawset(v,-3);
|
||||
}
|
||||
|
||||
static SQInteger _system_date(HSQUIRRELVM v)
|
||||
{
|
||||
time_t t;
|
||||
SQInteger it;
|
||||
SQInteger format = 'l';
|
||||
if(sq_gettop(v) > 1) {
|
||||
sq_getinteger(v,2,&it);
|
||||
t = it;
|
||||
if(sq_gettop(v) > 2) {
|
||||
sq_getinteger(v,3,(SQInteger*)&format);
|
||||
}
|
||||
}
|
||||
else {
|
||||
time(&t);
|
||||
}
|
||||
tm *date;
|
||||
if(format == 'u')
|
||||
date = gmtime(&t);
|
||||
else
|
||||
date = localtime(&t);
|
||||
if(!date)
|
||||
return sq_throwerror(v,_SC("crt api failure"));
|
||||
sq_newtable(v);
|
||||
_set_integer_slot(v, _SC("sec"), date->tm_sec);
|
||||
_set_integer_slot(v, _SC("min"), date->tm_min);
|
||||
_set_integer_slot(v, _SC("hour"), date->tm_hour);
|
||||
_set_integer_slot(v, _SC("day"), date->tm_mday);
|
||||
_set_integer_slot(v, _SC("month"), date->tm_mon);
|
||||
_set_integer_slot(v, _SC("year"), date->tm_year+1900);
|
||||
_set_integer_slot(v, _SC("wday"), date->tm_wday);
|
||||
_set_integer_slot(v, _SC("yday"), date->tm_yday);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#define _DECL_FUNC(name,nparams,pmask) {_SC(#name),_system_##name,nparams,pmask}
|
||||
static SQRegFunction systemlib_funcs[]={
|
||||
_DECL_FUNC(getenv,2,_SC(".s")),
|
||||
_DECL_FUNC(system,2,_SC(".s")),
|
||||
_DECL_FUNC(clock,1,NULL),
|
||||
_DECL_FUNC(time,1,NULL),
|
||||
_DECL_FUNC(date,-1,_SC(".nn")),
|
||||
_DECL_FUNC(remove,2,_SC(".s")),
|
||||
_DECL_FUNC(rename,3,_SC(".ss")),
|
||||
{0,0,0,0}
|
||||
};
|
||||
|
||||
|
||||
SQInteger sqstd_register_systemlib(HSQUIRRELVM v)
|
||||
{
|
||||
SQInteger i=0;
|
||||
while(systemlib_funcs[i].name!=0)
|
||||
{
|
||||
sq_pushstring(v,systemlib_funcs[i].name,-1);
|
||||
sq_newclosure(v,systemlib_funcs[i].f,0);
|
||||
sq_setparamscheck(v,systemlib_funcs[i].nparamscheck,systemlib_funcs[i].typemask);
|
||||
sq_setnativeclosurename(v,-1,systemlib_funcs[i].name);
|
||||
sq_createslot(v,-3);
|
||||
i++;
|
||||
}
|
||||
return 1;
|
||||
}
|
77
src/3rdparty/squirrel/squirrel.dsw
vendored
77
src/3rdparty/squirrel/squirrel.dsw
vendored
@@ -1,77 +0,0 @@
|
||||
Microsoft Developer Studio Workspace File, Format Version 6.00
|
||||
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
|
||||
|
||||
###############################################################################
|
||||
|
||||
Project: "sq"=.\sq\sq.dsp - Package Owner=<4>
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
begin source code control
|
||||
.
|
||||
end source code control
|
||||
}}}
|
||||
|
||||
Package=<4>
|
||||
{{{
|
||||
Begin Project Dependency
|
||||
Project_Dep_Name sqlibs
|
||||
End Project Dependency
|
||||
Begin Project Dependency
|
||||
Project_Dep_Name squirrel
|
||||
End Project Dependency
|
||||
Begin Project Dependency
|
||||
Project_Dep_Name sqstdlib
|
||||
End Project Dependency
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
Project: "sqstdlib"=.\sqstdlib\sqstdlib.dsp - Package Owner=<4>
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
begin source code control
|
||||
"$/squirrel", HAAAAAAA
|
||||
.
|
||||
end source code control
|
||||
}}}
|
||||
|
||||
Package=<4>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
Project: "squirrel"=.\squirrel\squirrel.dsp - Package Owner=<4>
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
begin source code control
|
||||
"$/squirrel", HAAAAAAA
|
||||
.
|
||||
end source code control
|
||||
}}}
|
||||
|
||||
Package=<4>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
Global:
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
begin source code control
|
||||
"$/squirrel", HAAAAAAA
|
||||
.
|
||||
end source code control
|
||||
}}}
|
||||
|
||||
Package=<3>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
52
src/3rdparty/squirrel/squirrel/Makefile
vendored
52
src/3rdparty/squirrel/squirrel/Makefile
vendored
@@ -1,52 +0,0 @@
|
||||
SQUIRREL= ..
|
||||
|
||||
|
||||
OUT= $(SQUIRREL)/lib/libsquirrel.a
|
||||
INCZ= -I$(SQUIRREL)/include -I. -Iinclude
|
||||
DEFS=
|
||||
LIB=
|
||||
|
||||
OBJS= \
|
||||
sqapi.o \
|
||||
sqbaselib.o \
|
||||
sqcompiler.o \
|
||||
sqdebug.o \
|
||||
sqlexer.o \
|
||||
sqobject.o \
|
||||
sqparser.o \
|
||||
sqstate.o \
|
||||
sqtable.o \
|
||||
sqvm.o \
|
||||
sqmem.o \
|
||||
sqclass.o
|
||||
|
||||
SRCS= \
|
||||
sqapi.cpp \
|
||||
sqbaselib.cpp \
|
||||
sqfuncstate.cpp \
|
||||
sqdebug.cpp \
|
||||
sqlexer.cpp \
|
||||
sqobject.cpp \
|
||||
sqcompiler.cpp \
|
||||
sqstate.cpp \
|
||||
sqtable.cpp \
|
||||
sqmem.cpp \
|
||||
sqvm.cpp \
|
||||
sqclass.cpp
|
||||
|
||||
|
||||
|
||||
sq32:
|
||||
gcc -O2 -fno-rtti -Wall -c $(SRCS) $(INCZ) $(DEFS)
|
||||
ar rc $(OUT) *.o
|
||||
|
||||
sqprof:
|
||||
gcc -O2 -pg -fno-rtti -pie -gstabs -g3 -Wall -c $(SRCS) $(INCZ) $(DEFS)
|
||||
ar rc $(OUT) *.o
|
||||
|
||||
sq64:
|
||||
gcc -O2 -D_SQ64 -fno-rtti -Wall -c $(SRCS) $(INCZ) $(DEFS)
|
||||
ar rc $(OUT) *.o
|
||||
|
||||
clean:
|
||||
rm -f $(OUT) $(SRCS:%.cpp=%.o)
|
139
src/3rdparty/squirrel/squirrel/sqapi.cpp
vendored
139
src/3rdparty/squirrel/squirrel/sqapi.cpp
vendored
@@ -1,6 +1,9 @@
|
||||
/*
|
||||
see copyright notice in squirrel.h
|
||||
*/
|
||||
* see copyright notice in squirrel.h
|
||||
*/
|
||||
|
||||
#include "../../../stdafx.h"
|
||||
|
||||
#include <squirrel.h>
|
||||
#include "sqpcheader.h"
|
||||
#include "sqvm.h"
|
||||
@@ -14,12 +17,16 @@
|
||||
#include "sqfuncstate.h"
|
||||
#include "sqclass.h"
|
||||
|
||||
#include "../../../string_func.h"
|
||||
|
||||
#include "../../../safeguards.h"
|
||||
|
||||
bool sq_aux_gettypedarg(HSQUIRRELVM v,SQInteger idx,SQObjectType type,SQObjectPtr **o)
|
||||
{
|
||||
*o = &stack_get(v,idx);
|
||||
if(type(**o) != type){
|
||||
SQObjectPtr oval = v->PrintObjVal(**o);
|
||||
v->Raise_Error(_SC("wrong argument type, expected '%s' got '%.50s'"),IdType2Name(type),_stringval(oval));
|
||||
v->Raise_Error("wrong argument type, expected '%s' got '%.50s'",IdType2Name(type),_stringval(oval));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -29,7 +36,7 @@ bool sq_aux_gettypedarg(HSQUIRRELVM v,SQInteger idx,SQObjectType type,SQObjectPt
|
||||
|
||||
#define sq_aux_paramscheck(v,count) \
|
||||
{ \
|
||||
if(sq_gettop(v) < count){ v->Raise_Error(_SC("not enough params in the stack")); return SQ_ERROR; }\
|
||||
if(sq_gettop(v) < count){ v->Raise_Error("not enough params in the stack"); return SQ_ERROR; }\
|
||||
}
|
||||
|
||||
SQInteger sq_aux_throwobject(HSQUIRRELVM v,SQObjectPtr &e)
|
||||
@@ -40,8 +47,9 @@ SQInteger sq_aux_throwobject(HSQUIRRELVM v,SQObjectPtr &e)
|
||||
|
||||
SQInteger sq_aux_invalidtype(HSQUIRRELVM v,SQObjectType type)
|
||||
{
|
||||
scsprintf(_ss(v)->GetScratchPad(100), _SC("unexpected type %s"), IdType2Name(type));
|
||||
return sq_throwerror(v, _ss(v)->GetScratchPad(-1));
|
||||
char buf[100];
|
||||
seprintf(buf, lastof(buf), "unexpected type %s", IdType2Name(type));
|
||||
return sq_throwerror(v, buf);
|
||||
}
|
||||
|
||||
HSQUIRRELVM sq_open(SQInteger initialstacksize)
|
||||
@@ -49,7 +57,6 @@ HSQUIRRELVM sq_open(SQInteger initialstacksize)
|
||||
SQSharedState *ss;
|
||||
SQVM *v;
|
||||
sq_new(ss, SQSharedState);
|
||||
ss->Init();
|
||||
v = (SQVM *)SQ_MALLOC(sizeof(SQVM));
|
||||
new (v) SQVM(ss);
|
||||
ss->_root_vm = v;
|
||||
@@ -253,7 +260,7 @@ SQRESULT sq_newclass(HSQUIRRELVM v,SQBool hasbase)
|
||||
if(hasbase) {
|
||||
SQObjectPtr &base = stack_get(v,-1);
|
||||
if(type(base) != OT_CLASS)
|
||||
return sq_throwerror(v,_SC("invalid base type"));
|
||||
return sq_throwerror(v,"invalid base type");
|
||||
baseclass = _class(base);
|
||||
}
|
||||
SQClass *newclass = SQClass::Create(_ss(v), baseclass);
|
||||
@@ -267,7 +274,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)
|
||||
return sq_throwerror(v,_SC("invalid param type"));
|
||||
return sq_throwerror(v,"invalid param type");
|
||||
return _instance(inst)->InstanceOf(_class(cl))?SQTrue:SQFalse;
|
||||
}
|
||||
|
||||
@@ -291,7 +298,7 @@ SQRESULT sq_arraypop(HSQUIRRELVM v,SQInteger idx,SQBool pushval)
|
||||
_array(*arr)->Pop();
|
||||
return SQ_OK;
|
||||
}
|
||||
return sq_throwerror(v, _SC("empty array"));
|
||||
return sq_throwerror(v, "empty array");
|
||||
}
|
||||
|
||||
SQRESULT sq_arrayresize(HSQUIRRELVM v,SQInteger idx,SQInteger newsize)
|
||||
@@ -303,7 +310,7 @@ SQRESULT sq_arrayresize(HSQUIRRELVM v,SQInteger idx,SQInteger newsize)
|
||||
_array(*arr)->Resize(newsize);
|
||||
return SQ_OK;
|
||||
}
|
||||
return sq_throwerror(v,_SC("negative size"));
|
||||
return sq_throwerror(v,"negative size");
|
||||
}
|
||||
|
||||
|
||||
@@ -332,7 +339,7 @@ SQRESULT sq_arrayremove(HSQUIRRELVM v,SQInteger idx,SQInteger itemidx)
|
||||
sq_aux_paramscheck(v, 1);
|
||||
SQObjectPtr *arr;
|
||||
_GETSAFE_OBJ(v, idx, OT_ARRAY,arr);
|
||||
return _array(*arr)->Remove(itemidx) ? SQ_OK : sq_throwerror(v,_SC("index out of range"));
|
||||
return _array(*arr)->Remove(itemidx) ? SQ_OK : sq_throwerror(v,"index out of range");
|
||||
}
|
||||
|
||||
SQRESULT sq_arrayinsert(HSQUIRRELVM v,SQInteger idx,SQInteger destpos)
|
||||
@@ -340,7 +347,7 @@ SQRESULT sq_arrayinsert(HSQUIRRELVM v,SQInteger idx,SQInteger destpos)
|
||||
sq_aux_paramscheck(v, 1);
|
||||
SQObjectPtr *arr;
|
||||
_GETSAFE_OBJ(v, idx, OT_ARRAY,arr);
|
||||
SQRESULT ret = _array(*arr)->Insert(destpos, v->GetUp(-1)) ? SQ_OK : sq_throwerror(v,_SC("index out of range"));
|
||||
SQRESULT ret = _array(*arr)->Insert(destpos, v->GetUp(-1)) ? SQ_OK : sq_throwerror(v,"index out of range");
|
||||
v->Pop();
|
||||
return ret;
|
||||
}
|
||||
@@ -349,7 +356,6 @@ SQRESULT sq_arrayinsert(HSQUIRRELVM v,SQInteger idx,SQInteger destpos)
|
||||
void sq_newclosure(HSQUIRRELVM v,SQFUNCTION func,SQUnsignedInteger nfreevars)
|
||||
{
|
||||
SQNativeClosure *nc = SQNativeClosure::Create(_ss(v), func);
|
||||
nc->_nparamscheck = 0;
|
||||
for(SQUnsignedInteger i = 0; i < nfreevars; i++) {
|
||||
nc->_outervalues.push_back(v->Top());
|
||||
v->Pop();
|
||||
@@ -367,7 +373,7 @@ SQRESULT sq_getclosureinfo(HSQUIRRELVM v,SQInteger idx,SQUnsignedInteger *nparam
|
||||
*nfreevars = (SQUnsignedInteger)c->_outervalues.size();
|
||||
return SQ_OK;
|
||||
}
|
||||
return sq_throwerror(v,_SC("the object is not a closure"));
|
||||
return sq_throwerror(v,"the object is not a closure");
|
||||
}
|
||||
|
||||
SQRESULT sq_setnativeclosurename(HSQUIRRELVM v,SQInteger idx,const SQChar *name)
|
||||
@@ -378,20 +384,20 @@ SQRESULT sq_setnativeclosurename(HSQUIRRELVM v,SQInteger idx,const SQChar *name)
|
||||
nc->_name = SQString::Create(_ss(v),name);
|
||||
return SQ_OK;
|
||||
}
|
||||
return sq_throwerror(v,_SC("the object is not a nativeclosure"));
|
||||
return sq_throwerror(v,"the object is not a nativeclosure");
|
||||
}
|
||||
|
||||
SQRESULT sq_setparamscheck(HSQUIRRELVM v,SQInteger nparamscheck,const SQChar *typemask)
|
||||
{
|
||||
SQObject o = stack_get(v, -1);
|
||||
if(!sq_isnativeclosure(o))
|
||||
return sq_throwerror(v, _SC("native closure expected"));
|
||||
return sq_throwerror(v, "native closure expected");
|
||||
SQNativeClosure *nc = _nativeclosure(o);
|
||||
nc->_nparamscheck = nparamscheck;
|
||||
if(typemask) {
|
||||
SQIntVec res;
|
||||
if(!CompileTypemask(res, typemask))
|
||||
return sq_throwerror(v, _SC("invalid typemask"));
|
||||
return sq_throwerror(v, "invalid typemask");
|
||||
nc->_typecheck.copy(res);
|
||||
}
|
||||
else {
|
||||
@@ -408,12 +414,12 @@ SQRESULT sq_bindenv(HSQUIRRELVM v,SQInteger idx)
|
||||
SQObjectPtr &o = stack_get(v,idx);
|
||||
if(!sq_isnativeclosure(o) &&
|
||||
!sq_isclosure(o))
|
||||
return sq_throwerror(v,_SC("the target is not a closure"));
|
||||
return sq_throwerror(v,"the target is not a closure");
|
||||
SQObjectPtr &env = stack_get(v,-1);
|
||||
if(!sq_istable(env) &&
|
||||
!sq_isclass(env) &&
|
||||
!sq_isinstance(env))
|
||||
return sq_throwerror(v,_SC("invalid environment"));
|
||||
return sq_throwerror(v,"invalid environment");
|
||||
SQObjectPtr w = _refcounted(env)->GetWeakRef(type(env));
|
||||
SQObjectPtr ret;
|
||||
if(sq_isclosure(o)) {
|
||||
@@ -438,7 +444,7 @@ SQRESULT sq_clear(HSQUIRRELVM v,SQInteger idx)
|
||||
case OT_TABLE: _table(o)->Clear(); break;
|
||||
case OT_ARRAY: _array(o)->Resize(0); break;
|
||||
default:
|
||||
return sq_throwerror(v, _SC("clear only works on table and array"));
|
||||
return sq_throwerror(v, "clear only works on table and array");
|
||||
break;
|
||||
|
||||
}
|
||||
@@ -468,7 +474,7 @@ SQRESULT sq_setroottable(HSQUIRRELVM v)
|
||||
v->Pop();
|
||||
return SQ_OK;
|
||||
}
|
||||
return sq_throwerror(v, _SC("ivalid type"));
|
||||
return sq_throwerror(v, "ivalid type");
|
||||
}
|
||||
|
||||
SQRESULT sq_setconsttable(HSQUIRRELVM v)
|
||||
@@ -479,7 +485,7 @@ SQRESULT sq_setconsttable(HSQUIRRELVM v)
|
||||
v->Pop();
|
||||
return SQ_OK;
|
||||
}
|
||||
return sq_throwerror(v, _SC("ivalid type, expected table"));
|
||||
return sq_throwerror(v, "ivalid type, expected table");
|
||||
}
|
||||
|
||||
void sq_setforeignptr(HSQUIRRELVM v,SQUserPointer p)
|
||||
@@ -605,7 +611,7 @@ SQRESULT sq_settypetag(HSQUIRRELVM v,SQInteger idx,SQUserPointer typetag)
|
||||
switch(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"));
|
||||
default: return sq_throwerror(v,"invalid object type");
|
||||
}
|
||||
return SQ_OK;
|
||||
}
|
||||
@@ -625,7 +631,7 @@ 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"));
|
||||
return sq_throwerror(v,"invalid object type");
|
||||
return SQ_OK;
|
||||
}
|
||||
|
||||
@@ -640,7 +646,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(type(o) != OT_INSTANCE) return sq_throwerror(v,"the object is not a class instance");
|
||||
_instance(o)->_userpointer = p;
|
||||
return SQ_OK;
|
||||
}
|
||||
@@ -648,8 +654,8 @@ 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(_class(o)->_locked) return sq_throwerror(v,_SC("the class is locked"));
|
||||
if(type(o) != OT_CLASS) return sq_throwerror(v,"the object is not a class");
|
||||
if(_class(o)->_locked) return sq_throwerror(v,"the class is locked");
|
||||
_class(o)->_udsize = udsize;
|
||||
return SQ_OK;
|
||||
}
|
||||
@@ -658,7 +664,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(type(o) != OT_INSTANCE) return sq_throwerror(v,"the object is not a class instance");
|
||||
(*p) = _instance(o)->_userpointer;
|
||||
if(typetag != 0) {
|
||||
SQClass *cl = _instance(o)->_class;
|
||||
@@ -667,7 +673,7 @@ SQRESULT sq_getinstanceup(HSQUIRRELVM v, SQInteger idx, SQUserPointer *p,SQUserP
|
||||
return SQ_OK;
|
||||
cl = cl->_base;
|
||||
}while(cl != NULL);
|
||||
return sq_throwerror(v,_SC("invalid type tag"));
|
||||
return sq_throwerror(v,"invalid type tag");
|
||||
}
|
||||
return SQ_OK;
|
||||
}
|
||||
@@ -717,7 +723,7 @@ SQRESULT sq_newslot(HSQUIRRELVM v, SQInteger idx, SQBool bstatic)
|
||||
SQObjectPtr &self = stack_get(v, idx);
|
||||
if(type(self) == OT_TABLE || 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(type(key) == OT_NULL) return sq_throwerror(v, "null is not a valid key");
|
||||
v->NewSlot(self, key, v->GetUp(-1),bstatic?true:false);
|
||||
v->Pop(2);
|
||||
}
|
||||
@@ -730,7 +736,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(type(key) == OT_NULL) return sq_throwerror(v, "null is not a valid key");
|
||||
SQObjectPtr res;
|
||||
if(!v->DeleteSlot(*self, key, res)){
|
||||
return SQ_ERROR;
|
||||
@@ -753,7 +759,7 @@ SQRESULT sq_set(HSQUIRRELVM v,SQInteger idx)
|
||||
SQRESULT sq_rawset(HSQUIRRELVM v,SQInteger idx)
|
||||
{
|
||||
SQObjectPtr &self = stack_get(v, idx);
|
||||
if(type(v->GetUp(-2)) == OT_NULL) return sq_throwerror(v, _SC("null key"));
|
||||
if(type(v->GetUp(-2)) == OT_NULL) return sq_throwerror(v, "null key");
|
||||
switch(type(self)) {
|
||||
case OT_TABLE:
|
||||
_table(self)->NewSlot(v->GetUp(-2), v->GetUp(-1));
|
||||
@@ -779,7 +785,7 @@ SQRESULT sq_rawset(HSQUIRRELVM v,SQInteger idx)
|
||||
break;
|
||||
default:
|
||||
v->Pop(2);
|
||||
return sq_throwerror(v, _SC("rawset works only on array/table/class and instance"));
|
||||
return sq_throwerror(v, "rawset works only on array/table/class and instance");
|
||||
}
|
||||
v->Raise_IdxError(v->GetUp(-2));return SQ_ERROR;
|
||||
}
|
||||
@@ -792,7 +798,7 @@ SQRESULT sq_setdelegate(HSQUIRRELVM v,SQInteger idx)
|
||||
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();}
|
||||
if(!_table(self)->SetDelegate(_table(mt))) return sq_throwerror(v, "delagate cycle"); v->Pop();}
|
||||
else if(type(mt)==OT_NULL) {
|
||||
_table(self)->SetDelegate(NULL); v->Pop(); }
|
||||
else return sq_aux_invalidtype(v,type);
|
||||
@@ -841,7 +847,7 @@ SQRESULT sq_getdelegate(HSQUIRRELVM v,SQInteger idx)
|
||||
}
|
||||
v->Push(SQObjectPtr(_delegable(self)->_delegate));
|
||||
break;
|
||||
default: return sq_throwerror(v,_SC("wrong type")); break;
|
||||
default: return sq_throwerror(v,"wrong type"); break;
|
||||
}
|
||||
return SQ_OK;
|
||||
|
||||
@@ -853,7 +859,7 @@ SQRESULT sq_get(HSQUIRRELVM v,SQInteger idx)
|
||||
if(v->Get(self,v->GetUp(-1),v->GetUp(-1),false,false))
|
||||
return SQ_OK;
|
||||
v->Pop(1);
|
||||
return sq_throwerror(v,_SC("the index doesn't exist"));
|
||||
return sq_throwerror(v,"the index doesn't exist");
|
||||
}
|
||||
|
||||
SQRESULT sq_rawget(HSQUIRRELVM v,SQInteger idx)
|
||||
@@ -878,10 +884,10 @@ SQRESULT sq_rawget(HSQUIRRELVM v,SQInteger idx)
|
||||
break;
|
||||
default:
|
||||
v->Pop(1);
|
||||
return sq_throwerror(v,_SC("rawget works only on array/table/instance and class"));
|
||||
return sq_throwerror(v,"rawget works only on array/table/instance and class");
|
||||
}
|
||||
v->Pop(1);
|
||||
return sq_throwerror(v,_SC("the index doesn't exist"));
|
||||
return sq_throwerror(v,"the index doesn't exist");
|
||||
}
|
||||
|
||||
SQRESULT sq_getstackobj(HSQUIRRELVM v,SQInteger idx,HSQOBJECT *po)
|
||||
@@ -959,7 +965,7 @@ SQRESULT sq_resume(HSQUIRRELVM v,SQBool retval,SQBool raiseerror)
|
||||
v->Pop();
|
||||
return SQ_OK;
|
||||
}
|
||||
return sq_throwerror(v,_SC("only generators can be resumed"));
|
||||
return sq_throwerror(v,"only generators can be resumed");
|
||||
}
|
||||
|
||||
SQRESULT sq_call(HSQUIRRELVM v,SQInteger params,SQBool retval,SQBool raiseerror, int suspend)
|
||||
@@ -981,9 +987,6 @@ SQRESULT sq_call(HSQUIRRELVM v,SQInteger params,SQBool retval,SQBool raiseerror,
|
||||
v->Pop(params);
|
||||
return SQ_ERROR;
|
||||
}
|
||||
if(!v->_suspended)
|
||||
v->Pop(params);
|
||||
return sq_throwerror(v,_SC("call failed"));
|
||||
}
|
||||
|
||||
SQRESULT sq_suspendvm(HSQUIRRELVM v)
|
||||
@@ -995,7 +998,7 @@ SQRESULT sq_wakeupvm(HSQUIRRELVM v,SQBool wakeupret,SQBool retval,SQBool raiseer
|
||||
{
|
||||
SQObjectPtr ret;
|
||||
if(!v->_suspended)
|
||||
return sq_throwerror(v,_SC("cannot resume a vm that is not running any code"));
|
||||
return sq_throwerror(v,"cannot resume a vm that is not running any code");
|
||||
if(wakeupret) {
|
||||
v->GetAt(v->_stackbase+v->_suspended_target)=v->GetUp(-1); //retval
|
||||
v->Pop();
|
||||
@@ -1051,7 +1054,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(w(up,&tag,2) != 2)
|
||||
return sq_throwerror(v,_SC("io error"));
|
||||
return sq_throwerror(v,"io error");
|
||||
if(!_closure(*o)->Save(v,up,w))
|
||||
return SQ_ERROR;
|
||||
return SQ_OK;
|
||||
@@ -1063,9 +1066,9 @@ SQRESULT sq_readclosure(HSQUIRRELVM v,SQREADFUNC r,SQUserPointer up)
|
||||
|
||||
unsigned short tag;
|
||||
if(r(up,&tag,2) != 2)
|
||||
return sq_throwerror(v,_SC("io error"));
|
||||
return sq_throwerror(v,"io error");
|
||||
if(tag != SQ_BYTECODE_STREAM_TAG)
|
||||
return sq_throwerror(v,_SC("invalid stream"));
|
||||
return sq_throwerror(v,"invalid stream");
|
||||
if(!SQClosure::Load(v,up,r,closure))
|
||||
return SQ_ERROR;
|
||||
v->Push(closure);
|
||||
@@ -1110,13 +1113,13 @@ SQRESULT sq_setfreevariable(HSQUIRRELVM v,SQInteger idx,SQUnsignedInteger nval)
|
||||
if(_closure(self)->_outervalues.size()>nval){
|
||||
_closure(self)->_outervalues[nval]=stack_get(v,-1);
|
||||
}
|
||||
else return sq_throwerror(v,_SC("invalid free var index"));
|
||||
else return sq_throwerror(v,"invalid free var index");
|
||||
break;
|
||||
case OT_NATIVECLOSURE:
|
||||
if(_nativeclosure(self)->_outervalues.size()>nval){
|
||||
_nativeclosure(self)->_outervalues[nval]=stack_get(v,-1);
|
||||
}
|
||||
else return sq_throwerror(v,_SC("invalid free var index"));
|
||||
else return sq_throwerror(v,"invalid free var index");
|
||||
break;
|
||||
default:
|
||||
return sq_aux_invalidtype(v,type(self));
|
||||
@@ -1144,7 +1147,7 @@ SQRESULT sq_setattributes(HSQUIRRELVM v,SQInteger idx)
|
||||
v->Push(attrs);
|
||||
return SQ_OK;
|
||||
}
|
||||
return sq_throwerror(v,_SC("wrong index"));
|
||||
return sq_throwerror(v,"wrong index");
|
||||
}
|
||||
|
||||
SQRESULT sq_getattributes(HSQUIRRELVM v,SQInteger idx)
|
||||
@@ -1164,7 +1167,7 @@ SQRESULT sq_getattributes(HSQUIRRELVM v,SQInteger idx)
|
||||
v->Push(attrs);
|
||||
return SQ_OK;
|
||||
}
|
||||
return sq_throwerror(v,_SC("wrong index"));
|
||||
return sq_throwerror(v,"wrong index");
|
||||
}
|
||||
|
||||
SQRESULT sq_getbase(HSQUIRRELVM v,SQInteger idx)
|
||||
@@ -1208,7 +1211,7 @@ SQRESULT sq_getweakrefval(HSQUIRRELVM v,SQInteger idx)
|
||||
{
|
||||
SQObjectPtr &o = stack_get(v,idx);
|
||||
if(type(o) != OT_WEAKREF) {
|
||||
return sq_throwerror(v,_SC("the object must be a weakref"));
|
||||
return sq_throwerror(v,"the object must be a weakref");
|
||||
}
|
||||
v->Push(_weakref(o)->_obj);
|
||||
return SQ_OK;
|
||||
@@ -1228,7 +1231,7 @@ SQRESULT sq_getdefaultdelegate(HSQUIRRELVM v,SQObjectType t)
|
||||
case OT_CLASS: v->Push(ss->_class_default_delegate); break;
|
||||
case OT_INSTANCE: v->Push(ss->_instance_default_delegate); break;
|
||||
case OT_WEAKREF: v->Push(ss->_weakref_default_delegate); break;
|
||||
default: return sq_throwerror(v,_SC("the type doesn't have a default delegate"));
|
||||
default: return sq_throwerror(v,"the type doesn't have a default delegate");
|
||||
}
|
||||
return SQ_OK;
|
||||
}
|
||||
@@ -1237,7 +1240,7 @@ 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) {
|
||||
return sq_throwerror(v,_SC("cannot iterate a generator"));
|
||||
return sq_throwerror(v,"cannot iterate a generator");
|
||||
}
|
||||
int faketojump;
|
||||
if(!v->FOREACH_OP(o,realkey,val,refpos,0,666,faketojump))
|
||||
@@ -1256,12 +1259,30 @@ struct BufState{
|
||||
SQInteger size;
|
||||
};
|
||||
|
||||
SQInteger buf_lexfeed(SQUserPointer file)
|
||||
WChar buf_lexfeed(SQUserPointer file)
|
||||
{
|
||||
BufState *buf=(BufState*)file;
|
||||
if(buf->size<(buf->ptr+1))
|
||||
return 0;
|
||||
return buf->buf[buf->ptr++];
|
||||
/* Convert an UTF-8 character into a WChar */
|
||||
BufState *buf = (BufState *)file;
|
||||
const char *p = &buf->buf[buf->ptr];
|
||||
|
||||
if (buf->size < buf->ptr + 1) return 0;
|
||||
|
||||
/* Read the first character, and get the length based on UTF-8 specs. If invalid, bail out. */
|
||||
uint len = Utf8EncodedCharLen(*p);
|
||||
if (len == 0) {
|
||||
buf->ptr++;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Read the remaining bits. */
|
||||
if (buf->size < buf->ptr + len) return 0;
|
||||
buf->ptr += len;
|
||||
|
||||
/* Convert the character, and when definitely invalid, bail out as well. */
|
||||
WChar c;
|
||||
if (Utf8Decode(&c, p) != len) return -1;
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
SQRESULT sq_compilebuffer(HSQUIRRELVM v,const SQChar *s,SQInteger size,const SQChar *sourcename,SQBool raiseerror) {
|
||||
|
304
src/3rdparty/squirrel/squirrel/sqbaselib.cpp
vendored
304
src/3rdparty/squirrel/squirrel/sqbaselib.cpp
vendored
@@ -1,8 +1,13 @@
|
||||
/*
|
||||
see copyright notice in squirrel.h
|
||||
*/
|
||||
/* Needs to be first due to a squirrel header defining type() and type()
|
||||
* being used in some versions of the headers included by algorithm. */
|
||||
* see copyright notice in squirrel.h
|
||||
*/
|
||||
/*
|
||||
* Needs to be first due to a squirrel header defining type() and type()
|
||||
* being used in some versions of the headers included by algorithm.
|
||||
*/
|
||||
|
||||
#include "../../../stdafx.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include "sqpcheader.h"
|
||||
#include "sqvm.h"
|
||||
@@ -12,21 +17,22 @@
|
||||
#include "sqfuncproto.h"
|
||||
#include "sqclosure.h"
|
||||
#include "sqclass.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include "../../../safeguards.h"
|
||||
|
||||
bool str2num(const SQChar *s,SQObjectPtr &res)
|
||||
{
|
||||
SQChar *end;
|
||||
if(scstrstr(s,_SC("."))){
|
||||
SQFloat r = SQFloat(scstrtod(s,&end));
|
||||
if(strstr(s,".")){
|
||||
SQFloat r = SQFloat(strtod(s,&end));
|
||||
if(s == end) return false;
|
||||
res = r;
|
||||
return true;
|
||||
}
|
||||
else{
|
||||
SQInteger r = SQInteger(scstrtol(s,&end,10));
|
||||
SQInteger r = SQInteger(strtol(s,&end,10));
|
||||
if(s == end) return false;
|
||||
res = r;
|
||||
return true;
|
||||
@@ -104,21 +110,21 @@ static SQInteger base_getstackinfos(HSQUIRRELVM v)
|
||||
sq_getinteger(v, -1, &level);
|
||||
if (SQ_SUCCEEDED(sq_stackinfos(v, level, &si)))
|
||||
{
|
||||
const SQChar *fn = _SC("unknown");
|
||||
const SQChar *src = _SC("unknown");
|
||||
const SQChar *fn = "unknown";
|
||||
const SQChar *src = "unknown";
|
||||
if(si.funcname)fn = si.funcname;
|
||||
if(si.source)src = si.source;
|
||||
sq_newtable(v);
|
||||
sq_pushstring(v, _SC("func"), -1);
|
||||
sq_pushstring(v, "func", -1);
|
||||
sq_pushstring(v, fn, -1);
|
||||
sq_createslot(v, -3);
|
||||
sq_pushstring(v, _SC("src"), -1);
|
||||
sq_pushstring(v, "src", -1);
|
||||
sq_pushstring(v, src, -1);
|
||||
sq_createslot(v, -3);
|
||||
sq_pushstring(v, _SC("line"), -1);
|
||||
sq_pushstring(v, "line", -1);
|
||||
sq_pushinteger(v, si.line);
|
||||
sq_createslot(v, -3);
|
||||
sq_pushstring(v, _SC("locals"), -1);
|
||||
sq_pushstring(v, "locals", -1);
|
||||
sq_newtable(v);
|
||||
seq=0;
|
||||
while ((name = sq_getlocal(v, level, seq))) {
|
||||
@@ -139,7 +145,7 @@ static SQInteger base_getstackinfos(HSQUIRRELVM v)
|
||||
static SQInteger base_assert(HSQUIRRELVM v)
|
||||
{
|
||||
if(v->IsFalse(stack_get(v,2))){
|
||||
return sq_throwerror(v,_SC("assertion failed"));
|
||||
return sq_throwerror(v,"assertion failed");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -171,7 +177,7 @@ static SQInteger base_print(HSQUIRRELVM v)
|
||||
const SQChar *str;
|
||||
sq_tostring(v,2);
|
||||
sq_getstring(v,-1,&str);
|
||||
if(_ss(v)->_printfunc) _ss(v)->_printfunc(v,_SC("%s"),str);
|
||||
if(_ss(v)->_printfunc) _ss(v)->_printfunc(v,"%s",str);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -179,7 +185,7 @@ static SQInteger base_print(HSQUIRRELVM v)
|
||||
static SQInteger base_compilestring(HSQUIRRELVM v)
|
||||
{
|
||||
SQInteger nargs=sq_gettop(v);
|
||||
const SQChar *src=NULL,*name=_SC("unnamedbuffer");
|
||||
const SQChar *src=NULL,*name="unnamedbuffer";
|
||||
SQInteger size;
|
||||
sq_getstring(v,2,&src);
|
||||
size=sq_getsize(v,2);
|
||||
@@ -210,16 +216,22 @@ static SQInteger base_suspend(HSQUIRRELVM v)
|
||||
static SQInteger base_array(HSQUIRRELVM v)
|
||||
{
|
||||
SQArray *a;
|
||||
SQObject &size = stack_get(v,2);
|
||||
SQInteger nInitialSize = tointeger(stack_get(v,2));
|
||||
SQInteger ret = 1;
|
||||
if (nInitialSize < 0) {
|
||||
v->Raise_Error("can't create/resize array with/to size %d", nInitialSize);
|
||||
nInitialSize = 0;
|
||||
ret = -1;
|
||||
}
|
||||
if(sq_gettop(v) > 2) {
|
||||
a = SQArray::Create(_ss(v),0);
|
||||
a->Resize(tointeger(size),stack_get(v,3));
|
||||
a->Resize(nInitialSize,stack_get(v,3));
|
||||
}
|
||||
else {
|
||||
a = SQArray::Create(_ss(v),tointeger(size));
|
||||
a = SQArray::Create(_ss(v),nInitialSize);
|
||||
}
|
||||
v->Push(a);
|
||||
return 1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
static SQInteger base_type(HSQUIRRELVM v)
|
||||
@@ -232,28 +244,28 @@ static SQInteger base_type(HSQUIRRELVM v)
|
||||
static SQRegFunction base_funcs[]={
|
||||
//generic
|
||||
#ifdef EXPORT_DEFAULT_SQUIRREL_FUNCTIONS
|
||||
{_SC("seterrorhandler"),base_seterrorhandler,2, NULL},
|
||||
{_SC("setdebughook"),base_setdebughook,2, NULL},
|
||||
{_SC("enabledebuginfo"),base_enabledebuginfo,2, NULL},
|
||||
{_SC("getstackinfos"),base_getstackinfos,2, _SC(".n")},
|
||||
{_SC("getroottable"),base_getroottable,1, NULL},
|
||||
{_SC("setroottable"),base_setroottable,2, NULL},
|
||||
{_SC("getconsttable"),base_getconsttable,1, NULL},
|
||||
{_SC("setconsttable"),base_setconsttable,2, NULL},
|
||||
{"seterrorhandler",base_seterrorhandler,2, NULL},
|
||||
{"setdebughook",base_setdebughook,2, NULL},
|
||||
{"enabledebuginfo",base_enabledebuginfo,2, NULL},
|
||||
{"getstackinfos",base_getstackinfos,2, ".n"},
|
||||
{"getroottable",base_getroottable,1, NULL},
|
||||
{"setroottable",base_setroottable,2, NULL},
|
||||
{"getconsttable",base_getconsttable,1, NULL},
|
||||
{"setconsttable",base_setconsttable,2, NULL},
|
||||
#endif
|
||||
{_SC("assert"),base_assert,2, NULL},
|
||||
{_SC("print"),base_print,2, NULL},
|
||||
{"assert",base_assert,2, NULL},
|
||||
{"print",base_print,2, NULL},
|
||||
#ifdef EXPORT_DEFAULT_SQUIRREL_FUNCTIONS
|
||||
{_SC("compilestring"),base_compilestring,-2, _SC(".ss")},
|
||||
{_SC("newthread"),base_newthread,2, _SC(".c")},
|
||||
{_SC("suspend"),base_suspend,-1, NULL},
|
||||
{"compilestring",base_compilestring,-2, ".ss"},
|
||||
{"newthread",base_newthread,2, ".c"},
|
||||
{"suspend",base_suspend,-1, NULL},
|
||||
#endif
|
||||
{_SC("array"),base_array,-2, _SC(".n")},
|
||||
{_SC("type"),base_type,2, NULL},
|
||||
{"array",base_array,-2, ".n"},
|
||||
{"type",base_type,2, NULL},
|
||||
#ifdef EXPORT_DEFAULT_SQUIRREL_FUNCTIONS
|
||||
{_SC("dummy"),base_dummy,0,NULL},
|
||||
{"dummy",base_dummy,0,NULL},
|
||||
#ifndef NO_GARBAGE_COLLECTOR
|
||||
{_SC("collectgarbage"),base_collectgarbage,1, _SC("t")},
|
||||
{"collectgarbage",base_collectgarbage,1, "t"},
|
||||
#endif
|
||||
#endif
|
||||
{0,0,0,0}
|
||||
@@ -271,16 +283,16 @@ void sq_base_register(HSQUIRRELVM v)
|
||||
sq_createslot(v,-3);
|
||||
i++;
|
||||
}
|
||||
sq_pushstring(v,_SC("_version_"),-1);
|
||||
sq_pushstring(v,"_version_",-1);
|
||||
sq_pushstring(v,SQUIRREL_VERSION,-1);
|
||||
sq_createslot(v,-3);
|
||||
sq_pushstring(v,_SC("_charsize_"),-1);
|
||||
sq_pushstring(v,"_charsize_",-1);
|
||||
sq_pushinteger(v,sizeof(SQChar));
|
||||
sq_createslot(v,-3);
|
||||
sq_pushstring(v,_SC("_intsize_"),-1);
|
||||
sq_pushstring(v,"_intsize_",-1);
|
||||
sq_pushinteger(v,sizeof(SQInteger));
|
||||
sq_createslot(v,-3);
|
||||
sq_pushstring(v,_SC("_floatsize_"),-1);
|
||||
sq_pushstring(v,"_floatsize_",-1);
|
||||
sq_pushinteger(v,sizeof(SQFloat));
|
||||
sq_createslot(v,-3);
|
||||
sq_pop(v,1);
|
||||
@@ -302,7 +314,7 @@ static SQInteger default_delegate_tofloat(HSQUIRRELVM v)
|
||||
v->Push(SQObjectPtr(tofloat(res)));
|
||||
break;
|
||||
}}
|
||||
return sq_throwerror(v, _SC("cannot convert the string"));
|
||||
return sq_throwerror(v, "cannot convert the string");
|
||||
break;
|
||||
case OT_INTEGER:case OT_FLOAT:
|
||||
v->Push(SQObjectPtr(tofloat(o)));
|
||||
@@ -327,7 +339,7 @@ static SQInteger default_delegate_tointeger(HSQUIRRELVM v)
|
||||
v->Push(SQObjectPtr(tointeger(res)));
|
||||
break;
|
||||
}}
|
||||
return sq_throwerror(v, _SC("cannot convert the string"));
|
||||
return sq_throwerror(v, "cannot convert the string");
|
||||
break;
|
||||
case OT_INTEGER:case OT_FLOAT:
|
||||
v->Push(SQObjectPtr(tointeger(o)));
|
||||
@@ -403,14 +415,14 @@ static SQInteger table_rawget(HSQUIRRELVM v)
|
||||
|
||||
|
||||
SQRegFunction SQSharedState::_table_default_delegate_funcz[]={
|
||||
{_SC("len"),default_delegate_len,1, _SC("t")},
|
||||
{_SC("rawget"),table_rawget,2, _SC("t")},
|
||||
{_SC("rawset"),table_rawset,3, _SC("t")},
|
||||
{_SC("rawdelete"),table_rawdelete,2, _SC("t")},
|
||||
{_SC("rawin"),container_rawexists,2, _SC("t")},
|
||||
{_SC("weakref"),obj_delegate_weakref,1, NULL },
|
||||
{_SC("tostring"),default_delegate_tostring,1, _SC(".")},
|
||||
{_SC("clear"),obj_clear,1, _SC(".")},
|
||||
{"len",default_delegate_len,1, "t"},
|
||||
{"rawget",table_rawget,2, "t"},
|
||||
{"rawset",table_rawset,3, "t"},
|
||||
{"rawdelete",table_rawdelete,2, "t"},
|
||||
{"rawin",container_rawexists,2, "t"},
|
||||
{"weakref",obj_delegate_weakref,1, NULL },
|
||||
{"tostring",default_delegate_tostring,1, "."},
|
||||
{"clear",obj_clear,1, "."},
|
||||
{0,0,0,0}
|
||||
};
|
||||
|
||||
@@ -444,7 +456,7 @@ static SQInteger array_top(HSQUIRRELVM v)
|
||||
v->Push(_array(o)->Top());
|
||||
return 1;
|
||||
}
|
||||
else return sq_throwerror(v,_SC("top() on a empty array"));
|
||||
else return sq_throwerror(v,"top() on a empty array");
|
||||
}
|
||||
|
||||
static SQInteger array_insert(HSQUIRRELVM v)
|
||||
@@ -453,7 +465,7 @@ static SQInteger array_insert(HSQUIRRELVM v)
|
||||
SQObject &idx=stack_get(v,2);
|
||||
SQObject &val=stack_get(v,3);
|
||||
if(!_array(o)->Insert(tointeger(idx),val))
|
||||
return sq_throwerror(v,_SC("index out of range"));
|
||||
return sq_throwerror(v,"index out of range");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -461,14 +473,14 @@ static SQInteger array_remove(HSQUIRRELVM v)
|
||||
{
|
||||
SQObject &o = stack_get(v, 1);
|
||||
SQObject &idx = stack_get(v, 2);
|
||||
if(!sq_isnumeric(idx)) return sq_throwerror(v, _SC("wrong type"));
|
||||
if(!sq_isnumeric(idx)) return sq_throwerror(v, "wrong type");
|
||||
SQObjectPtr val;
|
||||
if(_array(o)->Get(tointeger(idx), val)) {
|
||||
_array(o)->Remove(tointeger(idx));
|
||||
v->Push(val);
|
||||
return 1;
|
||||
}
|
||||
return sq_throwerror(v, _SC("idx out of range"));
|
||||
return sq_throwerror(v, "idx out of range");
|
||||
}
|
||||
|
||||
static SQInteger array_resize(HSQUIRRELVM v)
|
||||
@@ -482,7 +494,7 @@ static SQInteger array_resize(HSQUIRRELVM v)
|
||||
_array(o)->Resize(tointeger(nsize),fill);
|
||||
return 0;
|
||||
}
|
||||
return sq_throwerror(v, _SC("size must be a number"));
|
||||
return sq_throwerror(v, "size must be a number");
|
||||
}
|
||||
|
||||
|
||||
@@ -499,11 +511,11 @@ bool _sort_compare(HSQUIRRELVM v,SQObjectPtr &a,SQObjectPtr &b,SQInteger func,SQ
|
||||
v->Push(b);
|
||||
if(SQ_FAILED(sq_call(v, 3, SQTrue, SQFalse))) {
|
||||
if(!sq_isstring( v->_lasterror))
|
||||
v->Raise_Error(_SC("compare func failed"));
|
||||
v->Raise_Error("compare func failed");
|
||||
return false;
|
||||
}
|
||||
if(SQ_FAILED(sq_getinteger(v, -1, &ret))) {
|
||||
v->Raise_Error(_SC("numeric value expected as return value of the compare function"));
|
||||
v->Raise_Error("numeric value expected as return value of the compare function");
|
||||
return false;
|
||||
}
|
||||
sq_settop(v, top);
|
||||
@@ -539,7 +551,7 @@ bool _hsort_sift_down(HSQUIRRELVM v,SQArray *arr, SQInteger root, SQInteger bott
|
||||
return false;
|
||||
if (ret < 0) {
|
||||
if (root == maxChild) {
|
||||
v->Raise_Error(_SC("inconsistent compare function"));
|
||||
v->Raise_Error("inconsistent compare function");
|
||||
return false; // We'd be swapping ourselve. The compare function is incorrect
|
||||
}
|
||||
_Swap(arr->_values[root],arr->_values[maxChild]);
|
||||
@@ -590,8 +602,8 @@ static SQInteger array_slice(HSQUIRRELVM v)
|
||||
SQInteger alen = _array(o)->Size();
|
||||
if(sidx < 0)sidx = alen + sidx;
|
||||
if(eidx < 0)eidx = alen + eidx;
|
||||
if(eidx < sidx)return sq_throwerror(v,_SC("wrong indexes"));
|
||||
if(eidx > alen)return sq_throwerror(v,_SC("slice out of range"));
|
||||
if(eidx < sidx)return sq_throwerror(v,"wrong indexes");
|
||||
if(eidx > alen)return sq_throwerror(v,"slice out of range");
|
||||
SQArray *arr=SQArray::Create(_ss(v),eidx-sidx);
|
||||
SQObjectPtr t;
|
||||
SQInteger count=0;
|
||||
@@ -605,21 +617,21 @@ static SQInteger array_slice(HSQUIRRELVM v)
|
||||
}
|
||||
|
||||
SQRegFunction SQSharedState::_array_default_delegate_funcz[]={
|
||||
{_SC("len"),default_delegate_len,1, _SC("a")},
|
||||
{_SC("append"),array_append,2, _SC("a")},
|
||||
{_SC("extend"),array_extend,2, _SC("aa")},
|
||||
{_SC("push"),array_append,2, _SC("a")},
|
||||
{_SC("pop"),array_pop,1, _SC("a")},
|
||||
{_SC("top"),array_top,1, _SC("a")},
|
||||
{_SC("insert"),array_insert,3, _SC("an")},
|
||||
{_SC("remove"),array_remove,2, _SC("an")},
|
||||
{_SC("resize"),array_resize,-2, _SC("an")},
|
||||
{_SC("reverse"),array_reverse,1, _SC("a")},
|
||||
{_SC("sort"),array_sort,-1, _SC("ac")},
|
||||
{_SC("slice"),array_slice,-1, _SC("ann")},
|
||||
{_SC("weakref"),obj_delegate_weakref,1, NULL },
|
||||
{_SC("tostring"),default_delegate_tostring,1, _SC(".")},
|
||||
{_SC("clear"),obj_clear,1, _SC(".")},
|
||||
{"len",default_delegate_len,1, "a"},
|
||||
{"append",array_append,2, "a"},
|
||||
{"extend",array_extend,2, "aa"},
|
||||
{"push",array_append,2, "a"},
|
||||
{"pop",array_pop,1, "a"},
|
||||
{"top",array_top,1, "a"},
|
||||
{"insert",array_insert,3, "an"},
|
||||
{"remove",array_remove,2, "an"},
|
||||
{"resize",array_resize,-2, "an"},
|
||||
{"reverse",array_reverse,1, "a"},
|
||||
{"sort",array_sort,-1, "ac"},
|
||||
{"slice",array_slice,-1, "ann"},
|
||||
{"weakref",obj_delegate_weakref,1, NULL },
|
||||
{"tostring",default_delegate_tostring,1, "."},
|
||||
{"clear",obj_clear,1, "."},
|
||||
{0,0,0,0}
|
||||
};
|
||||
|
||||
@@ -632,8 +644,8 @@ static SQInteger string_slice(HSQUIRRELVM v)
|
||||
SQInteger slen = _string(o)->_len;
|
||||
if(sidx < 0)sidx = slen + sidx;
|
||||
if(eidx < 0)eidx = slen + eidx;
|
||||
if(eidx < sidx) return sq_throwerror(v,_SC("wrong indexes"));
|
||||
if(eidx > slen) return sq_throwerror(v,_SC("slice out of range"));
|
||||
if(eidx < sidx) return sq_throwerror(v,"wrong indexes");
|
||||
if(eidx > slen) return sq_throwerror(v,"slice out of range");
|
||||
v->Push(SQString::Create(_ss(v),&_stringval(o)[sidx],eidx-sidx));
|
||||
return 1;
|
||||
}
|
||||
@@ -645,7 +657,7 @@ static SQInteger string_find(HSQUIRRELVM v)
|
||||
if(((top=sq_gettop(v))>1) && SQ_SUCCEEDED(sq_getstring(v,1,&str)) && SQ_SUCCEEDED(sq_getstring(v,2,&substr))){
|
||||
if(top>2)sq_getinteger(v,3,&start_idx);
|
||||
if((sq_getsize(v,1)>start_idx) && (start_idx>=0)){
|
||||
ret=scstrstr(&str[start_idx],substr);
|
||||
ret=strstr(&str[start_idx],substr);
|
||||
if(ret){
|
||||
sq_pushinteger(v,(SQInteger)(ret-str));
|
||||
return 1;
|
||||
@@ -653,7 +665,7 @@ static SQInteger string_find(HSQUIRRELVM v)
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
return sq_throwerror(v,_SC("invalid param"));
|
||||
return sq_throwerror(v,"invalid param");
|
||||
}
|
||||
|
||||
#define STRING_TOFUNCZ(func) static SQInteger string_##func(HSQUIRRELVM v) \
|
||||
@@ -661,7 +673,7 @@ static SQInteger string_find(HSQUIRRELVM v)
|
||||
SQObject str=stack_get(v,1); \
|
||||
SQInteger len=_string(str)->_len; \
|
||||
const SQChar *sThis=_stringval(str); \
|
||||
SQChar *sNew=(_ss(v)->GetScratchPad(rsl(len))); \
|
||||
SQChar *sNew=(_ss(v)->GetScratchPad(len)); \
|
||||
for(SQInteger i=0;i<len;i++) sNew[i]=func(sThis[i]); \
|
||||
v->Push(SQString::Create(_ss(v),sNew,len)); \
|
||||
return 1; \
|
||||
@@ -672,25 +684,25 @@ STRING_TOFUNCZ(tolower)
|
||||
STRING_TOFUNCZ(toupper)
|
||||
|
||||
SQRegFunction SQSharedState::_string_default_delegate_funcz[]={
|
||||
{_SC("len"),default_delegate_len,1, _SC("s")},
|
||||
{_SC("tointeger"),default_delegate_tointeger,1, _SC("s")},
|
||||
{_SC("tofloat"),default_delegate_tofloat,1, _SC("s")},
|
||||
{_SC("tostring"),default_delegate_tostring,1, _SC(".")},
|
||||
{_SC("slice"),string_slice,-1, _SC(" s n n")},
|
||||
{_SC("find"),string_find,-2, _SC("s s n ")},
|
||||
{_SC("tolower"),string_tolower,1, _SC("s")},
|
||||
{_SC("toupper"),string_toupper,1, _SC("s")},
|
||||
{_SC("weakref"),obj_delegate_weakref,1, NULL },
|
||||
{"len",default_delegate_len,1, "s"},
|
||||
{"tointeger",default_delegate_tointeger,1, "s"},
|
||||
{"tofloat",default_delegate_tofloat,1, "s"},
|
||||
{"tostring",default_delegate_tostring,1, "."},
|
||||
{"slice",string_slice,-1, " s n n"},
|
||||
{"find",string_find,-2, "s s n "},
|
||||
{"tolower",string_tolower,1, "s"},
|
||||
{"toupper",string_toupper,1, "s"},
|
||||
{"weakref",obj_delegate_weakref,1, NULL },
|
||||
{0,0,0,0}
|
||||
};
|
||||
|
||||
//INTEGER DEFAULT DELEGATE//////////////////////////
|
||||
SQRegFunction SQSharedState::_number_default_delegate_funcz[]={
|
||||
{_SC("tointeger"),default_delegate_tointeger,1, _SC("n|b")},
|
||||
{_SC("tofloat"),default_delegate_tofloat,1, _SC("n|b")},
|
||||
{_SC("tostring"),default_delegate_tostring,1, _SC(".")},
|
||||
{_SC("tochar"),number_delegate_tochar,1, _SC("n|b")},
|
||||
{_SC("weakref"),obj_delegate_weakref,1, NULL },
|
||||
{"tointeger",default_delegate_tointeger,1, "n|b"},
|
||||
{"tofloat",default_delegate_tofloat,1, "n|b"},
|
||||
{"tostring",default_delegate_tostring,1, "."},
|
||||
{"tochar",number_delegate_tochar,1, "n|b"},
|
||||
{"weakref",obj_delegate_weakref,1, NULL },
|
||||
{0,0,0,0}
|
||||
};
|
||||
|
||||
@@ -742,19 +754,19 @@ static SQInteger closure_getinfos(HSQUIRRELVM v) {
|
||||
_array(params)->Set((SQInteger)n,f->_parameters[n]);
|
||||
}
|
||||
if(f->_varparams) {
|
||||
_array(params)->Set(nparams-1,SQString::Create(_ss(v),_SC("..."),-1));
|
||||
_array(params)->Set(nparams-1,SQString::Create(_ss(v),"...",-1));
|
||||
}
|
||||
res->NewSlot(SQString::Create(_ss(v),_SC("native"),-1),false);
|
||||
res->NewSlot(SQString::Create(_ss(v),_SC("name"),-1),f->_name);
|
||||
res->NewSlot(SQString::Create(_ss(v),_SC("src"),-1),f->_sourcename);
|
||||
res->NewSlot(SQString::Create(_ss(v),_SC("parameters"),-1),params);
|
||||
res->NewSlot(SQString::Create(_ss(v),_SC("varargs"),-1),f->_varparams);
|
||||
res->NewSlot(SQString::Create(_ss(v),"native",-1),false);
|
||||
res->NewSlot(SQString::Create(_ss(v),"name",-1),f->_name);
|
||||
res->NewSlot(SQString::Create(_ss(v),"src",-1),f->_sourcename);
|
||||
res->NewSlot(SQString::Create(_ss(v),"parameters",-1),params);
|
||||
res->NewSlot(SQString::Create(_ss(v),"varargs",-1),f->_varparams);
|
||||
}
|
||||
else { //OT_NATIVECLOSURE
|
||||
SQNativeClosure *nc = _nativeclosure(o);
|
||||
res->NewSlot(SQString::Create(_ss(v),_SC("native"),-1),true);
|
||||
res->NewSlot(SQString::Create(_ss(v),_SC("name"),-1),nc->_name);
|
||||
res->NewSlot(SQString::Create(_ss(v),_SC("paramscheck"),-1),nc->_nparamscheck);
|
||||
res->NewSlot(SQString::Create(_ss(v),"native",-1),true);
|
||||
res->NewSlot(SQString::Create(_ss(v),"name",-1),nc->_name);
|
||||
res->NewSlot(SQString::Create(_ss(v),"paramscheck",-1),nc->_nparamscheck);
|
||||
SQObjectPtr typecheck;
|
||||
if(nc->_typecheck.size() > 0) {
|
||||
typecheck =
|
||||
@@ -763,7 +775,7 @@ static SQInteger closure_getinfos(HSQUIRRELVM v) {
|
||||
_array(typecheck)->Set((SQInteger)n,nc->_typecheck[n]);
|
||||
}
|
||||
}
|
||||
res->NewSlot(SQString::Create(_ss(v),_SC("typecheck"),-1),typecheck);
|
||||
res->NewSlot(SQString::Create(_ss(v),"typecheck",-1),typecheck);
|
||||
}
|
||||
v->Push(res);
|
||||
return 1;
|
||||
@@ -771,14 +783,14 @@ static SQInteger closure_getinfos(HSQUIRRELVM v) {
|
||||
|
||||
|
||||
SQRegFunction SQSharedState::_closure_default_delegate_funcz[]={
|
||||
{_SC("call"),closure_call,-1, _SC("c")},
|
||||
{_SC("pcall"),closure_pcall,-1, _SC("c")},
|
||||
{_SC("acall"),closure_acall,2, _SC("ca")},
|
||||
{_SC("pacall"),closure_pacall,2, _SC("ca")},
|
||||
{_SC("weakref"),obj_delegate_weakref,1, NULL },
|
||||
{_SC("tostring"),default_delegate_tostring,1, _SC(".")},
|
||||
{_SC("bindenv"),closure_bindenv,2, _SC("c x|y|t")},
|
||||
{_SC("getinfos"),closure_getinfos,1, _SC("c")},
|
||||
{"call",closure_call,-1, "c"},
|
||||
{"pcall",closure_pcall,-1, "c"},
|
||||
{"acall",closure_acall,2, "ca"},
|
||||
{"pacall",closure_pacall,2, "ca"},
|
||||
{"weakref",obj_delegate_weakref,1, NULL },
|
||||
{"tostring",default_delegate_tostring,1, "."},
|
||||
{"bindenv",closure_bindenv,2, "c x|y|t"},
|
||||
{"getinfos",closure_getinfos,1, "c"},
|
||||
{0,0,0,0}
|
||||
};
|
||||
|
||||
@@ -787,17 +799,17 @@ static SQInteger generator_getstatus(HSQUIRRELVM v)
|
||||
{
|
||||
SQObject &o=stack_get(v,1);
|
||||
switch(_generator(o)->_state){
|
||||
case SQGenerator::eSuspended:v->Push(SQString::Create(_ss(v),_SC("suspended")));break;
|
||||
case SQGenerator::eRunning:v->Push(SQString::Create(_ss(v),_SC("running")));break;
|
||||
case SQGenerator::eDead:v->Push(SQString::Create(_ss(v),_SC("dead")));break;
|
||||
case SQGenerator::eSuspended:v->Push(SQString::Create(_ss(v),"suspended"));break;
|
||||
case SQGenerator::eRunning:v->Push(SQString::Create(_ss(v),"running"));break;
|
||||
case SQGenerator::eDead:v->Push(SQString::Create(_ss(v),"dead"));break;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
SQRegFunction SQSharedState::_generator_default_delegate_funcz[]={
|
||||
{_SC("getstatus"),generator_getstatus,1, _SC("g")},
|
||||
{_SC("weakref"),obj_delegate_weakref,1, NULL },
|
||||
{_SC("tostring"),default_delegate_tostring,1, _SC(".")},
|
||||
{"getstatus",generator_getstatus,1, "g"},
|
||||
{"weakref",obj_delegate_weakref,1, NULL },
|
||||
{"tostring",default_delegate_tostring,1, "."},
|
||||
{0,0,0,0}
|
||||
};
|
||||
|
||||
@@ -820,7 +832,7 @@ static SQInteger thread_call(HSQUIRRELVM v)
|
||||
v->_lasterror = _thread(o)->_lasterror;
|
||||
return SQ_ERROR;
|
||||
}
|
||||
return sq_throwerror(v,_SC("wrong parameter"));
|
||||
return sq_throwerror(v,"wrong parameter");
|
||||
}
|
||||
|
||||
static SQInteger thread_wakeup(HSQUIRRELVM v)
|
||||
@@ -832,10 +844,10 @@ static SQInteger thread_wakeup(HSQUIRRELVM v)
|
||||
if(state != SQ_VMSTATE_SUSPENDED) {
|
||||
switch(state) {
|
||||
case SQ_VMSTATE_IDLE:
|
||||
return sq_throwerror(v,_SC("cannot wakeup a idle thread"));
|
||||
return sq_throwerror(v,"cannot wakeup a idle thread");
|
||||
break;
|
||||
case SQ_VMSTATE_RUNNING:
|
||||
return sq_throwerror(v,_SC("cannot wakeup a running thread"));
|
||||
return sq_throwerror(v,"cannot wakeup a running thread");
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -856,7 +868,7 @@ static SQInteger thread_wakeup(HSQUIRRELVM v)
|
||||
v->_lasterror = thread->_lasterror;
|
||||
return SQ_ERROR;
|
||||
}
|
||||
return sq_throwerror(v,_SC("wrong parameter"));
|
||||
return sq_throwerror(v,"wrong parameter");
|
||||
}
|
||||
|
||||
static SQInteger thread_getstatus(HSQUIRRELVM v)
|
||||
@@ -864,26 +876,26 @@ static SQInteger thread_getstatus(HSQUIRRELVM v)
|
||||
SQObjectPtr &o = stack_get(v,1);
|
||||
switch(sq_getvmstate(_thread(o))) {
|
||||
case SQ_VMSTATE_IDLE:
|
||||
sq_pushstring(v,_SC("idle"),-1);
|
||||
sq_pushstring(v,"idle",-1);
|
||||
break;
|
||||
case SQ_VMSTATE_RUNNING:
|
||||
sq_pushstring(v,_SC("running"),-1);
|
||||
sq_pushstring(v,"running",-1);
|
||||
break;
|
||||
case SQ_VMSTATE_SUSPENDED:
|
||||
sq_pushstring(v,_SC("suspended"),-1);
|
||||
sq_pushstring(v,"suspended",-1);
|
||||
break;
|
||||
default:
|
||||
return sq_throwerror(v,_SC("internal VM error"));
|
||||
return sq_throwerror(v,"internal VM error");
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
SQRegFunction SQSharedState::_thread_default_delegate_funcz[] = {
|
||||
{_SC("call"), thread_call, -1, _SC("v")},
|
||||
{_SC("wakeup"), thread_wakeup, -1, _SC("v")},
|
||||
{_SC("getstatus"), thread_getstatus, 1, _SC("v")},
|
||||
{_SC("weakref"),obj_delegate_weakref,1, NULL },
|
||||
{_SC("tostring"),default_delegate_tostring,1, _SC(".")},
|
||||
{"call", thread_call, -1, "v"},
|
||||
{"wakeup", thread_wakeup, -1, "v"},
|
||||
{"getstatus", thread_getstatus, 1, "v"},
|
||||
{"weakref",obj_delegate_weakref,1, NULL },
|
||||
{"tostring",default_delegate_tostring,1, "."},
|
||||
{0,0,0,0},
|
||||
};
|
||||
|
||||
@@ -909,12 +921,12 @@ static SQInteger class_instance(HSQUIRRELVM v)
|
||||
}
|
||||
|
||||
SQRegFunction SQSharedState::_class_default_delegate_funcz[] = {
|
||||
{_SC("getattributes"), class_getattributes, 2, _SC("y.")},
|
||||
{_SC("setattributes"), class_setattributes, 3, _SC("y..")},
|
||||
{_SC("rawin"),container_rawexists,2, _SC("y")},
|
||||
{_SC("weakref"),obj_delegate_weakref,1, NULL },
|
||||
{_SC("tostring"),default_delegate_tostring,1, _SC(".")},
|
||||
{_SC("instance"),class_instance,1, _SC("y")},
|
||||
{"getattributes", class_getattributes, 2, "y."},
|
||||
{"setattributes", class_setattributes, 3, "y.."},
|
||||
{"rawin",container_rawexists,2, "y"},
|
||||
{"weakref",obj_delegate_weakref,1, NULL },
|
||||
{"tostring",default_delegate_tostring,1, "."},
|
||||
{"instance",class_instance,1, "y"},
|
||||
{0,0,0,0}
|
||||
};
|
||||
|
||||
@@ -926,10 +938,10 @@ static SQInteger instance_getclass(HSQUIRRELVM v)
|
||||
}
|
||||
|
||||
SQRegFunction SQSharedState::_instance_default_delegate_funcz[] = {
|
||||
{_SC("getclass"), instance_getclass, 1, _SC("x")},
|
||||
{_SC("rawin"),container_rawexists,2, _SC("x")},
|
||||
{_SC("weakref"),obj_delegate_weakref,1, NULL },
|
||||
{_SC("tostring"),default_delegate_tostring,1, _SC(".")},
|
||||
{"getclass", instance_getclass, 1, "x"},
|
||||
{"rawin",container_rawexists,2, "x"},
|
||||
{"weakref",obj_delegate_weakref,1, NULL },
|
||||
{"tostring",default_delegate_tostring,1, "."},
|
||||
{0,0,0,0}
|
||||
};
|
||||
|
||||
@@ -941,9 +953,9 @@ static SQInteger weakref_ref(HSQUIRRELVM v)
|
||||
}
|
||||
|
||||
SQRegFunction SQSharedState::_weakref_default_delegate_funcz[] = {
|
||||
{_SC("ref"),weakref_ref,1, _SC("r")},
|
||||
{_SC("weakref"),obj_delegate_weakref,1, NULL },
|
||||
{_SC("tostring"),default_delegate_tostring,1, _SC(".")},
|
||||
{"ref",weakref_ref,1, "r"},
|
||||
{"weakref",obj_delegate_weakref,1, NULL },
|
||||
{"tostring",default_delegate_tostring,1, "."},
|
||||
{0,0,0,0}
|
||||
};
|
||||
|
||||
|
9
src/3rdparty/squirrel/squirrel/sqclass.cpp
vendored
9
src/3rdparty/squirrel/squirrel/sqclass.cpp
vendored
@@ -1,12 +1,17 @@
|
||||
/*
|
||||
see copyright notice in squirrel.h
|
||||
*/
|
||||
* see copyright notice in squirrel.h
|
||||
*/
|
||||
|
||||
#include "../../../stdafx.h"
|
||||
|
||||
#include "sqpcheader.h"
|
||||
#include "sqvm.h"
|
||||
#include "sqtable.h"
|
||||
#include "sqclass.h"
|
||||
#include "sqclosure.h"
|
||||
|
||||
#include "../../../safeguards.h"
|
||||
|
||||
SQClass::SQClass(SQSharedState *ss,SQClass *base)
|
||||
{
|
||||
_base = base;
|
||||
|
2
src/3rdparty/squirrel/squirrel/sqclosure.h
vendored
2
src/3rdparty/squirrel/squirrel/sqclosure.h
vendored
@@ -80,7 +80,7 @@ public:
|
||||
struct SQNativeClosure : public CHAINABLE_OBJ
|
||||
{
|
||||
private:
|
||||
SQNativeClosure(SQSharedState *ss,SQFUNCTION func){_function=func;INIT_CHAIN();ADD_TO_CHAIN(&_ss(this)->_gc_chain,this); }
|
||||
SQNativeClosure(SQSharedState *ss,SQFUNCTION func) : _nparamscheck(0) {_function=func;INIT_CHAIN();ADD_TO_CHAIN(&_ss(this)->_gc_chain,this); }
|
||||
public:
|
||||
static SQNativeClosure *Create(SQSharedState *ss,SQFUNCTION func)
|
||||
{
|
||||
|
278
src/3rdparty/squirrel/squirrel/sqcompiler.cpp
vendored
278
src/3rdparty/squirrel/squirrel/sqcompiler.cpp
vendored
@@ -1,6 +1,9 @@
|
||||
/*
|
||||
see copyright notice in squirrel.h
|
||||
*/
|
||||
* see copyright notice in squirrel.h
|
||||
*/
|
||||
|
||||
#include "../../../stdafx.h"
|
||||
|
||||
#include <squirrel.h>
|
||||
#include "sqpcheader.h"
|
||||
#include <stdarg.h>
|
||||
@@ -13,6 +16,10 @@
|
||||
#include "sqvm.h"
|
||||
#include "sqtable.h"
|
||||
|
||||
#include "../../../string_func.h"
|
||||
|
||||
#include "../../../safeguards.h"
|
||||
|
||||
#define DEREF_NO_DEREF -1
|
||||
#define DEREF_FIELD -2
|
||||
|
||||
@@ -50,23 +57,22 @@ typedef sqvector<ExpState> ExpStateVec;
|
||||
class SQCompiler
|
||||
{
|
||||
public:
|
||||
SQCompiler(SQVM *v, SQLEXREADFUNC rg, SQUserPointer up, const SQChar* sourcename, bool raiseerror, bool lineinfo)
|
||||
SQCompiler(SQVM *v, SQLEXREADFUNC rg, SQUserPointer up, const SQChar* sourcename, bool raiseerror, bool lineinfo) : _token(0), _fs(NULL), _lex(_ss(v), rg, up, ThrowError, this), _debugline(0), _debugop(0)
|
||||
{
|
||||
_vm=v;
|
||||
_lex.Init(_ss(v), rg, up,ThrowError,this);
|
||||
_sourcename = SQString::Create(_ss(v), sourcename);
|
||||
_lineinfo = lineinfo;_raiseerror = raiseerror;
|
||||
}
|
||||
static void ThrowError(void *ud, const SQChar *s) {
|
||||
NORETURN static void ThrowError(void *ud, const SQChar *s) {
|
||||
SQCompiler *c = (SQCompiler *)ud;
|
||||
c->Error(s);
|
||||
}
|
||||
void Error(const SQChar *s, ...)
|
||||
NORETURN void Error(const SQChar *s, ...)
|
||||
{
|
||||
static SQChar temp[256];
|
||||
va_list vl;
|
||||
va_start(vl, s);
|
||||
scvsprintf(temp, s, vl);
|
||||
vseprintf(temp, lastof(temp), s, vl);
|
||||
va_end(vl);
|
||||
throw temp;
|
||||
}
|
||||
@@ -75,7 +81,7 @@ public:
|
||||
bool IsDerefToken(SQInteger tok)
|
||||
{
|
||||
switch(tok){
|
||||
case _SC('='): case _SC('('): case TK_NEWSLOT:
|
||||
case '=': case '(': case TK_NEWSLOT:
|
||||
case TK_MODEQ: case TK_MULEQ: case TK_DIVEQ: case TK_MINUSEQ: case TK_PLUSEQ: case TK_PLUSPLUS: case TK_MINUSMINUS: return true;
|
||||
}
|
||||
return false;
|
||||
@@ -91,7 +97,7 @@ public:
|
||||
|
||||
if(_token != tok) {
|
||||
if(_token == TK_CONSTRUCTOR && tok == TK_IDENTIFIER) {
|
||||
//ret = SQString::Create(_ss(_vm),_SC("constructor"));
|
||||
//ret = SQString::Create(_ss(_vm),"constructor");
|
||||
//do nothing
|
||||
}
|
||||
else {
|
||||
@@ -100,23 +106,23 @@ public:
|
||||
switch(tok)
|
||||
{
|
||||
case TK_IDENTIFIER:
|
||||
etypename = _SC("IDENTIFIER");
|
||||
etypename = "IDENTIFIER";
|
||||
break;
|
||||
case TK_STRING_LITERAL:
|
||||
etypename = _SC("STRING_LITERAL");
|
||||
etypename = "STRING_LITERAL";
|
||||
break;
|
||||
case TK_INTEGER:
|
||||
etypename = _SC("INTEGER");
|
||||
etypename = "INTEGER";
|
||||
break;
|
||||
case TK_FLOAT:
|
||||
etypename = _SC("FLOAT");
|
||||
etypename = "FLOAT";
|
||||
break;
|
||||
default:
|
||||
etypename = _lex.Tok2Str(tok);
|
||||
}
|
||||
Error(_SC("expected '%s'"), etypename);
|
||||
Error("expected '%s'", etypename);
|
||||
}
|
||||
Error(_SC("expected '%c'"), tok);
|
||||
Error("expected '%c'", tok);
|
||||
}
|
||||
}
|
||||
SQObjectPtr ret;
|
||||
@@ -138,12 +144,12 @@ public:
|
||||
Lex();
|
||||
return ret;
|
||||
}
|
||||
bool IsEndOfStatement() { return ((_lex._prevtoken == _SC('\n')) || (_token == SQUIRREL_EOB) || (_token == _SC('}')) || (_token == _SC(';'))); }
|
||||
bool IsEndOfStatement() { return ((_lex._prevtoken == '\n') || (_token == SQUIRREL_EOB) || (_token == '}') || (_token == ';')); }
|
||||
void OptionalSemicolon()
|
||||
{
|
||||
if(_token == _SC(';')) { Lex(); return; }
|
||||
if(_token == ';') { Lex(); return; }
|
||||
if(!IsEndOfStatement()) {
|
||||
Error(_SC("end of statement expected (; or lf)"));
|
||||
Error("end of statement expected (; or lf)");
|
||||
}
|
||||
}
|
||||
void MoveIfCurrentTargetIsLocal() {
|
||||
@@ -159,16 +165,16 @@ public:
|
||||
_debugop = 0;
|
||||
|
||||
SQFuncState funcstate(_ss(_vm), NULL,ThrowError,this);
|
||||
funcstate._name = SQString::Create(_ss(_vm), _SC("main"));
|
||||
funcstate._name = SQString::Create(_ss(_vm), "main");
|
||||
_fs = &funcstate;
|
||||
_fs->AddParameter(_fs->CreateString(_SC("this")));
|
||||
_fs->AddParameter(_fs->CreateString("this"));
|
||||
_fs->_sourcename = _sourcename;
|
||||
SQInteger stacksize = _fs->GetStackSize();
|
||||
try {
|
||||
Lex();
|
||||
while(_token > 0){
|
||||
Statement();
|
||||
if(_lex._prevtoken != _SC('}')) OptionalSemicolon();
|
||||
if(_lex._prevtoken != '}') OptionalSemicolon();
|
||||
}
|
||||
CleanStack(stacksize);
|
||||
_fs->AddLineInfos(_lex._currentline, _lineinfo, true);
|
||||
@@ -182,7 +188,7 @@ public:
|
||||
}
|
||||
catch (SQChar *compilererror) {
|
||||
if(_raiseerror && _ss(_vm)->_compilererrorhandler) {
|
||||
_ss(_vm)->_compilererrorhandler(_vm, compilererror, type(_sourcename) == OT_STRING?_stringval(_sourcename):_SC("unknown"),
|
||||
_ss(_vm)->_compilererrorhandler(_vm, compilererror, type(_sourcename) == OT_STRING?_stringval(_sourcename):"unknown",
|
||||
_lex._currentline, _lex._currentcolumn);
|
||||
}
|
||||
_vm->_lasterror = SQString::Create(_ss(_vm), compilererror, -1);
|
||||
@@ -191,16 +197,16 @@ public:
|
||||
}
|
||||
void Statements()
|
||||
{
|
||||
while(_token != _SC('}') && _token != TK_DEFAULT && _token != TK_CASE) {
|
||||
while(_token != '}' && _token != TK_DEFAULT && _token != TK_CASE) {
|
||||
Statement();
|
||||
if(_lex._prevtoken != _SC('}') && _lex._prevtoken != _SC(';')) OptionalSemicolon();
|
||||
if(_lex._prevtoken != '}' && _lex._prevtoken != ';') OptionalSemicolon();
|
||||
}
|
||||
}
|
||||
void Statement()
|
||||
{
|
||||
_fs->AddLineInfos(_lex._currentline, _lineinfo);
|
||||
switch(_token){
|
||||
case _SC(';'): Lex(); break;
|
||||
case ';': Lex(); break;
|
||||
case TK_IF: IfStatement(); break;
|
||||
case TK_WHILE: WhileStatement(); break;
|
||||
case TK_DO: DoWhileStatement(); break;
|
||||
@@ -236,7 +242,7 @@ public:
|
||||
}
|
||||
break;}
|
||||
case TK_BREAK:
|
||||
if(_fs->_breaktargets.size() <= 0)Error(_SC("'break' has to be in a loop block"));
|
||||
if(_fs->_breaktargets.size() <= 0)Error("'break' has to be in a loop block");
|
||||
if(_fs->_breaktargets.top() > 0){
|
||||
_fs->AddInstruction(_OP_POPTRAP, _fs->_breaktargets.top(), 0);
|
||||
}
|
||||
@@ -246,7 +252,7 @@ public:
|
||||
Lex();
|
||||
break;
|
||||
case TK_CONTINUE:
|
||||
if(_fs->_continuetargets.size() <= 0)Error(_SC("'continue' has to be in a loop block"));
|
||||
if(_fs->_continuetargets.size() <= 0)Error("'continue' has to be in a loop block");
|
||||
if(_fs->_continuetargets.top() > 0) {
|
||||
_fs->AddInstruction(_OP_POPTRAP, _fs->_continuetargets.top(), 0);
|
||||
}
|
||||
@@ -264,11 +270,11 @@ public:
|
||||
case TK_ENUM:
|
||||
EnumStatement();
|
||||
break;
|
||||
case _SC('{'):{
|
||||
case '{':{
|
||||
SQInteger stacksize = _fs->GetStackSize();
|
||||
Lex();
|
||||
Statements();
|
||||
Expect(_SC('}'));
|
||||
Expect('}');
|
||||
_fs->AddInstruction(_OP_SCOPE_END, stacksize, _fs->GetStackSize());
|
||||
_fs->SetStackSize(stacksize);
|
||||
}
|
||||
@@ -348,7 +354,7 @@ public:
|
||||
_exst._funcarg = funcarg;
|
||||
LogicalOrExp();
|
||||
switch(_token) {
|
||||
case _SC('='):
|
||||
case '=':
|
||||
case TK_NEWSLOT:
|
||||
case TK_MINUSEQ:
|
||||
case TK_PLUSEQ:
|
||||
@@ -359,19 +365,19 @@ public:
|
||||
SQInteger op = _token;
|
||||
SQInteger ds = _exst._deref;
|
||||
bool freevar = _exst._freevar;
|
||||
if(ds == DEREF_NO_DEREF) Error(_SC("can't assign expression"));
|
||||
if(ds == DEREF_NO_DEREF) Error("can't assign expression");
|
||||
Lex(); Expression();
|
||||
|
||||
switch(op){
|
||||
case TK_NEWSLOT:
|
||||
if(freevar) Error(_SC("free variables cannot be modified"));
|
||||
if(freevar) Error("free variables cannot be modified");
|
||||
if(ds == DEREF_FIELD)
|
||||
EmitDerefOp(_OP_NEWSLOT);
|
||||
else //if _derefstate != DEREF_NO_DEREF && DEREF_FIELD so is the index of a local
|
||||
Error(_SC("can't 'create' a local slot"));
|
||||
Error("can't 'create' a local slot");
|
||||
break;
|
||||
case _SC('='): //ASSIGN
|
||||
if(freevar) Error(_SC("free variables cannot be modified"));
|
||||
case '=': //ASSIGN
|
||||
if(freevar) Error("free variables cannot be modified");
|
||||
if(ds == DEREF_FIELD)
|
||||
EmitDerefOp(_OP_SET);
|
||||
else {//if _derefstate != DEREF_NO_DEREF && DEREF_FIELD so is the index of a local
|
||||
@@ -390,7 +396,7 @@ public:
|
||||
}
|
||||
}
|
||||
break;
|
||||
case _SC('?'): {
|
||||
case '?': {
|
||||
Lex();
|
||||
_fs->AddInstruction(_OP_JZ, _fs->PopTarget());
|
||||
SQInteger jzpos = _fs->GetCurrentPos();
|
||||
@@ -400,7 +406,7 @@ public:
|
||||
if(trg != first_exp) _fs->AddInstruction(_OP_MOVE, trg, first_exp);
|
||||
SQInteger endfirstexp = _fs->GetCurrentPos();
|
||||
_fs->AddInstruction(_OP_JMP, 0, 0);
|
||||
Expect(_SC(':'));
|
||||
Expect(':');
|
||||
SQInteger jmppos = _fs->GetCurrentPos();
|
||||
Expression();
|
||||
SQInteger second_exp = _fs->PopTarget();
|
||||
@@ -422,7 +428,7 @@ public:
|
||||
void LogicalOrExp()
|
||||
{
|
||||
LogicalAndExp();
|
||||
for(;;) if(_token == TK_OR) {
|
||||
if(_token == TK_OR) {
|
||||
SQInteger first_exp = _fs->PopTarget();
|
||||
SQInteger trg = _fs->PushTarget();
|
||||
_fs->AddInstruction(_OP_OR, trg, 0, first_exp, 0);
|
||||
@@ -434,8 +440,7 @@ public:
|
||||
if(trg != second_exp) _fs->AddInstruction(_OP_MOVE, trg, second_exp);
|
||||
_fs->SnoozeOpt();
|
||||
_fs->SetIntructionParam(jpos, 1, (_fs->GetCurrentPos() - jpos));
|
||||
break;
|
||||
}else return;
|
||||
}
|
||||
}
|
||||
void LogicalAndExp()
|
||||
{
|
||||
@@ -464,21 +469,21 @@ public:
|
||||
void BitwiseOrExp()
|
||||
{
|
||||
BitwiseXorExp();
|
||||
for(;;) if(_token == _SC('|'))
|
||||
for(;;) if(_token == '|')
|
||||
{BIN_EXP(_OP_BITW, &SQCompiler::BitwiseXorExp,BW_OR);
|
||||
}else return;
|
||||
}
|
||||
void BitwiseXorExp()
|
||||
{
|
||||
BitwiseAndExp();
|
||||
for(;;) if(_token == _SC('^'))
|
||||
for(;;) if(_token == '^')
|
||||
{BIN_EXP(_OP_BITW, &SQCompiler::BitwiseAndExp,BW_XOR);
|
||||
}else return;
|
||||
}
|
||||
void BitwiseAndExp()
|
||||
{
|
||||
CompExp();
|
||||
for(;;) if(_token == _SC('&'))
|
||||
for(;;) if(_token == '&')
|
||||
{BIN_EXP(_OP_BITW, &SQCompiler::CompExp,BW_AND);
|
||||
}else return;
|
||||
}
|
||||
@@ -487,8 +492,8 @@ public:
|
||||
ShiftExp();
|
||||
for(;;) switch(_token) {
|
||||
case TK_EQ: BIN_EXP(_OP_EQ, &SQCompiler::ShiftExp); break;
|
||||
case _SC('>'): BIN_EXP(_OP_CMP, &SQCompiler::ShiftExp,CMP_G); break;
|
||||
case _SC('<'): BIN_EXP(_OP_CMP, &SQCompiler::ShiftExp,CMP_L); break;
|
||||
case '>': BIN_EXP(_OP_CMP, &SQCompiler::ShiftExp,CMP_G); break;
|
||||
case '<': BIN_EXP(_OP_CMP, &SQCompiler::ShiftExp,CMP_L); break;
|
||||
case TK_GE: BIN_EXP(_OP_CMP, &SQCompiler::ShiftExp,CMP_GE); break;
|
||||
case TK_LE: BIN_EXP(_OP_CMP, &SQCompiler::ShiftExp,CMP_LE); break;
|
||||
case TK_NE: BIN_EXP(_OP_NE, &SQCompiler::ShiftExp); break;
|
||||
@@ -509,7 +514,7 @@ public:
|
||||
{
|
||||
MultExp();
|
||||
for(;;) switch(_token) {
|
||||
case _SC('+'): case _SC('-'):
|
||||
case '+': case '-':
|
||||
BIN_EXP(_OP_ARITH, &SQCompiler::MultExp,_token); break;
|
||||
default: return;
|
||||
}
|
||||
@@ -519,7 +524,7 @@ public:
|
||||
{
|
||||
PrefixedExpr();
|
||||
for(;;) switch(_token) {
|
||||
case _SC('*'): case _SC('/'): case _SC('%'):
|
||||
case '*': case '/': case '%':
|
||||
BIN_EXP(_OP_ARITH, &SQCompiler::PrefixedExpr,_token); break;
|
||||
default: return;
|
||||
}
|
||||
@@ -531,13 +536,13 @@ public:
|
||||
|
||||
for(;;) {
|
||||
switch(_token) {
|
||||
case _SC('.'): {
|
||||
case '.': {
|
||||
pos = -1;
|
||||
Lex();
|
||||
if(_token == TK_PARENT) {
|
||||
Lex();
|
||||
if(!NeedGet())
|
||||
Error(_SC("parent cannot be set"));
|
||||
Error("parent cannot be set");
|
||||
SQInteger src = _fs->PopTarget();
|
||||
_fs->AddInstruction(_OP_GETPARENT, _fs->PushTarget(), src);
|
||||
}
|
||||
@@ -549,9 +554,9 @@ public:
|
||||
_exst._freevar = false;
|
||||
}
|
||||
break;
|
||||
case _SC('['):
|
||||
if(_lex._prevtoken == _SC('\n')) Error(_SC("cannot brake deref/or comma needed after [exp]=exp slot declaration"));
|
||||
Lex(); Expression(); Expect(_SC(']'));
|
||||
case '[':
|
||||
if(_lex._prevtoken == '\n') Error("cannot brake deref/or comma needed after [exp]=exp slot declaration");
|
||||
Lex(); Expression(); Expect(']');
|
||||
pos = -1;
|
||||
if(NeedGet()) Emit2ArgsOP(_OP_GET);
|
||||
_exst._deref = DEREF_FIELD;
|
||||
@@ -571,7 +576,7 @@ public:
|
||||
}
|
||||
return;
|
||||
break;
|
||||
case _SC('('):
|
||||
case '(':
|
||||
{
|
||||
if(_exst._deref != DEREF_NO_DEREF) {
|
||||
if(pos<0) {
|
||||
@@ -609,9 +614,9 @@ public:
|
||||
break;
|
||||
case TK_VARGC: Lex(); _fs->AddInstruction(_OP_VARGC, _fs->PushTarget()); break;
|
||||
case TK_VARGV: { Lex();
|
||||
Expect(_SC('['));
|
||||
Expect('[');
|
||||
Expression();
|
||||
Expect(_SC(']'));
|
||||
Expect(']');
|
||||
SQInteger src = _fs->PopTarget();
|
||||
_fs->AddInstruction(_OP_GETVARGV, _fs->PushTarget(), src);
|
||||
}
|
||||
@@ -624,8 +629,8 @@ public:
|
||||
SQObject constant;
|
||||
switch(_token) {
|
||||
case TK_IDENTIFIER: id = _fs->CreateString(_lex._svalue); break;
|
||||
case TK_THIS: id = _fs->CreateString(_SC("this")); break;
|
||||
case TK_CONSTRUCTOR: id = _fs->CreateString(_SC("constructor")); break;
|
||||
case TK_THIS: id = _fs->CreateString("this"); break;
|
||||
case TK_CONSTRUCTOR: id = _fs->CreateString("constructor"); break;
|
||||
}
|
||||
SQInteger pos = -1;
|
||||
Lex();
|
||||
@@ -643,7 +648,7 @@ public:
|
||||
Expect('.'); constid = Expect(TK_IDENTIFIER);
|
||||
if(!_table(constant)->Get(constid,constval)) {
|
||||
constval.Null();
|
||||
Error(_SC("invalid constant [%s.%s]"), _stringval(id),_stringval(constid));
|
||||
Error("invalid constant [%s.%s]", _stringval(id),_stringval(constid));
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -683,7 +688,7 @@ public:
|
||||
case TK_DOUBLE_COLON: // "::"
|
||||
_fs->AddInstruction(_OP_LOADROOTTABLE, _fs->PushTarget());
|
||||
_exst._deref = DEREF_FIELD;
|
||||
_token = _SC('.'); //hack
|
||||
_token = '.'; //hack
|
||||
return -1;
|
||||
break;
|
||||
case TK_NULL:
|
||||
@@ -713,13 +718,13 @@ public:
|
||||
_fs->AddInstruction(_OP_LOADBOOL, _fs->PushTarget(),_token == TK_TRUE?1:0);
|
||||
Lex();
|
||||
break;
|
||||
case _SC('['): {
|
||||
case '[': {
|
||||
_fs->AddInstruction(_OP_NEWARRAY, _fs->PushTarget());
|
||||
SQInteger apos = _fs->GetCurrentPos(),key = 0;
|
||||
Lex();
|
||||
while(_token != _SC(']')) {
|
||||
while(_token != ']') {
|
||||
Expression();
|
||||
if(_token == _SC(',')) Lex();
|
||||
if(_token == ',') Lex();
|
||||
SQInteger val = _fs->PopTarget();
|
||||
SQInteger array = _fs->TopTarget();
|
||||
_fs->AddInstruction(_OP_APPENDARRAY, array, val);
|
||||
@@ -729,16 +734,16 @@ public:
|
||||
Lex();
|
||||
}
|
||||
break;
|
||||
case _SC('{'):{
|
||||
case '{':{
|
||||
_fs->AddInstruction(_OP_NEWTABLE, _fs->PushTarget());
|
||||
Lex();ParseTableOrClass(_SC(','));
|
||||
Lex();ParseTableOrClass(',');
|
||||
}
|
||||
break;
|
||||
case TK_FUNCTION: FunctionExp(_token);break;
|
||||
case TK_CLASS: Lex(); ClassExp();break;
|
||||
case _SC('-'): UnaryOP(_OP_NEG); break;
|
||||
case _SC('!'): UnaryOP(_OP_NOT); break;
|
||||
case _SC('~'): UnaryOP(_OP_BWNOT); break;
|
||||
case '-': UnaryOP(_OP_NEG); break;
|
||||
case '!': UnaryOP(_OP_NOT); break;
|
||||
case '~': UnaryOP(_OP_BWNOT); break;
|
||||
case TK_TYPEOF : UnaryOP(_OP_TYPEOF); break;
|
||||
case TK_RESUME : UnaryOP(_OP_RESUME); break;
|
||||
case TK_CLONE : UnaryOP(_OP_CLONE); break;
|
||||
@@ -746,9 +751,9 @@ public:
|
||||
case TK_PLUSPLUS :PrefixIncDec(_token); break;
|
||||
case TK_DELETE : DeleteExpr(); break;
|
||||
case TK_DELEGATE : DelegateExpr(); break;
|
||||
case _SC('('): Lex(); CommaExpr(); Expect(_SC(')'));
|
||||
case '(': Lex(); CommaExpr(); Expect(')');
|
||||
break;
|
||||
default: Error(_SC("expression expected"));
|
||||
default: Error("expression expected");
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
@@ -761,23 +766,23 @@ public:
|
||||
bool NeedGet()
|
||||
{
|
||||
switch(_token) {
|
||||
case _SC('='): case _SC('('): case TK_NEWSLOT: case TK_PLUSPLUS: case TK_MINUSMINUS:
|
||||
case '=': case '(': case TK_NEWSLOT: case TK_PLUSPLUS: case TK_MINUSMINUS:
|
||||
case TK_PLUSEQ: case TK_MINUSEQ: case TK_MULEQ: case TK_DIVEQ: case TK_MODEQ:
|
||||
return false;
|
||||
}
|
||||
return (!_exst._class_or_delete) || (_exst._class_or_delete && (_token == _SC('.') || _token == _SC('[')));
|
||||
return (!_exst._class_or_delete) || (_exst._class_or_delete && (_token == '.' || _token == '['));
|
||||
}
|
||||
|
||||
void FunctionCallArgs()
|
||||
{
|
||||
SQInteger nargs = 1;//this
|
||||
while(_token != _SC(')')) {
|
||||
while(_token != ')') {
|
||||
Expression(true);
|
||||
MoveIfCurrentTargetIsLocal();
|
||||
nargs++;
|
||||
if(_token == _SC(',')){
|
||||
if(_token == ','){
|
||||
Lex();
|
||||
if(_token == ')') Error(_SC("expression expected, found ')'"));
|
||||
if(_token == ')') Error("expression expected, found ')'");
|
||||
}
|
||||
}
|
||||
Lex();
|
||||
@@ -810,20 +815,20 @@ public:
|
||||
case TK_CONSTRUCTOR:{
|
||||
SQInteger tk = _token;
|
||||
Lex();
|
||||
SQObject id = tk == TK_FUNCTION ? Expect(TK_IDENTIFIER) : _fs->CreateString(_SC("constructor"));
|
||||
Expect(_SC('('));
|
||||
SQObject id = tk == TK_FUNCTION ? Expect(TK_IDENTIFIER) : _fs->CreateString("constructor");
|
||||
Expect('(');
|
||||
_fs->AddInstruction(_OP_LOAD, _fs->PushTarget(), _fs->GetConstant(id));
|
||||
CreateFunction(id);
|
||||
_fs->AddInstruction(_OP_CLOSURE, _fs->PushTarget(), _fs->_functions.size() - 1, 0);
|
||||
}
|
||||
break;
|
||||
case _SC('['):
|
||||
Lex(); CommaExpr(); Expect(_SC(']'));
|
||||
Expect(_SC('=')); Expression();
|
||||
case '[':
|
||||
Lex(); CommaExpr(); Expect(']');
|
||||
Expect('='); Expression();
|
||||
break;
|
||||
default :
|
||||
_fs->AddInstruction(_OP_LOAD, _fs->PushTarget(), _fs->GetConstant(Expect(TK_IDENTIFIER)));
|
||||
Expect(_SC('=')); Expression();
|
||||
Expect('='); Expression();
|
||||
}
|
||||
|
||||
if(_token == separator) Lex();//optional comma/semicolon
|
||||
@@ -837,7 +842,7 @@ public:
|
||||
_fs->AddInstruction(_OP_NEWSLOTA, flags, table, key, val);
|
||||
//_fs->PopTarget();
|
||||
}
|
||||
if(separator == _SC(',')) //hack recognizes a table from the separator
|
||||
if(separator == ',') //hack recognizes a table from the separator
|
||||
_fs->SetIntructionParam(tpos, 1, nkeys);
|
||||
Lex();
|
||||
}
|
||||
@@ -846,7 +851,7 @@ public:
|
||||
SQObject varname;
|
||||
do {
|
||||
Lex(); varname = Expect(TK_IDENTIFIER);
|
||||
if(_token == _SC('=')) {
|
||||
if(_token == '=') {
|
||||
Lex(); Expression();
|
||||
SQInteger src = _fs->PopTarget();
|
||||
SQInteger dest = _fs->PushTarget();
|
||||
@@ -858,20 +863,20 @@ public:
|
||||
_fs->PopTarget();
|
||||
_fs->PushLocalVariable(varname);
|
||||
|
||||
} while(_token == _SC(','));
|
||||
} while(_token == ',');
|
||||
}
|
||||
void IfStatement()
|
||||
{
|
||||
SQInteger jmppos;
|
||||
bool haselse = false;
|
||||
Lex(); Expect(_SC('(')); CommaExpr(); Expect(_SC(')'));
|
||||
Lex(); Expect('('); CommaExpr(); Expect(')');
|
||||
_fs->AddInstruction(_OP_JZ, _fs->PopTarget());
|
||||
SQInteger jnepos = _fs->GetCurrentPos();
|
||||
SQInteger stacksize = _fs->GetStackSize();
|
||||
|
||||
Statement();
|
||||
//
|
||||
if(_token != _SC('}') && _token != TK_ELSE) OptionalSemicolon();
|
||||
if(_token != '}' && _token != TK_ELSE) OptionalSemicolon();
|
||||
|
||||
CleanStack(stacksize);
|
||||
SQInteger endifblock = _fs->GetCurrentPos();
|
||||
@@ -892,7 +897,7 @@ public:
|
||||
SQInteger jzpos, jmppos;
|
||||
SQInteger stacksize = _fs->GetStackSize();
|
||||
jmppos = _fs->GetCurrentPos();
|
||||
Lex(); Expect(_SC('(')); CommaExpr(); Expect(_SC(')'));
|
||||
Lex(); Expect('('); CommaExpr(); Expect(')');
|
||||
|
||||
BEGIN_BREAKBLE_BLOCK();
|
||||
_fs->AddInstruction(_OP_JZ, _fs->PopTarget());
|
||||
@@ -917,9 +922,10 @@ public:
|
||||
_last_stacksize = _fs->GetStackSize();
|
||||
Statement();
|
||||
CleanStack(stacksize);
|
||||
_fs->AddLineInfos(_lex._currentline, _lineinfo, true);
|
||||
Expect(TK_WHILE);
|
||||
SQInteger continuetrg = _fs->GetCurrentPos();
|
||||
Expect(_SC('(')); CommaExpr(); Expect(_SC(')'));
|
||||
Expect('('); CommaExpr(); Expect(')');
|
||||
_fs->AddInstruction(_OP_JNZ, _fs->PopTarget(), jzpos - _fs->GetCurrentPos() - 1);
|
||||
END_BREAKBLE_BLOCK(continuetrg);
|
||||
}
|
||||
@@ -927,25 +933,25 @@ public:
|
||||
{
|
||||
Lex();
|
||||
SQInteger stacksize = _fs->GetStackSize();
|
||||
Expect(_SC('('));
|
||||
Expect('(');
|
||||
if(_token == TK_LOCAL) LocalDeclStatement();
|
||||
else if(_token != _SC(';')){
|
||||
else if(_token != ';'){
|
||||
CommaExpr();
|
||||
_fs->PopTarget();
|
||||
}
|
||||
Expect(_SC(';'));
|
||||
Expect(';');
|
||||
_fs->SnoozeOpt();
|
||||
SQInteger jmppos = _fs->GetCurrentPos();
|
||||
SQInteger jzpos = -1;
|
||||
if(_token != _SC(';')) { CommaExpr(); _fs->AddInstruction(_OP_JZ, _fs->PopTarget()); jzpos = _fs->GetCurrentPos(); }
|
||||
Expect(_SC(';'));
|
||||
if(_token != ';') { CommaExpr(); _fs->AddInstruction(_OP_JZ, _fs->PopTarget()); jzpos = _fs->GetCurrentPos(); }
|
||||
Expect(';');
|
||||
_fs->SnoozeOpt();
|
||||
SQInteger expstart = _fs->GetCurrentPos() + 1;
|
||||
if(_token != _SC(')')) {
|
||||
if(_token != ')') {
|
||||
CommaExpr();
|
||||
_fs->PopTarget();
|
||||
}
|
||||
Expect(_SC(')'));
|
||||
Expect(')');
|
||||
_fs->SnoozeOpt();
|
||||
SQInteger expend = _fs->GetCurrentPos();
|
||||
SQInteger expsize = (expend - expstart) + 1;
|
||||
@@ -972,20 +978,20 @@ public:
|
||||
void ForEachStatement()
|
||||
{
|
||||
SQObject idxname, valname;
|
||||
Lex(); Expect(_SC('(')); valname = Expect(TK_IDENTIFIER);
|
||||
if(_token == _SC(',')) {
|
||||
Lex(); Expect('('); valname = Expect(TK_IDENTIFIER);
|
||||
if(_token == ',') {
|
||||
idxname = valname;
|
||||
Lex(); valname = Expect(TK_IDENTIFIER);
|
||||
}
|
||||
else{
|
||||
idxname = _fs->CreateString(_SC("@INDEX@"));
|
||||
idxname = _fs->CreateString("@INDEX@");
|
||||
}
|
||||
Expect(TK_IN);
|
||||
|
||||
//save the stack size
|
||||
SQInteger stacksize = _fs->GetStackSize();
|
||||
//put the table in the stack(evaluate the table expression)
|
||||
Expression(); Expect(_SC(')'));
|
||||
Expression(); Expect(')');
|
||||
SQInteger container = _fs->TopTarget();
|
||||
//push the index local var
|
||||
SQInteger indexpos = _fs->PushLocalVariable(idxname);
|
||||
@@ -994,7 +1000,7 @@ public:
|
||||
SQInteger valuepos = _fs->PushLocalVariable(valname);
|
||||
_fs->AddInstruction(_OP_LOADNULLS, valuepos,1);
|
||||
//push reference index
|
||||
SQInteger itrpos = _fs->PushLocalVariable(_fs->CreateString(_SC("@ITERATOR@"))); //use invalid id to make it inaccessible
|
||||
SQInteger itrpos = _fs->PushLocalVariable(_fs->CreateString("@ITERATOR@")); //use invalid id to make it inaccessible
|
||||
_fs->AddInstruction(_OP_LOADNULLS, itrpos,1);
|
||||
SQInteger jmppos = _fs->GetCurrentPos();
|
||||
_fs->AddInstruction(_OP_FOREACH, container, 0, indexpos);
|
||||
@@ -1013,8 +1019,8 @@ public:
|
||||
}
|
||||
void SwitchStatement()
|
||||
{
|
||||
Lex(); Expect(_SC('(')); CommaExpr(); Expect(_SC(')'));
|
||||
Expect(_SC('{'));
|
||||
Lex(); Expect('('); CommaExpr(); Expect(')');
|
||||
Expect('{');
|
||||
SQInteger expr = _fs->TopTarget();
|
||||
bool bfirst = true;
|
||||
SQInteger tonextcondjmp = -1;
|
||||
@@ -1029,7 +1035,7 @@ public:
|
||||
_fs->SetIntructionParam(tonextcondjmp, 1, _fs->GetCurrentPos() - tonextcondjmp);
|
||||
}
|
||||
//condition
|
||||
Lex(); Expression(); Expect(_SC(':'));
|
||||
Lex(); Expression(); Expect(':');
|
||||
SQInteger trg = _fs->PopTarget();
|
||||
_fs->AddInstruction(_OP_EQ, trg, trg, expr);
|
||||
_fs->AddInstruction(_OP_JZ, trg, 0);
|
||||
@@ -1048,13 +1054,13 @@ public:
|
||||
_fs->SetIntructionParam(tonextcondjmp, 1, _fs->GetCurrentPos() - tonextcondjmp);
|
||||
if(_token == TK_DEFAULT) {
|
||||
// _fs->AddLineInfos(_lex._currentline, _lineinfo);
|
||||
Lex(); Expect(_SC(':'));
|
||||
Lex(); Expect(':');
|
||||
SQInteger stacksize = _fs->GetStackSize();
|
||||
_last_stacksize = _fs->GetStackSize();
|
||||
Statements();
|
||||
_fs->SetStackSize(stacksize);
|
||||
}
|
||||
Expect(_SC('}'));
|
||||
Expect('}');
|
||||
_fs->PopTarget();
|
||||
__nbreaks__ = _fs->_unresolvedbreaks.size() - __nbreaks__;
|
||||
if(__nbreaks__ > 0)ResolveBreaks(_fs, __nbreaks__);
|
||||
@@ -1075,7 +1081,7 @@ public:
|
||||
_fs->AddInstruction(_OP_LOAD, _fs->PushTarget(), _fs->GetConstant(id));
|
||||
if(_token == TK_DOUBLE_COLON) Emit2ArgsOP(_OP_GET);
|
||||
}
|
||||
Expect(_SC('('));
|
||||
Expect('(');
|
||||
CreateFunction(id);
|
||||
_fs->AddInstruction(_OP_CLOSURE, _fs->PushTarget(), _fs->_functions.size() - 1, 0);
|
||||
EmitDerefOp(_OP_NEWSLOT);
|
||||
@@ -1089,13 +1095,13 @@ public:
|
||||
_exst._funcarg = false;
|
||||
PrefixedExpr();
|
||||
es = PopExpState();
|
||||
if(es._deref == DEREF_NO_DEREF) Error(_SC("invalid class name"));
|
||||
if(es._deref == DEREF_NO_DEREF) Error("invalid class name");
|
||||
if(es._deref == DEREF_FIELD) {
|
||||
ClassExp();
|
||||
EmitDerefOp(_OP_NEWSLOT);
|
||||
_fs->PopTarget();
|
||||
}
|
||||
else Error(_SC("cannot create a class in a local with the syntax(class <local>)"));
|
||||
else Error("cannot create a class in a local with the syntax(class <local>)");
|
||||
}
|
||||
SQObject ExpectScalar()
|
||||
{
|
||||
@@ -1125,12 +1131,12 @@ public:
|
||||
val._unVal.fFloat = -_lex._fvalue;
|
||||
break;
|
||||
default:
|
||||
Error(_SC("scalar expected : integer,float"));
|
||||
Error("scalar expected : integer,float");
|
||||
val._type = OT_NULL; // Silent compile-warning
|
||||
}
|
||||
break;
|
||||
default:
|
||||
Error(_SC("scalar expected : integer,float or string"));
|
||||
Error("scalar expected : integer,float or string");
|
||||
val._type = OT_NULL; // Silent compile-warning
|
||||
}
|
||||
Lex();
|
||||
@@ -1141,14 +1147,14 @@ public:
|
||||
|
||||
Lex();
|
||||
SQObject id = Expect(TK_IDENTIFIER);
|
||||
Expect(_SC('{'));
|
||||
Expect('{');
|
||||
|
||||
SQObject table = _fs->CreateTable();
|
||||
SQInteger nval = 0;
|
||||
while(_token != _SC('}')) {
|
||||
while(_token != '}') {
|
||||
SQObject key = Expect(TK_IDENTIFIER);
|
||||
SQObject val;
|
||||
if(_token == _SC('=')) {
|
||||
if(_token == '=') {
|
||||
Lex();
|
||||
val = ExpectScalar();
|
||||
}
|
||||
@@ -1164,7 +1170,7 @@ public:
|
||||
/*SQObjectPtr dummy;
|
||||
if(enums->Get(strongid,dummy)) {
|
||||
dummy.Null(); strongid.Null();
|
||||
Error(_SC("enumeration already exists"));
|
||||
Error("enumeration already exists");
|
||||
}*/
|
||||
enums->NewSlot(SQObjectPtr(strongid),SQObjectPtr(table));
|
||||
strongid.Null();
|
||||
@@ -1188,7 +1194,7 @@ public:
|
||||
_fs->AddInstruction(_OP_JMP, 0, 0);
|
||||
SQInteger jmppos = _fs->GetCurrentPos();
|
||||
_fs->SetIntructionParam(trappos, 1, (_fs->GetCurrentPos() - trappos));
|
||||
Expect(TK_CATCH); Expect(_SC('(')); exid = Expect(TK_IDENTIFIER); Expect(_SC(')'));
|
||||
Expect(TK_CATCH); Expect('('); exid = Expect(TK_IDENTIFIER); Expect(')');
|
||||
SQInteger stacksize = _fs->GetStackSize();
|
||||
SQInteger ex_target = _fs->PushLocalVariable(exid);
|
||||
_fs->SetIntructionParam(trappos, 0, ex_target);
|
||||
@@ -1198,7 +1204,7 @@ public:
|
||||
}
|
||||
void FunctionExp(SQInteger ftype)
|
||||
{
|
||||
Lex(); Expect(_SC('('));
|
||||
Lex(); Expect('(');
|
||||
CreateFunction(_null_);
|
||||
_fs->AddInstruction(_OP_CLOSURE, _fs->PushTarget(), _fs->_functions.size() - 1, ftype == TK_FUNCTION?0:1);
|
||||
}
|
||||
@@ -1213,19 +1219,19 @@ public:
|
||||
if(_token == TK_ATTR_OPEN) {
|
||||
Lex();
|
||||
_fs->AddInstruction(_OP_NEWTABLE, _fs->PushTarget());
|
||||
ParseTableOrClass(_SC(','),TK_ATTR_CLOSE);
|
||||
ParseTableOrClass(',',TK_ATTR_CLOSE);
|
||||
attrs = _fs->TopTarget();
|
||||
}
|
||||
Expect(_SC('{'));
|
||||
Expect('{');
|
||||
if(attrs != -1) _fs->PopTarget();
|
||||
if(base != -1) _fs->PopTarget();
|
||||
_fs->AddInstruction(_OP_CLASS, _fs->PushTarget(), base, attrs);
|
||||
ParseTableOrClass(_SC(';'));
|
||||
ParseTableOrClass(';');
|
||||
}
|
||||
void DelegateExpr()
|
||||
{
|
||||
Lex(); CommaExpr();
|
||||
Expect(_SC(':'));
|
||||
Expect(':');
|
||||
CommaExpr();
|
||||
SQInteger table = _fs->PopTarget(), delegate = _fs->PopTarget();
|
||||
_fs->AddInstruction(_OP_DELEGATE, _fs->PushTarget(), table, delegate);
|
||||
@@ -1238,9 +1244,9 @@ public:
|
||||
_exst._funcarg = false;
|
||||
PrefixedExpr();
|
||||
es = PopExpState();
|
||||
if(es._deref == DEREF_NO_DEREF) Error(_SC("can't delete an expression"));
|
||||
if(es._deref == DEREF_NO_DEREF) Error("can't delete an expression");
|
||||
if(es._deref == DEREF_FIELD) Emit2ArgsOP(_OP_DELETE);
|
||||
else Error(_SC("cannot delete a local"));
|
||||
else Error("cannot delete a local");
|
||||
}
|
||||
void PrefixIncDec(SQInteger token)
|
||||
{
|
||||
@@ -1262,46 +1268,46 @@ public:
|
||||
SQFuncState *funcstate = _fs->PushChildState(_ss(_vm));
|
||||
funcstate->_name = name;
|
||||
SQObject paramname;
|
||||
funcstate->AddParameter(_fs->CreateString(_SC("this")));
|
||||
funcstate->AddParameter(_fs->CreateString("this"));
|
||||
funcstate->_sourcename = _sourcename;
|
||||
SQInteger defparams = 0;
|
||||
while(_token!=_SC(')')) {
|
||||
while(_token!=')') {
|
||||
if(_token == TK_VARPARAMS) {
|
||||
if(defparams > 0) Error(_SC("function with default parameters cannot have variable number of parameters"));
|
||||
if(defparams > 0) Error("function with default parameters cannot have variable number of parameters");
|
||||
funcstate->_varparams = true;
|
||||
Lex();
|
||||
if(_token != _SC(')')) Error(_SC("expected ')'"));
|
||||
if(_token != ')') Error("expected ')'");
|
||||
break;
|
||||
}
|
||||
else {
|
||||
paramname = Expect(TK_IDENTIFIER);
|
||||
funcstate->AddParameter(paramname);
|
||||
if(_token == _SC('=')) {
|
||||
if(_token == '=') {
|
||||
Lex();
|
||||
Expression();
|
||||
funcstate->AddDefaultParam(_fs->TopTarget());
|
||||
defparams++;
|
||||
}
|
||||
else {
|
||||
if(defparams > 0) Error(_SC("expected '='"));
|
||||
if(defparams > 0) Error("expected '='");
|
||||
}
|
||||
if(_token == _SC(',')) Lex();
|
||||
else if(_token != _SC(')')) Error(_SC("expected ')' or ','"));
|
||||
if(_token == ',') Lex();
|
||||
else if(_token != ')') Error("expected ')' or ','");
|
||||
}
|
||||
}
|
||||
Expect(_SC(')'));
|
||||
Expect(')');
|
||||
for(SQInteger n = 0; n < defparams; n++) {
|
||||
_fs->PopTarget();
|
||||
}
|
||||
//outer values
|
||||
if(_token == _SC(':')) {
|
||||
Lex(); Expect(_SC('('));
|
||||
while(_token != _SC(')')) {
|
||||
if(_token == ':') {
|
||||
Lex(); Expect('(');
|
||||
while(_token != ')') {
|
||||
paramname = Expect(TK_IDENTIFIER);
|
||||
//outers are treated as implicit local variables
|
||||
funcstate->AddOuterValue(paramname);
|
||||
if(_token == _SC(',')) Lex();
|
||||
else if(_token != _SC(')')) Error(_SC("expected ')' or ','"));
|
||||
if(_token == ',') Lex();
|
||||
else if(_token != ')') Error("expected ')' or ','");
|
||||
}
|
||||
Lex();
|
||||
}
|
||||
@@ -1309,7 +1315,7 @@ public:
|
||||
SQFuncState *currchunk = _fs;
|
||||
_fs = funcstate;
|
||||
Statement();
|
||||
funcstate->AddLineInfos(_lex._prevtoken == _SC('\n')?_lex._lasttokenline:_lex._currentline, _lineinfo, true);
|
||||
funcstate->AddLineInfos(_lex._prevtoken == '\n'?_lex._lasttokenline:_lex._currentline, _lineinfo, true);
|
||||
funcstate->AddInstruction(_OP_RETURN, -1);
|
||||
funcstate->SetStackSize(0);
|
||||
//_fs->->_stacksize = _fs->_stacksize;
|
||||
|
7
src/3rdparty/squirrel/squirrel/sqcompiler.h
vendored
7
src/3rdparty/squirrel/squirrel/sqcompiler.h
vendored
@@ -71,7 +71,12 @@ struct SQVM;
|
||||
#define TK_ENUM 323
|
||||
#define TK_CONST 324
|
||||
|
||||
|
||||
/* MSVC doesn't like NORETURN for function prototypes, but we kinda need it for GCC. */
|
||||
#if defined(_MSC_VER)
|
||||
typedef void(*CompilerErrorFunc)(void *ud, const SQChar *s);
|
||||
#else
|
||||
typedef NORETURN void(*CompilerErrorFunc)(void *ud, const SQChar *s);
|
||||
#endif
|
||||
|
||||
bool Compile(SQVM *vm, SQLEXREADFUNC rg, SQUserPointer up, const SQChar *sourcename, SQObjectPtr &out, bool raiseerror, bool lineinfo);
|
||||
#endif //_SQCOMPILER_H_
|
||||
|
55
src/3rdparty/squirrel/squirrel/sqdebug.cpp
vendored
55
src/3rdparty/squirrel/squirrel/sqdebug.cpp
vendored
@@ -1,14 +1,21 @@
|
||||
/*
|
||||
see copyright notice in squirrel.h
|
||||
*/
|
||||
* see copyright notice in squirrel.h
|
||||
*/
|
||||
|
||||
#include "../../../stdafx.h"
|
||||
|
||||
#include <squirrel.h>
|
||||
#include "sqpcheader.h"
|
||||
#include <stdarg.h>
|
||||
#include "sqvm.h"
|
||||
#include "sqfuncproto.h"
|
||||
#include "sqclosure.h"
|
||||
#include "sqstring.h"
|
||||
|
||||
#include "../../../core/alloc_func.hpp"
|
||||
#include "../../../string_func.h"
|
||||
|
||||
#include "../../../safeguards.h"
|
||||
|
||||
SQRESULT sq_getfunctioninfo(HSQUIRRELVM v,SQInteger level,SQFunctionInfo *fi)
|
||||
{
|
||||
SQInteger cssize = v->_callsstacksize;
|
||||
@@ -18,12 +25,12 @@ SQRESULT sq_getfunctioninfo(HSQUIRRELVM v,SQInteger level,SQFunctionInfo *fi)
|
||||
SQClosure *c = _closure(ci._closure);
|
||||
SQFunctionProto *proto = _funcproto(c->_function);
|
||||
fi->funcid = proto;
|
||||
fi->name = type(proto->_name) == OT_STRING?_stringval(proto->_name):_SC("unknown");
|
||||
fi->source = type(proto->_name) == OT_STRING?_stringval(proto->_sourcename):_SC("unknown");
|
||||
fi->name = type(proto->_name) == OT_STRING?_stringval(proto->_name):"unknown";
|
||||
fi->source = type(proto->_name) == OT_STRING?_stringval(proto->_sourcename):"unknown";
|
||||
return SQ_OK;
|
||||
}
|
||||
}
|
||||
return sq_throwerror(v,_SC("the object is not a closure"));
|
||||
return sq_throwerror(v,"the object is not a closure");
|
||||
}
|
||||
|
||||
SQRESULT sq_stackinfos(HSQUIRRELVM v, SQInteger level, SQStackInfos *si)
|
||||
@@ -43,8 +50,8 @@ SQRESULT sq_stackinfos(HSQUIRRELVM v, SQInteger level, SQStackInfos *si)
|
||||
}
|
||||
break;
|
||||
case OT_NATIVECLOSURE:
|
||||
si->source = _SC("NATIVE");
|
||||
si->funcname = _SC("unknown");
|
||||
si->source = "NATIVE";
|
||||
si->funcname = "unknown";
|
||||
if(type(_nativeclosure(ci._closure)->_name) == OT_STRING)
|
||||
si->funcname = _stringval(_nativeclosure(ci._closure)->_name);
|
||||
si->line = -1;
|
||||
@@ -60,9 +67,12 @@ void SQVM::Raise_Error(const SQChar *s, ...)
|
||||
{
|
||||
va_list vl;
|
||||
va_start(vl, s);
|
||||
scvsprintf(_sp(rsl((SQInteger)scstrlen(s)+(NUMBER_MAX_CHAR*2))), s, vl);
|
||||
size_t len = strlen(s)+(NUMBER_MAX_CHAR*2);
|
||||
char *buffer = MallocT<char>(len + 1);
|
||||
vseprintf(buffer, buffer + len, s, vl);
|
||||
va_end(vl);
|
||||
_lasterror = SQString::Create(_ss(this),_spval,-1);
|
||||
_lasterror = SQString::Create(_ss(this),buffer,-1);
|
||||
free(buffer);
|
||||
}
|
||||
|
||||
void SQVM::Raise_Error(SQObjectPtr &desc)
|
||||
@@ -72,20 +82,15 @@ void SQVM::Raise_Error(SQObjectPtr &desc)
|
||||
|
||||
SQString *SQVM::PrintObjVal(const SQObject &o)
|
||||
{
|
||||
char buf[NUMBER_MAX_CHAR+1];
|
||||
switch(type(o)) {
|
||||
case OT_STRING: return _string(o);
|
||||
case OT_INTEGER:
|
||||
#if defined(_SQ64)
|
||||
scsprintf(_sp(rsl(NUMBER_MAX_CHAR+1)), _SC("%ld"), _integer(o));
|
||||
#else
|
||||
scsprintf(_sp(rsl(NUMBER_MAX_CHAR+1)), _SC("%d"), _integer(o));
|
||||
#endif
|
||||
return SQString::Create(_ss(this), _spval);
|
||||
break;
|
||||
seprintf(buf, lastof(buf), OTTD_PRINTF64, _integer(o));
|
||||
return SQString::Create(_ss(this), buf);
|
||||
case OT_FLOAT:
|
||||
scsprintf(_sp(rsl(NUMBER_MAX_CHAR+1)), _SC("%.14g"), _float(o));
|
||||
return SQString::Create(_ss(this), _spval);
|
||||
break;
|
||||
seprintf(buf, lastof(buf), "%.14g", _float(o));
|
||||
return SQString::Create(_ss(this), buf);
|
||||
default:
|
||||
return SQString::Create(_ss(this), GetTypeName(o));
|
||||
}
|
||||
@@ -94,28 +99,28 @@ SQString *SQVM::PrintObjVal(const SQObject &o)
|
||||
void SQVM::Raise_IdxError(const SQObject &o)
|
||||
{
|
||||
SQObjectPtr oval = PrintObjVal(o);
|
||||
Raise_Error(_SC("the index '%.50s' does not exist"), _stringval(oval));
|
||||
Raise_Error("the index '%.50s' does not exist", _stringval(oval));
|
||||
}
|
||||
|
||||
void SQVM::Raise_CompareError(const SQObject &o1, const SQObject &o2)
|
||||
{
|
||||
SQObjectPtr oval1 = PrintObjVal(o1), oval2 = PrintObjVal(o2);
|
||||
Raise_Error(_SC("comparsion between '%.50s' and '%.50s'"), _stringval(oval1), _stringval(oval2));
|
||||
Raise_Error("comparsion between '%.50s' and '%.50s'", _stringval(oval1), _stringval(oval2));
|
||||
}
|
||||
|
||||
|
||||
void SQVM::Raise_ParamTypeError(SQInteger nparam,SQInteger typemask,SQInteger type)
|
||||
{
|
||||
SQObjectPtr exptypes = SQString::Create(_ss(this), _SC(""), -1);
|
||||
SQObjectPtr exptypes = SQString::Create(_ss(this), "", -1);
|
||||
SQInteger found = 0;
|
||||
for(SQInteger i=0; i<16; i++)
|
||||
{
|
||||
SQInteger mask = 0x00000001 << i;
|
||||
if(typemask & (mask)) {
|
||||
if(found>0) StringCat(exptypes,SQString::Create(_ss(this), _SC("|"), -1), exptypes);
|
||||
if(found>0) StringCat(exptypes,SQString::Create(_ss(this), "|", -1), exptypes);
|
||||
found ++;
|
||||
StringCat(exptypes,SQString::Create(_ss(this), IdType2Name((SQObjectType)mask), -1), exptypes);
|
||||
}
|
||||
}
|
||||
Raise_Error(_SC("parameter %d has an invalid type '%s' ; expected: '%s'"), nparam, IdType2Name((SQObjectType)type), _stringval(exptypes));
|
||||
Raise_Error("parameter %d has an invalid type '%s' ; expected: '%s'", nparam, IdType2Name((SQObjectType)type), _stringval(exptypes));
|
||||
}
|
||||
|
64
src/3rdparty/squirrel/squirrel/sqfuncproto.h
vendored
64
src/3rdparty/squirrel/squirrel/sqfuncproto.h
vendored
@@ -7,13 +7,13 @@
|
||||
enum SQOuterType {
|
||||
otLOCAL = 0,
|
||||
otSYMBOL = 1,
|
||||
otOUTER = 2
|
||||
otOUTER = 2,
|
||||
};
|
||||
|
||||
struct SQOuterVar
|
||||
{
|
||||
|
||||
SQOuterVar(){}
|
||||
SQOuterVar() : _type(otLOCAL) {}
|
||||
SQOuterVar(const SQObjectPtr &name,const SQObjectPtr &src,SQOuterType t)
|
||||
{
|
||||
_name = name;
|
||||
@@ -33,7 +33,7 @@ struct SQOuterVar
|
||||
|
||||
struct SQLocalVarInfo
|
||||
{
|
||||
SQLocalVarInfo():_start_op(0),_end_op(0){}
|
||||
SQLocalVarInfo():_start_op(0),_end_op(0), _pos(0){}
|
||||
SQLocalVarInfo(const SQLocalVarInfo &lvi)
|
||||
{
|
||||
_name=lvi._name;
|
||||
@@ -73,9 +73,37 @@ typedef sqvector<SQLineInfo> SQLineInfoVec;
|
||||
struct SQFunctionProto : public SQRefCounted
|
||||
{
|
||||
private:
|
||||
SQFunctionProto(){
|
||||
_stacksize=0;
|
||||
_bgenerator=false;}
|
||||
SQFunctionProto(SQInteger ninstructions,
|
||||
SQInteger nliterals,SQInteger nparameters,
|
||||
SQInteger nfunctions,SQInteger noutervalues,
|
||||
SQInteger nlineinfos,SQInteger nlocalvarinfos,SQInteger ndefaultparams)
|
||||
{
|
||||
_stacksize=0;
|
||||
_bgenerator=false;
|
||||
_varparams = false;
|
||||
_ninstructions = ninstructions;
|
||||
_literals = (SQObjectPtr*)&_instructions[ninstructions];
|
||||
_nliterals = nliterals;
|
||||
_parameters = (SQObjectPtr*)&_literals[nliterals];
|
||||
_nparameters = nparameters;
|
||||
_functions = (SQObjectPtr*)&_parameters[nparameters];
|
||||
_nfunctions = nfunctions;
|
||||
_outervalues = (SQOuterVar*)&_functions[nfunctions];
|
||||
_noutervalues = noutervalues;
|
||||
_lineinfos = (SQLineInfo *)&_outervalues[noutervalues];
|
||||
_nlineinfos = nlineinfos;
|
||||
_localvarinfos = (SQLocalVarInfo *)&_lineinfos[nlineinfos];
|
||||
_nlocalvarinfos = nlocalvarinfos;
|
||||
_defaultparams = (SQInteger *)&_localvarinfos[nlocalvarinfos];
|
||||
_ndefaultparams = ndefaultparams;
|
||||
|
||||
_CONSTRUCT_VECTOR(SQObjectPtr,_nliterals,_literals);
|
||||
_CONSTRUCT_VECTOR(SQObjectPtr,_nparameters,_parameters);
|
||||
_CONSTRUCT_VECTOR(SQObjectPtr,_nfunctions,_functions);
|
||||
_CONSTRUCT_VECTOR(SQOuterVar,_noutervalues,_outervalues);
|
||||
//_CONSTRUCT_VECTOR(SQLineInfo,_nlineinfos,_lineinfos); //not required are 2 integers
|
||||
_CONSTRUCT_VECTOR(SQLocalVarInfo,_nlocalvarinfos,_localvarinfos);
|
||||
}
|
||||
public:
|
||||
static SQFunctionProto *Create(SQInteger ninstructions,
|
||||
SQInteger nliterals,SQInteger nparameters,
|
||||
@@ -85,29 +113,7 @@ public:
|
||||
SQFunctionProto *f;
|
||||
//I compact the whole class and members in a single memory allocation
|
||||
f = (SQFunctionProto *)sq_vm_malloc(_FUNC_SIZE(ninstructions,nliterals,nparameters,nfunctions,noutervalues,nlineinfos,nlocalvarinfos,ndefaultparams));
|
||||
new (f) SQFunctionProto;
|
||||
f->_ninstructions = ninstructions;
|
||||
f->_literals = (SQObjectPtr*)&f->_instructions[ninstructions];
|
||||
f->_nliterals = nliterals;
|
||||
f->_parameters = (SQObjectPtr*)&f->_literals[nliterals];
|
||||
f->_nparameters = nparameters;
|
||||
f->_functions = (SQObjectPtr*)&f->_parameters[nparameters];
|
||||
f->_nfunctions = nfunctions;
|
||||
f->_outervalues = (SQOuterVar*)&f->_functions[nfunctions];
|
||||
f->_noutervalues = noutervalues;
|
||||
f->_lineinfos = (SQLineInfo *)&f->_outervalues[noutervalues];
|
||||
f->_nlineinfos = nlineinfos;
|
||||
f->_localvarinfos = (SQLocalVarInfo *)&f->_lineinfos[nlineinfos];
|
||||
f->_nlocalvarinfos = nlocalvarinfos;
|
||||
f->_defaultparams = (SQInteger *)&f->_localvarinfos[nlocalvarinfos];
|
||||
f->_ndefaultparams = ndefaultparams;
|
||||
|
||||
_CONSTRUCT_VECTOR(SQObjectPtr,f->_nliterals,f->_literals);
|
||||
_CONSTRUCT_VECTOR(SQObjectPtr,f->_nparameters,f->_parameters);
|
||||
_CONSTRUCT_VECTOR(SQObjectPtr,f->_nfunctions,f->_functions);
|
||||
_CONSTRUCT_VECTOR(SQOuterVar,f->_noutervalues,f->_outervalues);
|
||||
//_CONSTRUCT_VECTOR(SQLineInfo,f->_nlineinfos,f->_lineinfos); //not required are 2 integers
|
||||
_CONSTRUCT_VECTOR(SQLocalVarInfo,f->_nlocalvarinfos,f->_localvarinfos);
|
||||
new (f) SQFunctionProto(ninstructions, nliterals, nparameters, nfunctions, noutervalues, nlineinfos, nlocalvarinfos, ndefaultparams);
|
||||
return f;
|
||||
}
|
||||
void Release(){
|
||||
|
213
src/3rdparty/squirrel/squirrel/sqfuncstate.cpp
vendored
213
src/3rdparty/squirrel/squirrel/sqfuncstate.cpp
vendored
@@ -1,6 +1,9 @@
|
||||
/*
|
||||
see copyright notice in squirrel.h
|
||||
*/
|
||||
* see copyright notice in squirrel.h
|
||||
*/
|
||||
|
||||
#include "../../../stdafx.h"
|
||||
|
||||
#include "sqpcheader.h"
|
||||
#include "sqcompiler.h"
|
||||
#include "sqfuncproto.h"
|
||||
@@ -9,84 +12,82 @@
|
||||
#include "sqopcodes.h"
|
||||
#include "sqfuncstate.h"
|
||||
|
||||
#include "../../../safeguards.h"
|
||||
|
||||
#ifdef _DEBUG_DUMP
|
||||
SQInstructionDesc g_InstrDesc[]={
|
||||
{_SC("_OP_LINE")},
|
||||
{_SC("_OP_LOAD")},
|
||||
{_SC("_OP_LOADINT")},
|
||||
{_SC("_OP_LOADFLOAT")},
|
||||
{_SC("_OP_DLOAD")},
|
||||
{_SC("_OP_TAILCALL")},
|
||||
{_SC("_OP_CALL")},
|
||||
{_SC("_OP_PREPCALL")},
|
||||
{_SC("_OP_PREPCALLK")},
|
||||
{_SC("_OP_GETK")},
|
||||
{_SC("_OP_MOVE")},
|
||||
{_SC("_OP_NEWSLOT")},
|
||||
{_SC("_OP_DELETE")},
|
||||
{_SC("_OP_SET")},
|
||||
{_SC("_OP_GET")},
|
||||
{_SC("_OP_EQ")},
|
||||
{_SC("_OP_NE")},
|
||||
{_SC("_OP_ARITH")},
|
||||
{_SC("_OP_BITW")},
|
||||
{_SC("_OP_RETURN")},
|
||||
{_SC("_OP_LOADNULLS")},
|
||||
{_SC("_OP_LOADROOTTABLE")},
|
||||
{_SC("_OP_LOADBOOL")},
|
||||
{_SC("_OP_DMOVE")},
|
||||
{_SC("_OP_JMP")},
|
||||
{_SC("_OP_JNZ")},
|
||||
{_SC("_OP_JZ")},
|
||||
{_SC("_OP_LOADFREEVAR")},
|
||||
{_SC("_OP_VARGC")},
|
||||
{_SC("_OP_GETVARGV")},
|
||||
{_SC("_OP_NEWTABLE")},
|
||||
{_SC("_OP_NEWARRAY")},
|
||||
{_SC("_OP_APPENDARRAY")},
|
||||
{_SC("_OP_GETPARENT")},
|
||||
{_SC("_OP_COMPARITH")},
|
||||
{_SC("_OP_COMPARITHL")},
|
||||
{_SC("_OP_INC")},
|
||||
{_SC("_OP_INCL")},
|
||||
{_SC("_OP_PINC")},
|
||||
{_SC("_OP_PINCL")},
|
||||
{_SC("_OP_CMP")},
|
||||
{_SC("_OP_EXISTS")},
|
||||
{_SC("_OP_INSTANCEOF")},
|
||||
{_SC("_OP_AND")},
|
||||
{_SC("_OP_OR")},
|
||||
{_SC("_OP_NEG")},
|
||||
{_SC("_OP_NOT")},
|
||||
{_SC("_OP_BWNOT")},
|
||||
{_SC("_OP_CLOSURE")},
|
||||
{_SC("_OP_YIELD")},
|
||||
{_SC("_OP_RESUME")},
|
||||
{_SC("_OP_FOREACH")},
|
||||
{_SC("_OP_POSTFOREACH")},
|
||||
{_SC("_OP_DELEGATE")},
|
||||
{_SC("_OP_CLONE")},
|
||||
{_SC("_OP_TYPEOF")},
|
||||
{_SC("_OP_PUSHTRAP")},
|
||||
{_SC("_OP_POPTRAP")},
|
||||
{_SC("_OP_THROW")},
|
||||
{_SC("_OP_CLASS")},
|
||||
{_SC("_OP_NEWSLOTA")},
|
||||
{_SC("_OP_SCOPE_END")}
|
||||
{"_OP_LINE"},
|
||||
{"_OP_LOAD"},
|
||||
{"_OP_LOADINT"},
|
||||
{"_OP_LOADFLOAT"},
|
||||
{"_OP_DLOAD"},
|
||||
{"_OP_TAILCALL"},
|
||||
{"_OP_CALL"},
|
||||
{"_OP_PREPCALL"},
|
||||
{"_OP_PREPCALLK"},
|
||||
{"_OP_GETK"},
|
||||
{"_OP_MOVE"},
|
||||
{"_OP_NEWSLOT"},
|
||||
{"_OP_DELETE"},
|
||||
{"_OP_SET"},
|
||||
{"_OP_GET"},
|
||||
{"_OP_EQ"},
|
||||
{"_OP_NE"},
|
||||
{"_OP_ARITH"},
|
||||
{"_OP_BITW"},
|
||||
{"_OP_RETURN"},
|
||||
{"_OP_LOADNULLS"},
|
||||
{"_OP_LOADROOTTABLE"},
|
||||
{"_OP_LOADBOOL"},
|
||||
{"_OP_DMOVE"},
|
||||
{"_OP_JMP"},
|
||||
{"_OP_JNZ"},
|
||||
{"_OP_JZ"},
|
||||
{"_OP_LOADFREEVAR"},
|
||||
{"_OP_VARGC"},
|
||||
{"_OP_GETVARGV"},
|
||||
{"_OP_NEWTABLE"},
|
||||
{"_OP_NEWARRAY"},
|
||||
{"_OP_APPENDARRAY"},
|
||||
{"_OP_GETPARENT"},
|
||||
{"_OP_COMPARITH"},
|
||||
{"_OP_COMPARITHL"},
|
||||
{"_OP_INC"},
|
||||
{"_OP_INCL"},
|
||||
{"_OP_PINC"},
|
||||
{"_OP_PINCL"},
|
||||
{"_OP_CMP"},
|
||||
{"_OP_EXISTS"},
|
||||
{"_OP_INSTANCEOF"},
|
||||
{"_OP_AND"},
|
||||
{"_OP_OR"},
|
||||
{"_OP_NEG"},
|
||||
{"_OP_NOT"},
|
||||
{"_OP_BWNOT"},
|
||||
{"_OP_CLOSURE"},
|
||||
{"_OP_YIELD"},
|
||||
{"_OP_RESUME"},
|
||||
{"_OP_FOREACH"},
|
||||
{"_OP_POSTFOREACH"},
|
||||
{"_OP_DELEGATE"},
|
||||
{"_OP_CLONE"},
|
||||
{"_OP_TYPEOF"},
|
||||
{"_OP_PUSHTRAP"},
|
||||
{"_OP_POPTRAP"},
|
||||
{"_OP_THROW"},
|
||||
{"_OP_CLASS"},
|
||||
{"_OP_NEWSLOTA"},
|
||||
{"_OP_SCOPE_END"}
|
||||
};
|
||||
#endif
|
||||
void DumpLiteral(SQObjectPtr &o)
|
||||
{
|
||||
switch(type(o)){
|
||||
case OT_STRING: scprintf(_SC("\"%s\""),_stringval(o));break;
|
||||
case OT_FLOAT: scprintf(_SC("{%f}"),_float(o));break;
|
||||
#if defined(_SQ64)
|
||||
case OT_INTEGER: scprintf(_SC("{%ld}"),_integer(o));break;
|
||||
#else
|
||||
case OT_INTEGER: scprintf(_SC("{%d}"),_integer(o));break;
|
||||
#endif
|
||||
case OT_BOOL: scprintf(_SC("%s"),_integer(o)?_SC("true"):_SC("false"));break;
|
||||
default: scprintf(_SC("(%s %p)"),GetTypeName(o),(void*)_rawval(o));break; break; //shut up compiler
|
||||
case OT_STRING: printf("\"%s\"",_stringval(o));break;
|
||||
case OT_FLOAT: printf("{%f}",_float(o));break;
|
||||
case OT_INTEGER: printf("{" OTTD_PRINTF64 "}",_integer(o));break;
|
||||
case OT_BOOL: printf("%s",_integer(o)?"true":"false");break;
|
||||
default: printf("(%s %p)",GetTypeName(o),(void*)_rawval(o));break; break; //shut up compiler
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,11 +120,11 @@ 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("--------------------------------------------------------------------\n"));
|
||||
scprintf(_SC("*****FUNCTION [%s]\n"),type(func->_name)==OT_STRING?_stringval(func->_name):_SC("unknown"));
|
||||
scprintf(_SC("-----LITERALS\n"));
|
||||
printf("SQInstruction sizeof %d\n",sizeof(SQInstruction));
|
||||
printf("SQObject sizeof %d\n",sizeof(SQObject));
|
||||
printf("--------------------------------------------------------------------\n");
|
||||
printf("*****FUNCTION [%s]\n",type(func->_name)==OT_STRING?_stringval(func->_name):"unknown");
|
||||
printf("-----LITERALS\n");
|
||||
SQObjectPtr refidx,key,val;
|
||||
SQInteger idx;
|
||||
SQObjectPtrVec templiterals;
|
||||
@@ -133,43 +134,43 @@ void SQFuncState::Dump(SQFunctionProto *func)
|
||||
templiterals[_integer(val)]=key;
|
||||
}
|
||||
for(i=0;i<templiterals.size();i++){
|
||||
scprintf(_SC("[%d] "),n);
|
||||
printf("[%d] ",n);
|
||||
DumpLiteral(templiterals[i]);
|
||||
scprintf(_SC("\n"));
|
||||
printf("\n");
|
||||
n++;
|
||||
}
|
||||
scprintf(_SC("-----PARAMS\n"));
|
||||
printf("-----PARAMS\n");
|
||||
if(_varparams)
|
||||
scprintf(_SC("<<VARPARAMS>>\n"));
|
||||
printf("<<VARPARAMS>>\n");
|
||||
n=0;
|
||||
for(i=0;i<_parameters.size();i++){
|
||||
scprintf(_SC("[%d] "),n);
|
||||
printf("[%d] ",n);
|
||||
DumpLiteral(_parameters[i]);
|
||||
scprintf(_SC("\n"));
|
||||
printf("\n");
|
||||
n++;
|
||||
}
|
||||
scprintf(_SC("-----LOCALS\n"));
|
||||
printf("-----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);
|
||||
printf("[%d] %s \t%d %d\n",lvi._pos,_stringval(lvi._name),lvi._start_op,lvi._end_op);
|
||||
n++;
|
||||
}
|
||||
scprintf(_SC("-----LINE INFO\n"));
|
||||
printf("-----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);
|
||||
printf("op [%d] line [%d] \n",li._op,li._line);
|
||||
n++;
|
||||
}
|
||||
scprintf(_SC("-----dump\n"));
|
||||
printf("-----dump\n");
|
||||
n=0;
|
||||
for(i=0;i<_instructions.size();i++){
|
||||
SQInstruction &inst=_instructions[i];
|
||||
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);
|
||||
printf("[%03d] %15s %d ",n,g_InstrDesc[inst.op].name,inst._arg0);
|
||||
if(lidx >= 0xFFFFFFFF)
|
||||
scprintf(_SC("null"));
|
||||
printf("null");
|
||||
else {
|
||||
SQInteger refidx;
|
||||
SQObjectPtr val,key,refo;
|
||||
@@ -179,13 +180,13 @@ void SQFuncState::Dump(SQFunctionProto *func)
|
||||
DumpLiteral(key);
|
||||
}
|
||||
if(inst.op != _OP_DLOAD) {
|
||||
scprintf(_SC(" %d %d \n"),inst._arg2,inst._arg3);
|
||||
printf(" %d %d \n",inst._arg2,inst._arg3);
|
||||
}
|
||||
else {
|
||||
scprintf(_SC(" %d "),inst._arg2);
|
||||
printf(" %d ",inst._arg2);
|
||||
lidx = inst._arg3;
|
||||
if(lidx >= 0xFFFFFFFF)
|
||||
scprintf(_SC("null"));
|
||||
printf("null");
|
||||
else {
|
||||
SQInteger refidx;
|
||||
SQObjectPtr val,key,refo;
|
||||
@@ -193,23 +194,23 @@ void SQFuncState::Dump(SQFunctionProto *func)
|
||||
refo = refidx;
|
||||
}
|
||||
DumpLiteral(key);
|
||||
scprintf(_SC("\n"));
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
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);
|
||||
printf("[%03d] %15s %d %f %d %d\n",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);
|
||||
printf("[%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);
|
||||
printf("[%03d] %15s %d %d %d %d\n",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("--------------------------------------------------------------------\n\n"));
|
||||
printf("-----\n");
|
||||
printf("stack size[%d]\n",func->_stacksize);
|
||||
printf("--------------------------------------------------------------------\n\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -233,7 +234,7 @@ SQInteger SQFuncState::GetConstant(const SQObject &cons)
|
||||
_nliterals++;
|
||||
if(_nliterals > MAX_LITERALS) {
|
||||
val.Null();
|
||||
Error(_SC("internal compiler error: too many literals"));
|
||||
Error("internal compiler error: too many literals");
|
||||
}
|
||||
}
|
||||
return _integer(val);
|
||||
@@ -262,7 +263,7 @@ SQInteger SQFuncState::AllocStackPos()
|
||||
SQInteger npos=_vlocals.size();
|
||||
_vlocals.push_back(SQLocalVarInfo());
|
||||
if(_vlocals.size()>((SQUnsignedInteger)_stacksize)) {
|
||||
if(_stacksize>MAX_FUNC_STACKSIZE) Error(_SC("internal compiler error: too many locals"));
|
||||
if(_stacksize>MAX_FUNC_STACKSIZE) Error("internal compiler error: too many locals");
|
||||
_stacksize=_vlocals.size();
|
||||
}
|
||||
return npos;
|
||||
@@ -418,7 +419,6 @@ void SQFuncState::AddInstruction(SQInstruction &i)
|
||||
break;
|
||||
case _OP_GET:
|
||||
if( pi.op == _OP_LOAD && pi._arg0 == i._arg2 && (!IsLocal(pi._arg0))){
|
||||
pi._arg1 = pi._arg1;
|
||||
pi._arg2 = (unsigned char)i._arg1;
|
||||
pi.op = _OP_GETK;
|
||||
pi._arg0 = i._arg0;
|
||||
@@ -430,7 +430,6 @@ void SQFuncState::AddInstruction(SQInstruction &i)
|
||||
if( pi.op == _OP_LOAD && pi._arg0 == i._arg1 && (!IsLocal(pi._arg0))){
|
||||
pi.op = _OP_PREPCALLK;
|
||||
pi._arg0 = i._arg0;
|
||||
pi._arg1 = pi._arg1;
|
||||
pi._arg2 = i._arg2;
|
||||
pi._arg3 = i._arg3;
|
||||
return;
|
||||
@@ -440,7 +439,6 @@ void SQFuncState::AddInstruction(SQInstruction &i)
|
||||
if(pi.op == _OP_LOAD && pi._arg0 == i._arg1 && (!IsLocal(pi._arg0))){
|
||||
pi.op = _OP_APPENDARRAY;
|
||||
pi._arg0 = i._arg0;
|
||||
pi._arg1 = pi._arg1;
|
||||
pi._arg2 = MAX_FUNC_STACKSIZE;
|
||||
pi._arg3 = MAX_FUNC_STACKSIZE;
|
||||
return;
|
||||
@@ -475,7 +473,6 @@ void SQFuncState::AddInstruction(SQInstruction &i)
|
||||
{
|
||||
pi.op = i.op;
|
||||
pi._arg0 = i._arg0;
|
||||
pi._arg1 = pi._arg1;
|
||||
pi._arg2 = i._arg2;
|
||||
pi._arg3 = MAX_FUNC_STACKSIZE;
|
||||
return;
|
||||
@@ -541,7 +538,7 @@ SQFunctionProto *SQFuncState::BuildProto()
|
||||
for(SQUnsignedInteger no = 0; no < _lineinfos.size(); no++) f->_lineinfos[no] = _lineinfos[no];
|
||||
for(SQUnsignedInteger no = 0; no < _defaultparams.size(); no++) f->_defaultparams[no] = _defaultparams[no];
|
||||
|
||||
memcpy(f->_instructions,&_instructions[0],_instructions.size()*sizeof(SQInstruction));
|
||||
memcpy(f->_instructions,&_instructions[0],(size_t)_instructions.size()*sizeof(SQInstruction));
|
||||
|
||||
f->_varparams = _varparams;
|
||||
|
||||
|
231
src/3rdparty/squirrel/squirrel/sqlexer.cpp
vendored
231
src/3rdparty/squirrel/squirrel/sqlexer.cpp
vendored
@@ -1,30 +1,41 @@
|
||||
/*
|
||||
see copyright notice in squirrel.h
|
||||
*/
|
||||
* see copyright notice in squirrel.h
|
||||
*/
|
||||
|
||||
#include "../../../stdafx.h"
|
||||
|
||||
#include "sqpcheader.h"
|
||||
#include <ctype.h>
|
||||
#include <stdlib.h>
|
||||
#include "sqtable.h"
|
||||
#include "sqstring.h"
|
||||
#include "sqcompiler.h"
|
||||
#include "sqlexer.h"
|
||||
|
||||
#include "../../../string_func.h"
|
||||
|
||||
#include "../../../safeguards.h"
|
||||
|
||||
#define CUR_CHAR (_currdata)
|
||||
#define RETURN_TOKEN(t) { _prevtoken = _curtoken; _curtoken = t; return t;}
|
||||
#define IS_EOB() (CUR_CHAR <= SQUIRREL_EOB)
|
||||
#define NEXT() {Next();_currentcolumn++;}
|
||||
#define INIT_TEMP_STRING() { _longstr.resize(0);}
|
||||
#define APPEND_CHAR(c) { _longstr.push_back(c);}
|
||||
#define TERMINATE_BUFFER() {_longstr.push_back(_SC('\0'));}
|
||||
#define ADD_KEYWORD(key,id) _keywords->NewSlot( SQString::Create(ss, _SC(#key)) ,SQInteger(id))
|
||||
#define ADD_KEYWORD(key,id) _keywords->NewSlot( SQString::Create(ss, #key) ,SQInteger(id))
|
||||
|
||||
SQLexer::SQLexer(){}
|
||||
SQLexer::~SQLexer()
|
||||
{
|
||||
_keywords->Release();
|
||||
}
|
||||
|
||||
void SQLexer::Init(SQSharedState *ss, SQLEXREADFUNC rg, SQUserPointer up,CompilerErrorFunc efunc,void *ed)
|
||||
void SQLexer::APPEND_CHAR(WChar c)
|
||||
{
|
||||
char buf[4];
|
||||
size_t chars = Utf8Encode(buf, c);
|
||||
for (size_t i = 0; i < chars; i++) {
|
||||
_longstr.push_back(buf[i]);
|
||||
}
|
||||
}
|
||||
|
||||
SQLexer::SQLexer(SQSharedState *ss, SQLEXREADFUNC rg, SQUserPointer up,CompilerErrorFunc efunc,void *ed)
|
||||
{
|
||||
_errfunc = efunc;
|
||||
_errtarget = ed;
|
||||
@@ -74,20 +85,26 @@ void SQLexer::Init(SQSharedState *ss, SQLEXREADFUNC rg, SQUserPointer up,Compile
|
||||
_lasttokenline = _currentline = 1;
|
||||
_currentcolumn = 0;
|
||||
_prevtoken = -1;
|
||||
_curtoken = -1;
|
||||
|
||||
_svalue = NULL;
|
||||
_nvalue = 0;
|
||||
_fvalue = 0;
|
||||
|
||||
Next();
|
||||
}
|
||||
|
||||
void SQLexer::Error(const SQChar *err)
|
||||
NORETURN void SQLexer::Error(const SQChar *err)
|
||||
{
|
||||
_errfunc(_errtarget,err);
|
||||
}
|
||||
|
||||
void SQLexer::Next()
|
||||
{
|
||||
SQInteger t = _readf(_up);
|
||||
if(t > MAX_CHAR) Error(_SC("Invalid character"));
|
||||
WChar t = _readf(_up);
|
||||
if(t > MAX_CHAR) Error("Invalid character");
|
||||
if(t != 0) {
|
||||
_currdata = (LexChar)t;
|
||||
_currdata = t;
|
||||
return;
|
||||
}
|
||||
_currdata = SQUIRREL_EOB;
|
||||
@@ -110,9 +127,9 @@ void SQLexer::LexBlockComment()
|
||||
bool done = false;
|
||||
while(!done) {
|
||||
switch(CUR_CHAR) {
|
||||
case _SC('*'): { NEXT(); if(CUR_CHAR == _SC('/')) { done = true; NEXT(); }}; continue;
|
||||
case _SC('\n'): _currentline++; NEXT(); continue;
|
||||
case SQUIRREL_EOB: Error(_SC("missing \"*/\" in comment"));
|
||||
case '*': { NEXT(); if(CUR_CHAR == '/') { done = true; NEXT(); }}; continue;
|
||||
case '\n': _currentline++; NEXT(); continue;
|
||||
case SQUIRREL_EOB: Error("missing \"*/\" in comment");
|
||||
default: NEXT();
|
||||
}
|
||||
}
|
||||
@@ -123,136 +140,134 @@ SQInteger SQLexer::Lex()
|
||||
_lasttokenline = _currentline;
|
||||
while(CUR_CHAR != SQUIRREL_EOB) {
|
||||
switch(CUR_CHAR){
|
||||
case _SC('\t'): case _SC('\r'): case _SC(' '): NEXT(); continue;
|
||||
case _SC('\n'):
|
||||
case '\t': case '\r': case ' ': NEXT(); continue;
|
||||
case '\n':
|
||||
_currentline++;
|
||||
_prevtoken=_curtoken;
|
||||
_curtoken=_SC('\n');
|
||||
_curtoken='\n';
|
||||
NEXT();
|
||||
_currentcolumn=1;
|
||||
continue;
|
||||
case _SC('/'):
|
||||
case '/':
|
||||
NEXT();
|
||||
switch(CUR_CHAR){
|
||||
case _SC('*'):
|
||||
case '*':
|
||||
NEXT();
|
||||
LexBlockComment();
|
||||
continue;
|
||||
case _SC('/'):
|
||||
do { NEXT(); } while (CUR_CHAR != _SC('\n') && (!IS_EOB()));
|
||||
case '/':
|
||||
do { NEXT(); } while (CUR_CHAR != '\n' && (!IS_EOB()));
|
||||
continue;
|
||||
case _SC('='):
|
||||
case '=':
|
||||
NEXT();
|
||||
RETURN_TOKEN(TK_DIVEQ);
|
||||
continue;
|
||||
case _SC('>'):
|
||||
case '>':
|
||||
NEXT();
|
||||
RETURN_TOKEN(TK_ATTR_CLOSE);
|
||||
continue;
|
||||
default:
|
||||
RETURN_TOKEN('/');
|
||||
}
|
||||
case _SC('='):
|
||||
case '=':
|
||||
NEXT();
|
||||
if (CUR_CHAR != _SC('=')){ RETURN_TOKEN('=') }
|
||||
if (CUR_CHAR != '='){ RETURN_TOKEN('=') }
|
||||
else { NEXT(); RETURN_TOKEN(TK_EQ); }
|
||||
case _SC('<'):
|
||||
case '<':
|
||||
NEXT();
|
||||
if ( CUR_CHAR == _SC('=') ) { NEXT(); RETURN_TOKEN(TK_LE) }
|
||||
else if ( CUR_CHAR == _SC('-') ) { NEXT(); RETURN_TOKEN(TK_NEWSLOT); }
|
||||
else if ( CUR_CHAR == _SC('<') ) { NEXT(); RETURN_TOKEN(TK_SHIFTL); }
|
||||
else if ( CUR_CHAR == _SC('/') ) { NEXT(); RETURN_TOKEN(TK_ATTR_OPEN); }
|
||||
//else if ( CUR_CHAR == _SC('[') ) { NEXT(); ReadMultilineString(); RETURN_TOKEN(TK_STRING_LITERAL); }
|
||||
if ( CUR_CHAR == '=' ) { NEXT(); RETURN_TOKEN(TK_LE) }
|
||||
else if ( CUR_CHAR == '-' ) { NEXT(); RETURN_TOKEN(TK_NEWSLOT); }
|
||||
else if ( CUR_CHAR == '<' ) { NEXT(); RETURN_TOKEN(TK_SHIFTL); }
|
||||
else if ( CUR_CHAR == '/' ) { NEXT(); RETURN_TOKEN(TK_ATTR_OPEN); }
|
||||
//else if ( CUR_CHAR == '[' ) { NEXT(); ReadMultilineString(); RETURN_TOKEN(TK_STRING_LITERAL); }
|
||||
else { RETURN_TOKEN('<') }
|
||||
case _SC('>'):
|
||||
case '>':
|
||||
NEXT();
|
||||
if (CUR_CHAR == _SC('=')){ NEXT(); RETURN_TOKEN(TK_GE);}
|
||||
else if(CUR_CHAR == _SC('>')){
|
||||
if (CUR_CHAR == '='){ NEXT(); RETURN_TOKEN(TK_GE);}
|
||||
else if(CUR_CHAR == '>'){
|
||||
NEXT();
|
||||
if(CUR_CHAR == _SC('>')){
|
||||
if(CUR_CHAR == '>'){
|
||||
NEXT();
|
||||
RETURN_TOKEN(TK_USHIFTR);
|
||||
}
|
||||
RETURN_TOKEN(TK_SHIFTR);
|
||||
}
|
||||
else { RETURN_TOKEN('>') }
|
||||
case _SC('!'):
|
||||
case '!':
|
||||
NEXT();
|
||||
if (CUR_CHAR != _SC('=')){ RETURN_TOKEN('!')}
|
||||
if (CUR_CHAR != '='){ RETURN_TOKEN('!')}
|
||||
else { NEXT(); RETURN_TOKEN(TK_NE); }
|
||||
case _SC('@'): {
|
||||
case '@': {
|
||||
SQInteger stype;
|
||||
NEXT();
|
||||
if(CUR_CHAR != _SC('"'))
|
||||
Error(_SC("string expected"));
|
||||
if((stype=ReadString(_SC('"'),true))!=-1) {
|
||||
if(CUR_CHAR != '"')
|
||||
Error("string expected");
|
||||
if((stype=ReadString('"',true))!=-1) {
|
||||
RETURN_TOKEN(stype);
|
||||
}
|
||||
Error(_SC("error parsing the string"));
|
||||
Error("error parsing the string");
|
||||
}
|
||||
case _SC('"'):
|
||||
case _SC('\''): {
|
||||
case '"':
|
||||
case '\'': {
|
||||
SQInteger stype;
|
||||
if((stype=ReadString(CUR_CHAR,false))!=-1){
|
||||
RETURN_TOKEN(stype);
|
||||
}
|
||||
Error(_SC("error parsing the string"));
|
||||
Error("error parsing the string");
|
||||
}
|
||||
case _SC('{'): case _SC('}'): case _SC('('): case _SC(')'): case _SC('['): case _SC(']'):
|
||||
case _SC(';'): case _SC(','): case _SC('?'): case _SC('^'): case _SC('~'):
|
||||
case '{': case '}': case '(': case ')': case '[': case ']':
|
||||
case ';': case ',': case '?': case '^': case '~':
|
||||
{SQInteger ret = CUR_CHAR;
|
||||
NEXT(); RETURN_TOKEN(ret); }
|
||||
case _SC('.'):
|
||||
case '.':
|
||||
NEXT();
|
||||
if (CUR_CHAR != _SC('.')){ RETURN_TOKEN('.') }
|
||||
if (CUR_CHAR != '.'){ RETURN_TOKEN('.') }
|
||||
NEXT();
|
||||
if (CUR_CHAR != _SC('.')){ Error(_SC("invalid token '..'")); }
|
||||
if (CUR_CHAR != '.'){ Error("invalid token '..'"); }
|
||||
NEXT();
|
||||
RETURN_TOKEN(TK_VARPARAMS);
|
||||
case _SC('&'):
|
||||
case '&':
|
||||
NEXT();
|
||||
if (CUR_CHAR != _SC('&')){ RETURN_TOKEN('&') }
|
||||
if (CUR_CHAR != '&'){ RETURN_TOKEN('&') }
|
||||
else { NEXT(); RETURN_TOKEN(TK_AND); }
|
||||
case _SC('|'):
|
||||
case '|':
|
||||
NEXT();
|
||||
if (CUR_CHAR != _SC('|')){ RETURN_TOKEN('|') }
|
||||
if (CUR_CHAR != '|'){ RETURN_TOKEN('|') }
|
||||
else { NEXT(); RETURN_TOKEN(TK_OR); }
|
||||
case _SC(':'):
|
||||
case ':':
|
||||
NEXT();
|
||||
if (CUR_CHAR != _SC(':')){ RETURN_TOKEN(':') }
|
||||
if (CUR_CHAR != ':'){ RETURN_TOKEN(':') }
|
||||
else { NEXT(); RETURN_TOKEN(TK_DOUBLE_COLON); }
|
||||
case _SC('*'):
|
||||
case '*':
|
||||
NEXT();
|
||||
if (CUR_CHAR == _SC('=')){ NEXT(); RETURN_TOKEN(TK_MULEQ);}
|
||||
if (CUR_CHAR == '='){ NEXT(); RETURN_TOKEN(TK_MULEQ);}
|
||||
else RETURN_TOKEN('*');
|
||||
case _SC('%'):
|
||||
case '%':
|
||||
NEXT();
|
||||
if (CUR_CHAR == _SC('=')){ NEXT(); RETURN_TOKEN(TK_MODEQ);}
|
||||
if (CUR_CHAR == '='){ NEXT(); RETURN_TOKEN(TK_MODEQ);}
|
||||
else RETURN_TOKEN('%');
|
||||
case _SC('-'):
|
||||
case '-':
|
||||
NEXT();
|
||||
if (CUR_CHAR == _SC('=')){ NEXT(); RETURN_TOKEN(TK_MINUSEQ);}
|
||||
else if (CUR_CHAR == _SC('-')){ NEXT(); RETURN_TOKEN(TK_MINUSMINUS);}
|
||||
if (CUR_CHAR == '='){ NEXT(); RETURN_TOKEN(TK_MINUSEQ);}
|
||||
else if (CUR_CHAR == '-'){ NEXT(); RETURN_TOKEN(TK_MINUSMINUS);}
|
||||
else RETURN_TOKEN('-');
|
||||
case _SC('+'):
|
||||
case '+':
|
||||
NEXT();
|
||||
if (CUR_CHAR == _SC('=')){ NEXT(); RETURN_TOKEN(TK_PLUSEQ);}
|
||||
else if (CUR_CHAR == _SC('+')){ NEXT(); RETURN_TOKEN(TK_PLUSPLUS);}
|
||||
if (CUR_CHAR == '='){ NEXT(); RETURN_TOKEN(TK_PLUSEQ);}
|
||||
else if (CUR_CHAR == '+'){ NEXT(); RETURN_TOKEN(TK_PLUSPLUS);}
|
||||
else RETURN_TOKEN('+');
|
||||
case SQUIRREL_EOB:
|
||||
return 0;
|
||||
default:{
|
||||
if (scisdigit(CUR_CHAR)) {
|
||||
if (isdigit(CUR_CHAR)) {
|
||||
SQInteger ret = ReadNumber();
|
||||
RETURN_TOKEN(ret);
|
||||
}
|
||||
else if (scisalpha(CUR_CHAR) || CUR_CHAR == _SC('_')) {
|
||||
else if (isalpha(CUR_CHAR) || CUR_CHAR == '_') {
|
||||
SQInteger t = ReadID();
|
||||
RETURN_TOKEN(t);
|
||||
}
|
||||
else {
|
||||
SQInteger c = CUR_CHAR;
|
||||
if (sciscntrl((int)c)) Error(_SC("unexpected character(control)"));
|
||||
if (iscntrl((int)c)) Error("unexpected character(control)");
|
||||
NEXT();
|
||||
RETURN_TOKEN(c);
|
||||
}
|
||||
@@ -273,7 +288,7 @@ SQInteger SQLexer::GetIDType(SQChar *s)
|
||||
}
|
||||
|
||||
|
||||
SQInteger SQLexer::ReadString(SQChar ndelim,bool verbatim)
|
||||
SQInteger SQLexer::ReadString(WChar ndelim,bool verbatim)
|
||||
{
|
||||
INIT_TEMP_STRING();
|
||||
NEXT();
|
||||
@@ -282,22 +297,22 @@ SQInteger SQLexer::ReadString(SQChar ndelim,bool verbatim)
|
||||
while(CUR_CHAR != ndelim) {
|
||||
switch(CUR_CHAR) {
|
||||
case SQUIRREL_EOB:
|
||||
Error(_SC("unfinished string"));
|
||||
Error("unfinished string");
|
||||
return -1;
|
||||
case _SC('\n'):
|
||||
if(!verbatim) Error(_SC("newline in a constant"));
|
||||
case '\n':
|
||||
if(!verbatim) Error("newline in a constant");
|
||||
APPEND_CHAR(CUR_CHAR); NEXT();
|
||||
_currentline++;
|
||||
break;
|
||||
case _SC('\\'):
|
||||
case '\\':
|
||||
if(verbatim) {
|
||||
APPEND_CHAR('\\'); NEXT();
|
||||
}
|
||||
else {
|
||||
NEXT();
|
||||
switch(CUR_CHAR) {
|
||||
case _SC('x'): NEXT(); {
|
||||
if(!isxdigit(CUR_CHAR)) Error(_SC("hexadecimal number expected"));
|
||||
case 'x': NEXT(); {
|
||||
if(!isxdigit(CUR_CHAR)) Error("hexadecimal number expected");
|
||||
const SQInteger maxdigits = 4;
|
||||
SQChar temp[maxdigits+1];
|
||||
SQInteger n = 0;
|
||||
@@ -308,22 +323,22 @@ SQInteger SQLexer::ReadString(SQChar ndelim,bool verbatim)
|
||||
}
|
||||
temp[n] = 0;
|
||||
SQChar *sTemp;
|
||||
APPEND_CHAR((SQChar)scstrtoul(temp,&sTemp,16));
|
||||
APPEND_CHAR((SQChar)strtoul(temp,&sTemp,16));
|
||||
}
|
||||
break;
|
||||
case _SC('t'): APPEND_CHAR(_SC('\t')); NEXT(); break;
|
||||
case _SC('a'): APPEND_CHAR(_SC('\a')); NEXT(); break;
|
||||
case _SC('b'): APPEND_CHAR(_SC('\b')); NEXT(); break;
|
||||
case _SC('n'): APPEND_CHAR(_SC('\n')); NEXT(); break;
|
||||
case _SC('r'): APPEND_CHAR(_SC('\r')); NEXT(); break;
|
||||
case _SC('v'): APPEND_CHAR(_SC('\v')); NEXT(); break;
|
||||
case _SC('f'): APPEND_CHAR(_SC('\f')); NEXT(); break;
|
||||
case _SC('0'): APPEND_CHAR(_SC('\0')); NEXT(); break;
|
||||
case _SC('\\'): APPEND_CHAR(_SC('\\')); NEXT(); break;
|
||||
case _SC('"'): APPEND_CHAR(_SC('"')); NEXT(); break;
|
||||
case _SC('\''): APPEND_CHAR(_SC('\'')); NEXT(); break;
|
||||
case 't': APPEND_CHAR('\t'); NEXT(); break;
|
||||
case 'a': APPEND_CHAR('\a'); NEXT(); break;
|
||||
case 'b': APPEND_CHAR('\b'); NEXT(); break;
|
||||
case 'n': APPEND_CHAR('\n'); NEXT(); break;
|
||||
case 'r': APPEND_CHAR('\r'); NEXT(); break;
|
||||
case 'v': APPEND_CHAR('\v'); NEXT(); break;
|
||||
case 'f': APPEND_CHAR('\f'); NEXT(); break;
|
||||
case '0': APPEND_CHAR('\0'); NEXT(); break;
|
||||
case '\\': APPEND_CHAR('\\'); NEXT(); break;
|
||||
case '"': APPEND_CHAR('"'); NEXT(); break;
|
||||
case '\'': APPEND_CHAR('\''); NEXT(); break;
|
||||
default:
|
||||
Error(_SC("unrecognised escaper char"));
|
||||
Error("unrecognised escaper char");
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -344,9 +359,9 @@ SQInteger SQLexer::ReadString(SQChar ndelim,bool verbatim)
|
||||
}
|
||||
TERMINATE_BUFFER();
|
||||
SQInteger len = _longstr.size()-1;
|
||||
if(ndelim == _SC('\'')) {
|
||||
if(len == 0) Error(_SC("empty constant"));
|
||||
if(len > 1) Error(_SC("constant too long"));
|
||||
if(ndelim == '\'') {
|
||||
if(len == 0) Error("empty constant");
|
||||
if(len > 1) Error("constant too long");
|
||||
_nvalue = _longstr[0];
|
||||
return TK_INTEGER;
|
||||
}
|
||||
@@ -359,8 +374,8 @@ void LexHexadecimal(const SQChar *s,SQUnsignedInteger *res)
|
||||
*res = 0;
|
||||
while(*s != 0)
|
||||
{
|
||||
if(scisdigit(*s)) *res = (*res)*16+((*s++)-'0');
|
||||
else if(scisxdigit(*s)) *res = (*res)*16+(toupper(*s++)-'A'+10);
|
||||
if(isdigit(*s)) *res = (*res)*16+((*s++)-'0');
|
||||
else if(isxdigit(*s)) *res = (*res)*16+(toupper(*s++)-'A'+10);
|
||||
else { assert(0); }
|
||||
}
|
||||
}
|
||||
@@ -374,7 +389,7 @@ void LexInteger(const SQChar *s,SQUnsignedInteger *res)
|
||||
}
|
||||
}
|
||||
|
||||
SQInteger scisodigit(SQChar c) { return c >= _SC('0') && c <= _SC('7'); }
|
||||
SQInteger scisodigit(SQChar c) { return c >= '0' && c <= '7'; }
|
||||
|
||||
void LexOctal(const SQChar *s,SQUnsignedInteger *res)
|
||||
{
|
||||
@@ -401,14 +416,14 @@ SQInteger SQLexer::ReadNumber()
|
||||
SQChar *sTemp;
|
||||
INIT_TEMP_STRING();
|
||||
NEXT();
|
||||
if(firstchar == _SC('0') && (toupper(CUR_CHAR) == _SC('X') || scisodigit(CUR_CHAR)) ) {
|
||||
if(firstchar == '0' && (toupper(CUR_CHAR) == 'X' || scisodigit(CUR_CHAR)) ) {
|
||||
if(scisodigit(CUR_CHAR)) {
|
||||
type = TOCTAL;
|
||||
while(scisodigit(CUR_CHAR)) {
|
||||
APPEND_CHAR(CUR_CHAR);
|
||||
NEXT();
|
||||
}
|
||||
if(scisdigit(CUR_CHAR)) Error(_SC("invalid octal number"));
|
||||
if(isdigit(CUR_CHAR)) Error("invalid octal number");
|
||||
}
|
||||
else {
|
||||
NEXT();
|
||||
@@ -417,15 +432,15 @@ SQInteger SQLexer::ReadNumber()
|
||||
APPEND_CHAR(CUR_CHAR);
|
||||
NEXT();
|
||||
}
|
||||
if(_longstr.size() > MAX_HEX_DIGITS) Error(_SC("too many digits for an Hex number"));
|
||||
if(_longstr.size() > MAX_HEX_DIGITS) Error("too many digits for an Hex number");
|
||||
}
|
||||
}
|
||||
else {
|
||||
APPEND_CHAR((int)firstchar);
|
||||
while (CUR_CHAR == _SC('.') || scisdigit(CUR_CHAR) || isexponent(CUR_CHAR)) {
|
||||
if(CUR_CHAR == _SC('.') || isexponent(CUR_CHAR)) type = TFLOAT;
|
||||
while (CUR_CHAR == '.' || isdigit(CUR_CHAR) || isexponent(CUR_CHAR)) {
|
||||
if(CUR_CHAR == '.' || isexponent(CUR_CHAR)) type = TFLOAT;
|
||||
if(isexponent(CUR_CHAR)) {
|
||||
if(type != TFLOAT) Error(_SC("invalid numeric format"));
|
||||
if(type != TFLOAT) Error("invalid numeric format");
|
||||
type = TSCIENTIFIC;
|
||||
APPEND_CHAR(CUR_CHAR);
|
||||
NEXT();
|
||||
@@ -433,7 +448,7 @@ SQInteger SQLexer::ReadNumber()
|
||||
APPEND_CHAR(CUR_CHAR);
|
||||
NEXT();
|
||||
}
|
||||
if(!scisdigit(CUR_CHAR)) Error(_SC("exponent expected"));
|
||||
if(!isdigit(CUR_CHAR)) Error("exponent expected");
|
||||
}
|
||||
|
||||
APPEND_CHAR(CUR_CHAR);
|
||||
@@ -444,7 +459,7 @@ SQInteger SQLexer::ReadNumber()
|
||||
switch(type) {
|
||||
case TSCIENTIFIC:
|
||||
case TFLOAT:
|
||||
_fvalue = (SQFloat)scstrtod(&_longstr[0],&sTemp);
|
||||
_fvalue = (SQFloat)strtod(&_longstr[0],&sTemp);
|
||||
return TK_FLOAT;
|
||||
case TINT:
|
||||
LexInteger(&_longstr[0],(SQUnsignedInteger *)&_nvalue);
|
||||
@@ -466,7 +481,7 @@ SQInteger SQLexer::ReadID()
|
||||
do {
|
||||
APPEND_CHAR(CUR_CHAR);
|
||||
NEXT();
|
||||
} while(scisalnum(CUR_CHAR) || CUR_CHAR == _SC('_'));
|
||||
} while(isalnum(CUR_CHAR) || CUR_CHAR == '_');
|
||||
TERMINATE_BUFFER();
|
||||
res = GetIDType(&_longstr[0]);
|
||||
if(res == TK_IDENTIFIER || res == TK_CONSTRUCTOR) {
|
||||
|
15
src/3rdparty/squirrel/squirrel/sqlexer.h
vendored
15
src/3rdparty/squirrel/squirrel/sqlexer.h
vendored
@@ -2,25 +2,26 @@
|
||||
#ifndef _SQLEXER_H_
|
||||
#define _SQLEXER_H_
|
||||
|
||||
typedef unsigned short LexChar;
|
||||
|
||||
struct SQLexer
|
||||
{
|
||||
SQLexer();
|
||||
~SQLexer();
|
||||
void Init(SQSharedState *ss,SQLEXREADFUNC rg,SQUserPointer up,CompilerErrorFunc efunc,void *ed);
|
||||
void Error(const SQChar *err);
|
||||
SQLexer(SQSharedState *ss,SQLEXREADFUNC rg,SQUserPointer up,CompilerErrorFunc efunc,void *ed);
|
||||
NORETURN void Error(const SQChar *err);
|
||||
SQInteger Lex();
|
||||
const SQChar *Tok2Str(SQInteger tok);
|
||||
private:
|
||||
SQInteger GetIDType(SQChar *s);
|
||||
SQInteger ReadString(SQChar ndelim,bool verbatim);
|
||||
SQInteger ReadString(WChar ndelim,bool verbatim);
|
||||
SQInteger ReadNumber();
|
||||
void LexBlockComment();
|
||||
SQInteger ReadID();
|
||||
void Next();
|
||||
SQInteger _curtoken;
|
||||
SQTable *_keywords;
|
||||
void INIT_TEMP_STRING() { _longstr.resize(0); }
|
||||
void APPEND_CHAR(WChar c);
|
||||
void TERMINATE_BUFFER() { _longstr.push_back('\0'); }
|
||||
|
||||
public:
|
||||
SQInteger _prevtoken;
|
||||
SQInteger _currentline;
|
||||
@@ -31,7 +32,7 @@ public:
|
||||
SQFloat _fvalue;
|
||||
SQLEXREADFUNC _readf;
|
||||
SQUserPointer _up;
|
||||
LexChar _currdata;
|
||||
WChar _currdata;
|
||||
SQSharedState *_sharedstate;
|
||||
sqvector<SQChar> _longstr;
|
||||
CompilerErrorFunc _errfunc;
|
||||
|
17
src/3rdparty/squirrel/squirrel/sqmem.cpp
vendored
17
src/3rdparty/squirrel/squirrel/sqmem.cpp
vendored
@@ -1,9 +1,16 @@
|
||||
/*
|
||||
see copyright notice in squirrel.h
|
||||
*/
|
||||
#include "sqpcheader.h"
|
||||
void *sq_vm_malloc(SQUnsignedInteger size){ return malloc(size); }
|
||||
* see copyright notice in squirrel.h
|
||||
*/
|
||||
|
||||
void *sq_vm_realloc(void *p, SQUnsignedInteger oldsize, SQUnsignedInteger size){ return realloc(p, size); }
|
||||
#include "../../../stdafx.h"
|
||||
|
||||
#include "sqpcheader.h"
|
||||
|
||||
#include "../../../core/alloc_func.hpp"
|
||||
#include "../../../safeguards.h"
|
||||
|
||||
void *sq_vm_malloc(SQUnsignedInteger size){ return MallocT<char>((size_t)size); }
|
||||
|
||||
void *sq_vm_realloc(void *p, SQUnsignedInteger oldsize, SQUnsignedInteger size){ return ReallocT<char>(static_cast<char*>(p), (size_t)size); }
|
||||
|
||||
void sq_vm_free(void *p, SQUnsignedInteger size){ free(p); }
|
||||
|
63
src/3rdparty/squirrel/squirrel/sqobject.cpp
vendored
63
src/3rdparty/squirrel/squirrel/sqobject.cpp
vendored
@@ -1,6 +1,9 @@
|
||||
/*
|
||||
see copyright notice in squirrel.h
|
||||
*/
|
||||
* see copyright notice in squirrel.h
|
||||
*/
|
||||
|
||||
#include "../../../stdafx.h"
|
||||
|
||||
#include "sqpcheader.h"
|
||||
#include "sqvm.h"
|
||||
#include "sqstring.h"
|
||||
@@ -11,30 +14,32 @@
|
||||
#include "sqclass.h"
|
||||
#include "sqclosure.h"
|
||||
|
||||
#include "../../../safeguards.h"
|
||||
|
||||
|
||||
const SQChar *IdType2Name(SQObjectType type)
|
||||
{
|
||||
switch(_RAW_TYPE(type))
|
||||
{
|
||||
case _RT_NULL:return _SC("null");
|
||||
case _RT_INTEGER:return _SC("integer");
|
||||
case _RT_FLOAT:return _SC("float");
|
||||
case _RT_BOOL:return _SC("bool");
|
||||
case _RT_STRING:return _SC("string");
|
||||
case _RT_TABLE:return _SC("table");
|
||||
case _RT_ARRAY:return _SC("array");
|
||||
case _RT_GENERATOR:return _SC("generator");
|
||||
case _RT_NULL:return "null";
|
||||
case _RT_INTEGER:return "integer";
|
||||
case _RT_FLOAT:return "float";
|
||||
case _RT_BOOL:return "bool";
|
||||
case _RT_STRING:return "string";
|
||||
case _RT_TABLE:return "table";
|
||||
case _RT_ARRAY:return "array";
|
||||
case _RT_GENERATOR:return "generator";
|
||||
case _RT_CLOSURE:
|
||||
case _RT_NATIVECLOSURE:
|
||||
return _SC("function");
|
||||
return "function";
|
||||
case _RT_USERDATA:
|
||||
case _RT_USERPOINTER:
|
||||
return _SC("userdata");
|
||||
case _RT_THREAD: return _SC("thread");
|
||||
case _RT_FUNCPROTO: return _SC("function");
|
||||
case _RT_CLASS: return _SC("class");
|
||||
case _RT_INSTANCE: return _SC("instance");
|
||||
case _RT_WEAKREF: return _SC("weakref");
|
||||
return "userdata";
|
||||
case _RT_THREAD: return "thread";
|
||||
case _RT_FUNCPROTO: return "function";
|
||||
case _RT_CLASS: return "class";
|
||||
case _RT_INSTANCE: return "instance";
|
||||
case _RT_WEAKREF: return "weakref";
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
@@ -130,8 +135,8 @@ bool SQDelegable::SetDelegate(SQTable *mt)
|
||||
|
||||
bool SQGenerator::Yield(SQVM *v)
|
||||
{
|
||||
if(_state==eSuspended) { v->Raise_Error(_SC("internal vm error, yielding dead generator")); return false;}
|
||||
if(_state==eDead) { v->Raise_Error(_SC("internal vm error, yielding a dead generator")); return false; }
|
||||
if(_state==eSuspended) { v->Raise_Error("internal vm error, yielding dead generator"); return false;}
|
||||
if(_state==eDead) { v->Raise_Error("internal vm error, yielding a dead generator"); return false; }
|
||||
SQInteger size = v->_top-v->_stackbase;
|
||||
_ci=*v->ci;
|
||||
_stack.resize(size);
|
||||
@@ -156,8 +161,8 @@ bool SQGenerator::Yield(SQVM *v)
|
||||
bool SQGenerator::Resume(SQVM *v,SQInteger target)
|
||||
{
|
||||
SQInteger size=_stack.size();
|
||||
if(_state==eDead){ v->Raise_Error(_SC("resuming dead generator")); return false; }
|
||||
if(_state==eRunning){ v->Raise_Error(_SC("resuming active generator")); return false; }
|
||||
if(_state==eDead){ v->Raise_Error("resuming dead generator"); return false; }
|
||||
if(_state==eRunning){ v->Raise_Error("resuming active generator"); return false; }
|
||||
SQInteger prevtop=v->_top-v->_stackbase;
|
||||
PUSH_CALLINFO(v,_ci);
|
||||
SQInteger oldstackbase=v->_stackbase;
|
||||
@@ -184,7 +189,7 @@ bool SQGenerator::Resume(SQVM *v,SQInteger target)
|
||||
v->ci->_prevstkbase = (SQInt32)(v->_stackbase - oldstackbase);
|
||||
_state=eRunning;
|
||||
if (type(v->_debughook) != OT_NULL && _rawval(v->_debughook) != _rawval(v->ci->_closure))
|
||||
v->CallDebugHook(_SC('c'));
|
||||
v->CallDebugHook('c');
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -232,7 +237,7 @@ SQInteger SQFunctionProto::GetLine(SQInstruction *curr)
|
||||
bool SafeWrite(HSQUIRRELVM v,SQWRITEFUNC write,SQUserPointer up,SQUserPointer dest,SQInteger size)
|
||||
{
|
||||
if(write(up,dest,size) != size) {
|
||||
v->Raise_Error(_SC("io error (write function failure)"));
|
||||
v->Raise_Error("io error (write function failure)");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -241,7 +246,7 @@ bool SafeWrite(HSQUIRRELVM v,SQWRITEFUNC write,SQUserPointer up,SQUserPointer de
|
||||
bool SafeRead(HSQUIRRELVM v,SQWRITEFUNC read,SQUserPointer up,SQUserPointer dest,SQInteger size)
|
||||
{
|
||||
if(size && read(up,dest,size) != size) {
|
||||
v->Raise_Error(_SC("io error, read function failure, the origin stream could be corrupted/trucated"));
|
||||
v->Raise_Error("io error, read function failure, the origin stream could be corrupted/trucated");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -257,7 +262,7 @@ bool CheckTag(HSQUIRRELVM v,SQWRITEFUNC read,SQUserPointer up,SQInteger tag)
|
||||
SQInteger t;
|
||||
_CHECK_IO(SafeRead(v,read,up,&t,sizeof(t)));
|
||||
if(t != tag){
|
||||
v->Raise_Error(_SC("invalid or corrupted closure stream"));
|
||||
v->Raise_Error("invalid or corrupted closure stream");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -269,7 +274,7 @@ bool WriteObject(HSQUIRRELVM v,SQUserPointer up,SQWRITEFUNC write,SQObjectPtr &o
|
||||
switch(type(o)){
|
||||
case OT_STRING:
|
||||
_CHECK_IO(SafeWrite(v,write,up,&_string(o)->_len,sizeof(SQInteger)));
|
||||
_CHECK_IO(SafeWrite(v,write,up,_stringval(o),rsl(_string(o)->_len)));
|
||||
_CHECK_IO(SafeWrite(v,write,up,_stringval(o),_string(o)->_len));
|
||||
break;
|
||||
case OT_INTEGER:
|
||||
_CHECK_IO(SafeWrite(v,write,up,&_integer(o),sizeof(SQInteger)));break;
|
||||
@@ -278,7 +283,7 @@ bool WriteObject(HSQUIRRELVM v,SQUserPointer up,SQWRITEFUNC write,SQObjectPtr &o
|
||||
case OT_NULL:
|
||||
break;
|
||||
default:
|
||||
v->Raise_Error(_SC("cannot serialize a %s"),GetTypeName(o));
|
||||
v->Raise_Error("cannot serialize a %s",GetTypeName(o));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -292,7 +297,7 @@ bool ReadObject(HSQUIRRELVM v,SQUserPointer up,SQREADFUNC read,SQObjectPtr &o)
|
||||
case OT_STRING:{
|
||||
SQInteger len;
|
||||
_CHECK_IO(SafeRead(v,read,up,&len,sizeof(SQInteger)));
|
||||
_CHECK_IO(SafeRead(v,read,up,_ss(v)->GetScratchPad(rsl(len)),rsl(len)));
|
||||
_CHECK_IO(SafeRead(v,read,up,_ss(v)->GetScratchPad(len),len));
|
||||
o=SQString::Create(_ss(v),_ss(v)->GetScratchPad(-1),len);
|
||||
}
|
||||
break;
|
||||
@@ -308,7 +313,7 @@ bool ReadObject(HSQUIRRELVM v,SQUserPointer up,SQREADFUNC read,SQObjectPtr &o)
|
||||
o=_null_;
|
||||
break;
|
||||
default:
|
||||
v->Raise_Error(_SC("cannot serialize a %s"),IdType2Name(t));
|
||||
v->Raise_Error("cannot serialize a %s",IdType2Name(t));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
36
src/3rdparty/squirrel/squirrel/sqobject.h
vendored
36
src/3rdparty/squirrel/squirrel/sqobject.h
vendored
@@ -32,24 +32,24 @@ enum SQMetaMethod{
|
||||
MT_LAST = 18
|
||||
};
|
||||
|
||||
#define MM_ADD _SC("_add")
|
||||
#define MM_SUB _SC("_sub")
|
||||
#define MM_MUL _SC("_mul")
|
||||
#define MM_DIV _SC("_div")
|
||||
#define MM_UNM _SC("_unm")
|
||||
#define MM_MODULO _SC("_modulo")
|
||||
#define MM_SET _SC("_set")
|
||||
#define MM_GET _SC("_get")
|
||||
#define MM_TYPEOF _SC("_typeof")
|
||||
#define MM_NEXTI _SC("_nexti")
|
||||
#define MM_CMP _SC("_cmp")
|
||||
#define MM_CALL _SC("_call")
|
||||
#define MM_CLONED _SC("_cloned")
|
||||
#define MM_NEWSLOT _SC("_newslot")
|
||||
#define MM_DELSLOT _SC("_delslot")
|
||||
#define MM_TOSTRING _SC("_tostring")
|
||||
#define MM_NEWMEMBER _SC("_newmember")
|
||||
#define MM_INHERITED _SC("_inherited")
|
||||
#define MM_ADD "_add"
|
||||
#define MM_SUB "_sub"
|
||||
#define MM_MUL "_mul"
|
||||
#define MM_DIV "_div"
|
||||
#define MM_UNM "_unm"
|
||||
#define MM_MODULO "_modulo"
|
||||
#define MM_SET "_set"
|
||||
#define MM_GET "_get"
|
||||
#define MM_TYPEOF "_typeof"
|
||||
#define MM_NEXTI "_nexti"
|
||||
#define MM_CMP "_cmp"
|
||||
#define MM_CALL "_call"
|
||||
#define MM_CLONED "_cloned"
|
||||
#define MM_NEWSLOT "_newslot"
|
||||
#define MM_DELSLOT "_delslot"
|
||||
#define MM_TOSTRING "_tostring"
|
||||
#define MM_NEWMEMBER "_newmember"
|
||||
#define MM_INHERITED "_inherited"
|
||||
|
||||
#define MINPOWER2 4
|
||||
|
||||
|
3
src/3rdparty/squirrel/squirrel/sqopcodes.h
vendored
3
src/3rdparty/squirrel/squirrel/sqopcodes.h
vendored
@@ -92,8 +92,7 @@ struct SQInstructionDesc {
|
||||
|
||||
struct SQInstruction
|
||||
{
|
||||
SQInstruction(){};
|
||||
SQInstruction(SQOpcode _op,SQInteger a0=0,SQInteger a1=0,SQInteger a2=0,SQInteger a3=0)
|
||||
SQInstruction(SQOpcode _op=_OP_SCOPE_END,SQInteger a0=0,SQInteger a1=0,SQInteger a2=0,SQInteger a3=0)
|
||||
{ op = _op;
|
||||
_arg0 = (unsigned char)a0;_arg1 = (SQInt32)a1;
|
||||
_arg2 = (unsigned char)a2;_arg3 = (unsigned char)a3;
|
||||
|
4
src/3rdparty/squirrel/squirrel/sqpcheader.h
vendored
4
src/3rdparty/squirrel/squirrel/sqpcheader.h
vendored
@@ -6,10 +6,6 @@
|
||||
#include <crtdbg.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <new>
|
||||
//squirrel stuff
|
||||
#include <squirrel.h>
|
||||
|
91
src/3rdparty/squirrel/squirrel/sqstate.cpp
vendored
91
src/3rdparty/squirrel/squirrel/sqstate.cpp
vendored
@@ -1,6 +1,9 @@
|
||||
/*
|
||||
see copyright notice in squirrel.h
|
||||
*/
|
||||
* see copyright notice in squirrel.h
|
||||
*/
|
||||
|
||||
#include "../../../stdafx.h"
|
||||
|
||||
#include "sqpcheader.h"
|
||||
#include "sqopcodes.h"
|
||||
#include "sqvm.h"
|
||||
@@ -12,20 +15,14 @@
|
||||
#include "squserdata.h"
|
||||
#include "sqclass.h"
|
||||
|
||||
#include "../../../safeguards.h"
|
||||
|
||||
SQObjectPtr _null_;
|
||||
SQObjectPtr _true_(true);
|
||||
SQObjectPtr _false_(false);
|
||||
SQObjectPtr _one_((SQInteger)1);
|
||||
SQObjectPtr _minusone_((SQInteger)-1);
|
||||
|
||||
SQSharedState::SQSharedState()
|
||||
{
|
||||
_compilererrorhandler = NULL;
|
||||
_printfunc = NULL;
|
||||
_debuginfo = false;
|
||||
_notifyallexceptions = false;
|
||||
}
|
||||
|
||||
#define newsysstring(s) { \
|
||||
_systemstrings->push_back(SQString::Create(this,s)); \
|
||||
}
|
||||
@@ -94,8 +91,12 @@ SQTable *CreateDefaultDelegate(SQSharedState *ss,SQRegFunction *funcz)
|
||||
return t;
|
||||
}
|
||||
|
||||
void SQSharedState::Init()
|
||||
SQSharedState::SQSharedState()
|
||||
{
|
||||
_compilererrorhandler = NULL;
|
||||
_printfunc = NULL;
|
||||
_debuginfo = false;
|
||||
_notifyallexceptions = false;
|
||||
_scratchpad=NULL;
|
||||
_scratchpadsize=0;
|
||||
#ifndef NO_GARBAGE_COLLECTOR
|
||||
@@ -108,21 +109,21 @@ void SQSharedState::Init()
|
||||
_metamethodsmap = SQTable::Create(this,MT_LAST-1);
|
||||
//adding type strings to avoid memory trashing
|
||||
//types names
|
||||
newsysstring(_SC("null"));
|
||||
newsysstring(_SC("table"));
|
||||
newsysstring(_SC("array"));
|
||||
newsysstring(_SC("closure"));
|
||||
newsysstring(_SC("string"));
|
||||
newsysstring(_SC("userdata"));
|
||||
newsysstring(_SC("integer"));
|
||||
newsysstring(_SC("float"));
|
||||
newsysstring(_SC("userpointer"));
|
||||
newsysstring(_SC("function"));
|
||||
newsysstring(_SC("generator"));
|
||||
newsysstring(_SC("thread"));
|
||||
newsysstring(_SC("class"));
|
||||
newsysstring(_SC("instance"));
|
||||
newsysstring(_SC("bool"));
|
||||
newsysstring("null");
|
||||
newsysstring("table");
|
||||
newsysstring("array");
|
||||
newsysstring("closure");
|
||||
newsysstring("string");
|
||||
newsysstring("userdata");
|
||||
newsysstring("integer");
|
||||
newsysstring("float");
|
||||
newsysstring("userpointer");
|
||||
newsysstring("function");
|
||||
newsysstring("generator");
|
||||
newsysstring("thread");
|
||||
newsysstring("class");
|
||||
newsysstring("instance");
|
||||
newsysstring("bool");
|
||||
//meta methods
|
||||
newmetamethod(MM_ADD);
|
||||
newmetamethod(MM_SUB);
|
||||
@@ -143,7 +144,7 @@ void SQSharedState::Init()
|
||||
newmetamethod(MM_NEWMEMBER);
|
||||
newmetamethod(MM_INHERITED);
|
||||
|
||||
_constructoridx = SQString::Create(this,_SC("constructor"));
|
||||
_constructoridx = SQString::Create(this,"constructor");
|
||||
_registry = SQTable::Create(this,0);
|
||||
_consts = SQTable::Create(this,0);
|
||||
_table_default_delegate = CreateDefaultDelegate(this,_table_default_delegate_funcz);
|
||||
@@ -486,10 +487,10 @@ void RefTable::AllocNodes(SQUnsignedInteger size)
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//SQStringTable
|
||||
/*
|
||||
* The following code is based on Lua 4.0 (Copyright 1994-2002 Tecgraf, PUC-Rio.)
|
||||
* http://www.lua.org/copyright.html#4
|
||||
* http://www.lua.org/source/4.0.1/src_lstring.c.html
|
||||
*/
|
||||
* The following code is based on Lua 4.0 (Copyright 1994-2002 Tecgraf, PUC-Rio.)
|
||||
* http://www.lua.org/copyright.html#4
|
||||
* http://www.lua.org/source/4.0.1/src_lstring.c.html
|
||||
*/
|
||||
|
||||
SQStringTable::SQStringTable()
|
||||
{
|
||||
@@ -507,26 +508,22 @@ void SQStringTable::AllocNodes(SQInteger size)
|
||||
{
|
||||
_numofslots = size;
|
||||
_strings = (SQString**)SQ_MALLOC(sizeof(SQString*)*_numofslots);
|
||||
memset(_strings,0,sizeof(SQString*)*_numofslots);
|
||||
memset(_strings,0,sizeof(SQString*)*(size_t)_numofslots);
|
||||
}
|
||||
|
||||
SQString *SQStringTable::Add(const SQChar *news,SQInteger len)
|
||||
{
|
||||
if(len<0)
|
||||
len = (SQInteger)scstrlen(news);
|
||||
SQHash h = ::_hashstr(news,len)&(_numofslots-1);
|
||||
len = (SQInteger)strlen(news);
|
||||
SQHash h = ::_hashstr(news,(size_t)len)&(_numofslots-1);
|
||||
SQString *s;
|
||||
for (s = _strings[h]; s; s = s->_next){
|
||||
if(s->_len == len && (!memcmp(news,s->_val,rsl(len))))
|
||||
if(s->_len == len && (!memcmp(news,s->_val,(size_t)len)))
|
||||
return s; //found
|
||||
}
|
||||
|
||||
SQString *t=(SQString *)SQ_MALLOC(rsl(len)+sizeof(SQString));
|
||||
new (t) SQString;
|
||||
memcpy(t->_val,news,rsl(len));
|
||||
t->_val[len] = _SC('\0');
|
||||
t->_len = len;
|
||||
t->_hash = ::_hashstr(news,len);
|
||||
SQString *t=(SQString *)SQ_MALLOC(len+sizeof(SQString));
|
||||
new (t) SQString(news, len);
|
||||
t->_next = _strings[h];
|
||||
_strings[h] = t;
|
||||
_slotused++;
|
||||
@@ -535,6 +532,16 @@ SQString *SQStringTable::Add(const SQChar *news,SQInteger len)
|
||||
return t;
|
||||
}
|
||||
|
||||
SQString::SQString(const SQChar *news, SQInteger len)
|
||||
{
|
||||
memcpy(_val,news,(size_t)len);
|
||||
_val[len] = '\0';
|
||||
_len = len;
|
||||
_hash = ::_hashstr(news,(size_t)len);
|
||||
_next = NULL;
|
||||
_sharedstate = NULL;
|
||||
}
|
||||
|
||||
void SQStringTable::Resize(SQInteger size)
|
||||
{
|
||||
SQInteger oldsize=_numofslots;
|
||||
@@ -568,7 +575,7 @@ void SQStringTable::Remove(SQString *bs)
|
||||
_slotused--;
|
||||
SQInteger slen = s->_len;
|
||||
s->~SQString();
|
||||
SQ_FREE(s,sizeof(SQString) + rsl(slen));
|
||||
SQ_FREE(s,sizeof(SQString) + slen);
|
||||
return;
|
||||
}
|
||||
prev = s;
|
||||
|
7
src/3rdparty/squirrel/squirrel/sqstate.h
vendored
7
src/3rdparty/squirrel/squirrel/sqstate.h
vendored
@@ -58,7 +58,6 @@ struct SQSharedState
|
||||
{
|
||||
SQSharedState();
|
||||
~SQSharedState();
|
||||
void Init();
|
||||
public:
|
||||
SQChar* GetScratchPad(SQInteger size);
|
||||
SQInteger GetMetaMethodIdxByName(const SQObjectPtr &name);
|
||||
@@ -123,12 +122,6 @@ private:
|
||||
#define _instance_ddel _table(_sharedstate->_instance_default_delegate)
|
||||
#define _weakref_ddel _table(_sharedstate->_weakref_default_delegate)
|
||||
|
||||
#ifdef SQUNICODE //rsl REAL STRING LEN
|
||||
#define rsl(l) ((l)<<1)
|
||||
#else
|
||||
#define rsl(l) (l)
|
||||
#endif
|
||||
|
||||
extern SQObjectPtr _null_;
|
||||
extern SQObjectPtr _true_;
|
||||
extern SQObjectPtr _false_;
|
||||
|
2
src/3rdparty/squirrel/squirrel/sqstring.h
vendored
2
src/3rdparty/squirrel/squirrel/sqstring.h
vendored
@@ -13,7 +13,7 @@ inline SQHash _hashstr (const SQChar *s, size_t l)
|
||||
|
||||
struct SQString : public SQRefCounted
|
||||
{
|
||||
SQString(){}
|
||||
SQString(const SQChar *news, SQInteger len);
|
||||
~SQString(){}
|
||||
public:
|
||||
static SQString *Create(SQSharedState *ss, const SQChar *, SQInteger len = -1 );
|
||||
|
9
src/3rdparty/squirrel/squirrel/sqtable.cpp
vendored
9
src/3rdparty/squirrel/squirrel/sqtable.cpp
vendored
@@ -1,12 +1,17 @@
|
||||
/*
|
||||
see copyright notice in squirrel.h
|
||||
*/
|
||||
* see copyright notice in squirrel.h
|
||||
*/
|
||||
|
||||
#include "../../../stdafx.h"
|
||||
|
||||
#include "sqpcheader.h"
|
||||
#include "sqvm.h"
|
||||
#include "sqtable.h"
|
||||
#include "sqfuncproto.h"
|
||||
#include "sqclosure.h"
|
||||
|
||||
#include "../../../safeguards.h"
|
||||
|
||||
SQTable::SQTable(SQSharedState *ss,SQInteger nInitialSize)
|
||||
{
|
||||
SQInteger pow2size=MINPOWER2;
|
||||
|
8
src/3rdparty/squirrel/squirrel/sqtable.h
vendored
8
src/3rdparty/squirrel/squirrel/sqtable.h
vendored
@@ -2,10 +2,10 @@
|
||||
#ifndef _SQTABLE_H_
|
||||
#define _SQTABLE_H_
|
||||
/*
|
||||
* The following code is based on Lua 4.0 (Copyright 1994-2002 Tecgraf, PUC-Rio.)
|
||||
* http://www.lua.org/copyright.html#4
|
||||
* http://www.lua.org/source/4.0.1/src_ltable.c.html
|
||||
*/
|
||||
* The following code is based on Lua 4.0 (Copyright 1994-2002 Tecgraf, PUC-Rio.)
|
||||
* http://www.lua.org/copyright.html#4
|
||||
* http://www.lua.org/source/4.0.1/src_ltable.c.html
|
||||
*/
|
||||
|
||||
#include "sqstring.h"
|
||||
|
||||
|
302
src/3rdparty/squirrel/squirrel/squirrel.dsp
vendored
302
src/3rdparty/squirrel/squirrel/squirrel.dsp
vendored
@@ -1,302 +0,0 @@
|
||||
# Microsoft Developer Studio Project File - Name="squirrel" - Package Owner=<4>
|
||||
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||
# ** DO NOT EDIT **
|
||||
|
||||
# TARGTYPE "Win32 (x86) Static Library" 0x0104
|
||||
|
||||
CFG=squirrel - Win32 Debug
|
||||
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||
!MESSAGE use the Export Makefile command and run
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "squirrel.mak".
|
||||
!MESSAGE
|
||||
!MESSAGE You can specify a configuration when running NMAKE
|
||||
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "squirrel.mak" CFG="squirrel - Win32 Debug"
|
||||
!MESSAGE
|
||||
!MESSAGE Possible choices for configuration are:
|
||||
!MESSAGE
|
||||
!MESSAGE "squirrel - Win32 Release" (based on "Win32 (x86) Static Library")
|
||||
!MESSAGE "squirrel - Win32 Debug" (based on "Win32 (x86) Static Library")
|
||||
!MESSAGE
|
||||
|
||||
# Begin Project
|
||||
# PROP AllowPerConfigDependencies 0
|
||||
# PROP Scc_LocalPath ".."
|
||||
CPP=cl.exe
|
||||
RSC=rc.exe
|
||||
|
||||
!IF "$(CFG)" == "squirrel - Win32 Release"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "Release"
|
||||
# PROP BASE Intermediate_Dir "Release"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "Release"
|
||||
# PROP Intermediate_Dir "Release"
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c
|
||||
# ADD CPP /nologo /W3 /GX /O2 /I "..\include" /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /D "GARBAGE_COLLECTOR" /YX /FD /c
|
||||
# ADD BASE RSC /l 0x410 /d "NDEBUG"
|
||||
# ADD RSC /l 0x410 /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LIB32=link.exe -lib
|
||||
# ADD BASE LIB32 /nologo
|
||||
# ADD LIB32 /nologo /out:"..\lib\squirrel.lib"
|
||||
|
||||
!ELSEIF "$(CFG)" == "squirrel - Win32 Debug"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 1
|
||||
# PROP BASE Output_Dir "Debug"
|
||||
# PROP BASE Intermediate_Dir "Debug"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 1
|
||||
# PROP Output_Dir "Debug"
|
||||
# PROP Intermediate_Dir "Debug"
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c
|
||||
# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I "..\include" /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /D "GARBAGE_COLLECTOR" /YX /FD /GZ /c
|
||||
# ADD BASE RSC /l 0x410 /d "_DEBUG"
|
||||
# ADD RSC /l 0x410 /d "_DEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LIB32=link.exe -lib
|
||||
# ADD BASE LIB32 /nologo
|
||||
# ADD LIB32 /nologo /out:"..\lib\squirrel.lib"
|
||||
|
||||
!ENDIF
|
||||
|
||||
# Begin Target
|
||||
|
||||
# Name "squirrel - Win32 Release"
|
||||
# Name "squirrel - Win32 Debug"
|
||||
# Begin Group "Source Files"
|
||||
|
||||
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\sqapi.cpp
|
||||
|
||||
!IF "$(CFG)" == "squirrel - Win32 Release"
|
||||
|
||||
!ELSEIF "$(CFG)" == "squirrel - Win32 Debug"
|
||||
|
||||
# ADD CPP /YX"stdafx.h"
|
||||
|
||||
!ENDIF
|
||||
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\sqbaselib.cpp
|
||||
|
||||
!IF "$(CFG)" == "squirrel - Win32 Release"
|
||||
|
||||
!ELSEIF "$(CFG)" == "squirrel - Win32 Debug"
|
||||
|
||||
# ADD CPP /YX"stdafx.h"
|
||||
|
||||
!ENDIF
|
||||
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\sqcompiler.cpp
|
||||
|
||||
!IF "$(CFG)" == "squirrel - Win32 Release"
|
||||
|
||||
!ELSEIF "$(CFG)" == "squirrel - Win32 Debug"
|
||||
|
||||
# ADD CPP /YX"stdafx.h"
|
||||
|
||||
!ENDIF
|
||||
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\sqdebug.cpp
|
||||
|
||||
!IF "$(CFG)" == "squirrel - Win32 Release"
|
||||
|
||||
!ELSEIF "$(CFG)" == "squirrel - Win32 Debug"
|
||||
|
||||
# ADD CPP /YX"stdafx.h"
|
||||
|
||||
!ENDIF
|
||||
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\sqfuncstate.cpp
|
||||
|
||||
!IF "$(CFG)" == "squirrel - Win32 Release"
|
||||
|
||||
!ELSEIF "$(CFG)" == "squirrel - Win32 Debug"
|
||||
|
||||
# ADD CPP /YX"stdafx.h"
|
||||
|
||||
!ENDIF
|
||||
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\sqlexer.cpp
|
||||
|
||||
!IF "$(CFG)" == "squirrel - Win32 Release"
|
||||
|
||||
!ELSEIF "$(CFG)" == "squirrel - Win32 Debug"
|
||||
|
||||
# ADD CPP /YX"stdafx.h"
|
||||
|
||||
!ENDIF
|
||||
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\sqmem.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\sqobject.cpp
|
||||
|
||||
!IF "$(CFG)" == "squirrel - Win32 Release"
|
||||
|
||||
!ELSEIF "$(CFG)" == "squirrel - Win32 Debug"
|
||||
|
||||
# ADD CPP /YX"stdafx.h"
|
||||
|
||||
!ENDIF
|
||||
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\sqstate.cpp
|
||||
|
||||
!IF "$(CFG)" == "squirrel - Win32 Release"
|
||||
|
||||
!ELSEIF "$(CFG)" == "squirrel - Win32 Debug"
|
||||
|
||||
# ADD CPP /YX"stdafx.h"
|
||||
|
||||
!ENDIF
|
||||
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\sqtable.cpp
|
||||
|
||||
!IF "$(CFG)" == "squirrel - Win32 Release"
|
||||
|
||||
!ELSEIF "$(CFG)" == "squirrel - Win32 Debug"
|
||||
|
||||
# ADD CPP /YX"stdafx.h"
|
||||
|
||||
!ENDIF
|
||||
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\sqclass.cpp
|
||||
|
||||
!IF "$(CFG)" == "squirrel - Win32 Release"
|
||||
|
||||
!ELSEIF "$(CFG)" == "squirrel - Win32 Debug"
|
||||
|
||||
# ADD CPP /YX"stdafx.h"
|
||||
|
||||
!ENDIF
|
||||
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\sqvm.cpp
|
||||
|
||||
!IF "$(CFG)" == "squirrel - Win32 Release"
|
||||
|
||||
!ELSEIF "$(CFG)" == "squirrel - Win32 Debug"
|
||||
|
||||
# ADD CPP /YX"stdafx.h"
|
||||
|
||||
!ENDIF
|
||||
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Header Files"
|
||||
|
||||
# PROP Default_Filter "h;hpp;hxx;hm;inl"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\sqarray.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\sqclosure.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\sqcompiler.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\sqfuncproto.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\sqfuncstate.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\sqlexer.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\sqobject.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\sqopcodes.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\sqpcheader.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\sqstate.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\sqstring.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\sqtable.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\squserdata.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\squtils.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\sqclass.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\sqvm.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# End Target
|
||||
# End Project
|
7
src/3rdparty/squirrel/squirrel/squserdata.h
vendored
7
src/3rdparty/squirrel/squirrel/squserdata.h
vendored
@@ -4,7 +4,8 @@
|
||||
|
||||
struct SQUserData : SQDelegable
|
||||
{
|
||||
SQUserData(SQSharedState *ss){ _delegate = 0; _hook = NULL; INIT_CHAIN(); ADD_TO_CHAIN(&_ss(this)->_gc_chain, this); }
|
||||
SQUserData(SQSharedState *ss, SQInteger size){ _delegate = 0; _hook = NULL; INIT_CHAIN(); ADD_TO_CHAIN(&_ss(this)->_gc_chain, this); _size = size; _typetag = 0;
|
||||
}
|
||||
~SQUserData()
|
||||
{
|
||||
REMOVE_FROM_CHAIN(&_ss(this)->_gc_chain, this);
|
||||
@@ -13,9 +14,7 @@ struct SQUserData : SQDelegable
|
||||
static SQUserData* Create(SQSharedState *ss, SQInteger size)
|
||||
{
|
||||
SQUserData* ud = (SQUserData*)SQ_MALLOC(sizeof(SQUserData)+(size-1));
|
||||
new (ud) SQUserData(ss);
|
||||
ud->_size = size;
|
||||
ud->_typetag = 0;
|
||||
new (ud) SQUserData(ss, size);
|
||||
return ud;
|
||||
}
|
||||
#ifndef NO_GARBAGE_COLLECTOR
|
||||
|
18
src/3rdparty/squirrel/squirrel/squtils.h
vendored
18
src/3rdparty/squirrel/squirrel/squtils.h
vendored
@@ -37,9 +37,13 @@ public:
|
||||
~sqvector()
|
||||
{
|
||||
if(_allocated) {
|
||||
for(SQUnsignedInteger i = 0; i < _size; i++)
|
||||
/* Break freeing loops, if this vector (indirectly) links to itself. */
|
||||
size_t allocated_size = _allocated * sizeof(T);
|
||||
_allocated = 0;
|
||||
|
||||
for(size_t i = 0; i < _size; i++)
|
||||
_vals[i].~T();
|
||||
SQ_FREE(_vals, (_allocated * sizeof(T)));
|
||||
SQ_FREE(_vals, allocated_size);
|
||||
}
|
||||
}
|
||||
void reserve(SQUnsignedInteger newsize) { _realloc(newsize); }
|
||||
@@ -57,7 +61,7 @@ public:
|
||||
for(SQUnsignedInteger i = newsize; i < _size; i++) {
|
||||
_vals[i].~T();
|
||||
}
|
||||
_size = newsize;
|
||||
_size = (size_t)newsize;
|
||||
}
|
||||
}
|
||||
void shrinktofit() { if(_size > 4) { _realloc(_size); } }
|
||||
@@ -86,7 +90,7 @@ public:
|
||||
{
|
||||
_vals[idx].~T();
|
||||
if(idx < (_size - 1)) {
|
||||
memmove(&_vals[idx], &_vals[idx+1], sizeof(T) * (_size - idx - 1));
|
||||
memmove(&_vals[idx], &_vals[idx+1], sizeof(T) * (_size - (size_t)idx - 1));
|
||||
}
|
||||
_size--;
|
||||
}
|
||||
@@ -99,10 +103,10 @@ private:
|
||||
{
|
||||
newsize = (newsize > 0)?newsize:4;
|
||||
_vals = (T*)SQ_REALLOC(_vals, _allocated * sizeof(T), newsize * sizeof(T));
|
||||
_allocated = newsize;
|
||||
_allocated = (size_t)newsize;
|
||||
}
|
||||
SQUnsignedInteger _size;
|
||||
SQUnsignedInteger _allocated;
|
||||
size_t _size;
|
||||
size_t _allocated;
|
||||
};
|
||||
|
||||
#endif //_SQUTILS_H_
|
||||
|
193
src/3rdparty/squirrel/squirrel/sqvm.cpp
vendored
193
src/3rdparty/squirrel/squirrel/sqvm.cpp
vendored
@@ -1,10 +1,12 @@
|
||||
/*
|
||||
see copyright notice in squirrel.h
|
||||
*/
|
||||
* see copyright notice in squirrel.h
|
||||
*/
|
||||
|
||||
#include "../../../stdafx.h"
|
||||
|
||||
#include <squirrel.h>
|
||||
#include "sqpcheader.h"
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
#include "sqopcodes.h"
|
||||
#include "sqfuncproto.h"
|
||||
#include "sqvm.h"
|
||||
@@ -15,6 +17,10 @@
|
||||
#include "sqarray.h"
|
||||
#include "sqclass.h"
|
||||
|
||||
#include "../../../string_func.h"
|
||||
|
||||
#include "../../../safeguards.h"
|
||||
|
||||
#define TOP() (_stack._vals[_top-1])
|
||||
|
||||
#define CLEARSTACK(_last_top) { if((_last_top) >= _top) ClearStack(_last_top); }
|
||||
@@ -45,10 +51,10 @@ bool SQVM::BW_OP(SQUnsignedInteger op,SQObjectPtr &trg,const SQObjectPtr &o1,con
|
||||
case BW_SHIFTL: res = i1 << i2; break;
|
||||
case BW_SHIFTR: res = i1 >> i2; break;
|
||||
case BW_USHIFTR:res = (SQInteger)(*((SQUnsignedInteger*)&i1) >> i2); break;
|
||||
default: { Raise_Error(_SC("internal vm error bitwise op failed")); return false; }
|
||||
default: { Raise_Error("internal vm error bitwise op failed"); return false; }
|
||||
}
|
||||
}
|
||||
else { Raise_Error(_SC("bitwise op between '%s' and '%s'"),GetTypeName(o1),GetTypeName(o2)); return false;}
|
||||
else { Raise_Error("bitwise op between '%s' and '%s'",GetTypeName(o1),GetTypeName(o2)); return false;}
|
||||
trg = res;
|
||||
return true;
|
||||
}
|
||||
@@ -61,11 +67,11 @@ bool SQVM::ARITH_OP(SQUnsignedInteger op,SQObjectPtr &trg,const SQObjectPtr &o1,
|
||||
switch(op) {
|
||||
case '+': res = i1 + i2; break;
|
||||
case '-': res = i1 - i2; break;
|
||||
case '/': if(i2 == 0) { Raise_Error(_SC("division by zero")); return false; }
|
||||
case '/': if(i2 == 0) { Raise_Error("division by zero"); return false; }
|
||||
res = i1 / i2;
|
||||
break;
|
||||
case '*': res = i1 * i2; break;
|
||||
case '%': if(i2 == 0) { Raise_Error(_SC("modulo by zero")); return false; }
|
||||
case '%': if(i2 == 0) { Raise_Error("modulo by zero"); return false; }
|
||||
res = i1 % i2;
|
||||
break;
|
||||
default: res = 0xDEADBEEF;
|
||||
@@ -88,7 +94,7 @@ bool SQVM::ARITH_OP(SQUnsignedInteger op,SQObjectPtr &trg,const SQObjectPtr &o1,
|
||||
if(!StringCat(o1, o2, trg)) return false;
|
||||
}
|
||||
else if(!ArithMetaMethod(op,o1,o2,trg)) {
|
||||
Raise_Error(_SC("arith op %c on between '%s' and '%s'"),op,GetTypeName(o1),GetTypeName(o2)); return false;
|
||||
Raise_Error("arith op %c on between '%s' and '%s'",op,GetTypeName(o1),GetTypeName(o2)); return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
@@ -107,7 +113,13 @@ SQVM::SQVM(SQSharedState *ss)
|
||||
_errorhandler = _null_;
|
||||
_debughook = _null_;
|
||||
_can_suspend = false;
|
||||
_in_stackoverflow = false;
|
||||
_ops_till_suspend = 0;
|
||||
_callsstack = NULL;
|
||||
_callsstacksize = 0;
|
||||
_alloccallsstacksize = 0;
|
||||
_top = 0;
|
||||
_stackbase = 0;
|
||||
ci = NULL;
|
||||
INIT_CHAIN();ADD_TO_CHAIN(&_ss(this)->_gc_chain,this);
|
||||
}
|
||||
@@ -136,11 +148,11 @@ bool SQVM::ArithMetaMethod(SQInteger op,const SQObjectPtr &o1,const SQObjectPtr
|
||||
{
|
||||
SQMetaMethod mm;
|
||||
switch(op){
|
||||
case _SC('+'): mm=MT_ADD; break;
|
||||
case _SC('-'): mm=MT_SUB; break;
|
||||
case _SC('/'): mm=MT_DIV; break;
|
||||
case _SC('*'): mm=MT_MUL; break;
|
||||
case _SC('%'): mm=MT_MODULO; break;
|
||||
case '+': mm=MT_ADD; break;
|
||||
case '-': mm=MT_SUB; break;
|
||||
case '/': mm=MT_DIV; break;
|
||||
case '*': mm=MT_MUL; break;
|
||||
case '%': mm=MT_MODULO; break;
|
||||
default: mm = MT_ADD; assert(0); break; //shutup compiler
|
||||
}
|
||||
if(is_delegable(o1) && _delegable(o1)->_delegate) {
|
||||
@@ -172,7 +184,7 @@ bool SQVM::NEG_OP(SQObjectPtr &trg,const SQObjectPtr &o)
|
||||
}
|
||||
default:break; //shutup compiler
|
||||
}
|
||||
Raise_Error(_SC("attempt to negate a %s"), GetTypeName(o));
|
||||
Raise_Error("attempt to negate a %s", GetTypeName(o));
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -184,7 +196,7 @@ bool SQVM::ObjCmp(const SQObjectPtr &o1,const SQObjectPtr &o2,SQInteger &result)
|
||||
SQObjectPtr res;
|
||||
switch(type(o1)){
|
||||
case OT_STRING:
|
||||
_RET_SUCCEED(scstrcmp(_stringval(o1),_stringval(o2)));
|
||||
_RET_SUCCEED(strcmp(_stringval(o1),_stringval(o2)));
|
||||
case OT_INTEGER:
|
||||
/* FS#3954: wrong integer comparison */
|
||||
_RET_SUCCEED((_integer(o1)<_integer(o2))?-1:(_integer(o1)==_integer(o2))?0:1);
|
||||
@@ -197,7 +209,7 @@ bool SQVM::ObjCmp(const SQObjectPtr &o1,const SQObjectPtr &o2,SQInteger &result)
|
||||
Push(o1);Push(o2);
|
||||
if(CallMetaMethod(_delegable(o1),MT_CMP,2,res)) {
|
||||
if(type(res) != OT_INTEGER) {
|
||||
Raise_Error(_SC("_cmp must return an integer"));
|
||||
Raise_Error("_cmp must return an integer");
|
||||
return false;
|
||||
}
|
||||
_RET_SUCCEED(_integer(res))
|
||||
@@ -250,22 +262,19 @@ bool SQVM::CMP_OP(CmpOP op, const SQObjectPtr &o1,const SQObjectPtr &o2,SQObject
|
||||
|
||||
void SQVM::ToString(const SQObjectPtr &o,SQObjectPtr &res)
|
||||
{
|
||||
char buf[64];
|
||||
switch(type(o)) {
|
||||
case OT_STRING:
|
||||
res = o;
|
||||
return;
|
||||
case OT_FLOAT:
|
||||
scsprintf(_sp(rsl(NUMBER_MAX_CHAR+1)),_SC("%g"),_float(o));
|
||||
seprintf(buf, lastof(buf),"%g",_float(o));
|
||||
break;
|
||||
case OT_INTEGER:
|
||||
#if defined(_SQ64)
|
||||
scsprintf(_sp(rsl(NUMBER_MAX_CHAR+1)),_SC("%ld"),_integer(o));
|
||||
#else
|
||||
scsprintf(_sp(rsl(NUMBER_MAX_CHAR+1)),_SC("%d"),_integer(o));
|
||||
#endif
|
||||
seprintf(buf, lastof(buf),OTTD_PRINTF64,_integer(o));
|
||||
break;
|
||||
case OT_BOOL:
|
||||
scsprintf(_sp(rsl(6)),_integer(o)?_SC("true"):_SC("false"));
|
||||
seprintf(buf, lastof(buf),_integer(o)?"true":"false");
|
||||
break;
|
||||
case OT_TABLE:
|
||||
case OT_USERDATA:
|
||||
@@ -279,9 +288,9 @@ void SQVM::ToString(const SQObjectPtr &o,SQObjectPtr &res)
|
||||
}
|
||||
}
|
||||
default:
|
||||
scsprintf(_sp(rsl(sizeof(void*)+20)),_SC("(%s : 0x%p)"),GetTypeName(o),(void*)_rawval(o));
|
||||
seprintf(buf, lastof(buf),"(%s : 0x%p)",GetTypeName(o),(void*)_rawval(o));
|
||||
}
|
||||
res = SQString::Create(_ss(this),_spval);
|
||||
res = SQString::Create(_ss(this),buf);
|
||||
}
|
||||
|
||||
|
||||
@@ -291,9 +300,9 @@ bool SQVM::StringCat(const SQObjectPtr &str,const SQObjectPtr &obj,SQObjectPtr &
|
||||
ToString(str, a);
|
||||
ToString(obj, b);
|
||||
SQInteger l = _string(a)->_len , ol = _string(b)->_len;
|
||||
SQChar *s = _sp(rsl(l + ol + 1));
|
||||
memcpy(s, _stringval(a), rsl(l));
|
||||
memcpy(s + l, _stringval(b), rsl(ol));
|
||||
SQChar *s = _sp(l + ol + 1);
|
||||
memcpy(s, _stringval(a), (size_t)l);
|
||||
memcpy(s + l, _stringval(b), (size_t)ol);
|
||||
dest = SQString::Create(_ss(this), _spval, l + ol);
|
||||
return true;
|
||||
}
|
||||
@@ -349,7 +358,7 @@ bool SQVM::StartCall(SQClosure *closure,SQInteger target,SQInteger args,SQIntege
|
||||
else if(func->_varparams)
|
||||
{
|
||||
if (nargs < paramssize) {
|
||||
Raise_Error(_SC("wrong number of parameters"));
|
||||
Raise_Error("wrong number of parameters");
|
||||
return false;
|
||||
}
|
||||
for(SQInteger n = 0; n < nargs - paramssize; n++) {
|
||||
@@ -358,7 +367,7 @@ bool SQVM::StartCall(SQClosure *closure,SQInteger target,SQInteger args,SQIntege
|
||||
}
|
||||
}
|
||||
else {
|
||||
Raise_Error(_SC("wrong number of parameters"));
|
||||
Raise_Error("wrong number of parameters");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -395,7 +404,7 @@ bool SQVM::StartCall(SQClosure *closure,SQInteger target,SQInteger args,SQIntege
|
||||
_top = newtop;
|
||||
_stackbase = stackbase;
|
||||
if (type(_debughook) != OT_NULL && _rawval(_debughook) != _rawval(ci->_closure))
|
||||
CallDebugHook(_SC('c'));
|
||||
CallDebugHook('c');
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -403,7 +412,7 @@ bool SQVM::Return(SQInteger _arg0, SQInteger _arg1, SQObjectPtr &retval)
|
||||
{
|
||||
if (type(_debughook) != OT_NULL && _rawval(_debughook) != _rawval(ci->_closure))
|
||||
for(SQInteger i=0;i<ci->_ncalls;i++)
|
||||
CallDebugHook(_SC('r'));
|
||||
CallDebugHook('r');
|
||||
|
||||
SQBool broot = ci->_root;
|
||||
SQInteger last_top = _top;
|
||||
@@ -469,9 +478,9 @@ bool SQVM::DerefInc(SQInteger op,SQObjectPtr &target, SQObjectPtr &self, SQObjec
|
||||
SQRESULT SQVM::Suspend()
|
||||
{
|
||||
if (_suspended)
|
||||
return sq_throwerror(this, _SC("cannot suspend an already suspended vm"));
|
||||
return sq_throwerror(this, "cannot suspend an already suspended vm");
|
||||
if (_nnativecalls!=2)
|
||||
return sq_throwerror(this, _SC("cannot suspend through native calls/metamethods"));
|
||||
return sq_throwerror(this, "cannot suspend through native calls/metamethods");
|
||||
return SQ_SUSPEND_FLAG;
|
||||
}
|
||||
|
||||
@@ -509,12 +518,12 @@ bool SQVM::FOREACH_OP(SQObjectPtr &o1,SQObjectPtr &o2,SQObjectPtr
|
||||
o4 = o2 = itr;
|
||||
if(type(itr) == OT_NULL) _FINISH(exitpos);
|
||||
if(!Get(o1, itr, o3, false,false)) {
|
||||
Raise_Error(_SC("_nexti returned an invalid idx"));
|
||||
Raise_Error("_nexti returned an invalid idx");
|
||||
return false;
|
||||
}
|
||||
_FINISH(1);
|
||||
}
|
||||
Raise_Error(_SC("_nexti failed"));
|
||||
Raise_Error("_nexti failed");
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
@@ -530,19 +539,20 @@ bool SQVM::FOREACH_OP(SQObjectPtr &o1,SQObjectPtr &o2,SQObjectPtr
|
||||
_generator(o1)->Resume(this, arg_2+1);
|
||||
_FINISH(0);
|
||||
}
|
||||
/* FALL THROUGH */
|
||||
default:
|
||||
Raise_Error(_SC("cannot iterate %s"), GetTypeName(o1));
|
||||
Raise_Error("cannot iterate %s", GetTypeName(o1));
|
||||
}
|
||||
return false; //cannot be hit(just to avoid warnings)
|
||||
}
|
||||
|
||||
bool SQVM::DELEGATE_OP(SQObjectPtr &trg,SQObjectPtr &o1,SQObjectPtr &o2)
|
||||
{
|
||||
if(type(o1) != OT_TABLE) { Raise_Error(_SC("delegating a '%s'"), GetTypeName(o1)); return false; }
|
||||
if(type(o1) != OT_TABLE) { Raise_Error("delegating a '%s'", GetTypeName(o1)); return false; }
|
||||
switch(type(o2)) {
|
||||
case OT_TABLE:
|
||||
if(!_table(o1)->SetDelegate(_table(o2))){
|
||||
Raise_Error(_SC("delegate cycle detected"));
|
||||
Raise_Error("delegate cycle detected");
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
@@ -550,7 +560,7 @@ bool SQVM::DELEGATE_OP(SQObjectPtr &trg,SQObjectPtr &o1,SQObjectPtr &o2)
|
||||
_table(o1)->SetDelegate(NULL);
|
||||
break;
|
||||
default:
|
||||
Raise_Error(_SC("using '%s' as delegate"), GetTypeName(o2));
|
||||
Raise_Error("using '%s' as delegate", GetTypeName(o2));
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
@@ -602,15 +612,15 @@ bool SQVM::CLOSURE_OP(SQObjectPtr &target, SQFunctionProto *func)
|
||||
bool SQVM::GETVARGV_OP(SQObjectPtr &target,SQObjectPtr &index,CallInfo *ci)
|
||||
{
|
||||
if(ci->_vargs.size == 0) {
|
||||
Raise_Error(_SC("the function doesn't have var args"));
|
||||
Raise_Error("the function doesn't have var args");
|
||||
return false;
|
||||
}
|
||||
if(!sq_isnumeric(index)){
|
||||
Raise_Error(_SC("indexing 'vargv' with %s"),GetTypeName(index));
|
||||
Raise_Error("indexing 'vargv' with %s",GetTypeName(index));
|
||||
return false;
|
||||
}
|
||||
SQInteger idx = tointeger(index);
|
||||
if(idx < 0 || idx >= ci->_vargs.size){ Raise_Error(_SC("vargv index out of range")); return false; }
|
||||
if(idx < 0 || idx >= ci->_vargs.size){ Raise_Error("vargv index out of range"); return false; }
|
||||
target = _vargsstack[ci->_vargs.base+idx];
|
||||
return true;
|
||||
}
|
||||
@@ -620,7 +630,7 @@ 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(type(_stack._vals[_stackbase+baseclass]) != OT_CLASS) { Raise_Error("trying to inherit from a %s",GetTypeName(_stack._vals[_stackbase+baseclass])); return false; }
|
||||
base = _class(_stack._vals[_stackbase + baseclass]);
|
||||
}
|
||||
if(attributes != MAX_FUNC_STACKSIZE) {
|
||||
@@ -675,7 +685,7 @@ bool SQVM::GETPARENT_OP(SQObjectPtr &o,SQObjectPtr &target)
|
||||
case OT_CLASS: target = _class(o)->_base?_class(o)->_base:_null_;
|
||||
break;
|
||||
default:
|
||||
Raise_Error(_SC("the %s type doesn't have a parent slot"), GetTypeName(o));
|
||||
Raise_Error("the %s type doesn't have a parent slot", GetTypeName(o));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -683,7 +693,7 @@ bool SQVM::GETPARENT_OP(SQObjectPtr &o,SQObjectPtr &target)
|
||||
|
||||
bool SQVM::Execute(SQObjectPtr &closure, SQInteger target, SQInteger nargs, SQInteger stackbase,SQObjectPtr &outres, SQBool raiseerror,ExecutionType et)
|
||||
{
|
||||
if ((_nnativecalls + 1) > MAX_NATIVE_CALLS) { Raise_Error(_SC("Native stack overflow")); return false; }
|
||||
if ((_nnativecalls + 1) > MAX_NATIVE_CALLS) { Raise_Error("Native stack overflow"); return false; }
|
||||
_nnativecalls++;
|
||||
AutoDec ad(&_nnativecalls);
|
||||
SQInteger traps = 0;
|
||||
@@ -738,12 +748,12 @@ exception_restore:
|
||||
|
||||
const SQInstruction &_i_ = *ci->_ip++;
|
||||
//dumpstack(_stackbase);
|
||||
//scprintf("%s %d %d %d %d\n",g_InstrDesc[_i_.op].name,arg0,arg1,arg2,arg3);
|
||||
//printf("%s %d %d %d %d\n",g_InstrDesc[_i_.op].name,arg0,arg1,arg2,arg3);
|
||||
switch(_i_.op)
|
||||
{
|
||||
case _OP_LINE:
|
||||
if(type(_debughook) != OT_NULL && _rawval(_debughook) != _rawval(ci->_closure))
|
||||
CallDebugHook(_SC('l'),arg1);
|
||||
CallDebugHook('l',arg1);
|
||||
continue;
|
||||
case _OP_LOAD: TARGET = ci->_literals[arg1]; continue;
|
||||
case _OP_LOADINT: TARGET = (SQInteger)arg1; continue;
|
||||
@@ -759,6 +769,7 @@ exception_restore:
|
||||
ct_stackbase = _stackbase;
|
||||
goto common_call;
|
||||
}
|
||||
/* FALL THROUGH */
|
||||
case _OP_CALL: {
|
||||
ct_tailcall = false;
|
||||
ct_target = arg0;
|
||||
@@ -828,11 +839,11 @@ common_call:
|
||||
STK(ct_target) = clo;
|
||||
break;
|
||||
}
|
||||
Raise_Error(_SC("attempt to call '%s'"), GetTypeName(clo));
|
||||
Raise_Error("attempt to call '%s'", GetTypeName(clo));
|
||||
SQ_THROW();
|
||||
}
|
||||
default:
|
||||
Raise_Error(_SC("attempt to call '%s'"), GetTypeName(clo));
|
||||
Raise_Error("attempt to call '%s'", GetTypeName(clo));
|
||||
SQ_THROW();
|
||||
}
|
||||
}
|
||||
@@ -934,7 +945,7 @@ common_call:
|
||||
case _OP_EXISTS: TARGET = Get(STK(arg1), STK(arg2), temp_reg, true,false)?_true_:_false_;continue;
|
||||
case _OP_INSTANCEOF:
|
||||
if(type(STK(arg1)) != OT_CLASS || type(STK(arg2)) != OT_INSTANCE)
|
||||
{Raise_Error(_SC("cannot apply instanceof between a %s and a %s"),GetTypeName(STK(arg1)),GetTypeName(STK(arg2))); SQ_THROW();}
|
||||
{Raise_Error("cannot apply instanceof between a %s and a %s",GetTypeName(STK(arg1)),GetTypeName(STK(arg2))); SQ_THROW();}
|
||||
TARGET = _instance(STK(arg2))->InstanceOf(_class(STK(arg1)))?_true_:_false_;
|
||||
continue;
|
||||
case _OP_AND:
|
||||
@@ -957,7 +968,7 @@ common_call:
|
||||
TARGET = SQInteger(~t);
|
||||
continue;
|
||||
}
|
||||
Raise_Error(_SC("attempt to perform a bitwise op on a %s"), GetTypeName(STK(arg1)));
|
||||
Raise_Error("attempt to perform a bitwise op on a %s", GetTypeName(STK(arg1)));
|
||||
SQ_THROW();
|
||||
case _OP_CLOSURE: {
|
||||
SQClosure *c = ci->_closure._unVal.pClosure;
|
||||
@@ -972,7 +983,7 @@ common_call:
|
||||
traps -= ci->_etraps;
|
||||
if(sarg1 != MAX_FUNC_STACKSIZE) STK(arg1) = temp_reg;
|
||||
}
|
||||
else { Raise_Error(_SC("trying to yield a '%s',only genenerator can be yielded"), GetTypeName(ci->_closure)); SQ_THROW();}
|
||||
else { Raise_Error("trying to yield a '%s',only genenerator can be yielded", GetTypeName(ci->_closure)); SQ_THROW();}
|
||||
if(Return(arg0, arg1, temp_reg)){
|
||||
assert(traps == 0);
|
||||
outres = temp_reg;
|
||||
@@ -982,7 +993,7 @@ common_call:
|
||||
}
|
||||
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(type(STK(arg1)) != OT_GENERATOR){ Raise_Error("trying to resume a '%s',only genenerator can be resumed", GetTypeName(STK(arg1))); SQ_THROW();}
|
||||
_GUARD(_generator(STK(arg1))->Resume(this, arg0));
|
||||
traps += ci->_etraps;
|
||||
continue;
|
||||
@@ -998,7 +1009,7 @@ common_call:
|
||||
case _OP_DELEGATE: _GUARD(DELEGATE_OP(TARGET,STK(arg1),STK(arg2))); continue;
|
||||
case _OP_CLONE:
|
||||
if(!Clone(STK(arg1), TARGET))
|
||||
{ Raise_Error(_SC("cloning a %s"), GetTypeName(STK(arg1))); SQ_THROW();}
|
||||
{ Raise_Error("cloning a %s", GetTypeName(STK(arg1))); SQ_THROW();}
|
||||
continue;
|
||||
case _OP_TYPEOF: TypeOf(STK(arg1), TARGET); continue;
|
||||
case _OP_PUSHTRAP:{
|
||||
@@ -1014,7 +1025,7 @@ common_call:
|
||||
}
|
||||
}
|
||||
continue;
|
||||
case _OP_THROW: Raise_Error(TARGET); SQ_THROW(); continue;
|
||||
case _OP_THROW: Raise_Error(TARGET); SQ_THROW();
|
||||
case _OP_CLASS: _GUARD(CLASS_OP(TARGET,arg1,arg2)); continue;
|
||||
case _OP_NEWSLOTA:
|
||||
bool bstatic = (arg0&NEW_SLOT_STATIC_FLAG)?true:false;
|
||||
@@ -1124,11 +1135,11 @@ void SQVM::CallDebugHook(SQInteger type,SQInteger forcedline)
|
||||
|
||||
bool SQVM::CallNative(SQNativeClosure *nclosure,SQInteger nargs,SQInteger stackbase,SQObjectPtr &retval,bool &suspend)
|
||||
{
|
||||
if (_nnativecalls + 1 > MAX_NATIVE_CALLS) { Raise_Error(_SC("Native stack overflow")); return false; }
|
||||
if (_nnativecalls + 1 > MAX_NATIVE_CALLS) { Raise_Error("Native stack overflow"); return false; }
|
||||
SQInteger nparamscheck = nclosure->_nparamscheck;
|
||||
if(((nparamscheck > 0) && (nparamscheck != nargs))
|
||||
|| ((nparamscheck < 0) && (nargs < (-nparamscheck)))) {
|
||||
Raise_Error(_SC("wrong number of parameters"));
|
||||
Raise_Error("wrong number of parameters");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1190,7 +1201,7 @@ bool SQVM::CallNative(SQNativeClosure *nclosure,SQInteger nargs,SQInteger stackb
|
||||
throw;
|
||||
}
|
||||
|
||||
assert(cstksize == _callsstacksize);
|
||||
_callsstacksize = cstksize;
|
||||
|
||||
_nnativecalls--;
|
||||
suspend = false;
|
||||
@@ -1336,10 +1347,10 @@ bool SQVM::Set(const SQObjectPtr &self,const SQObjectPtr &key,const SQObjectPtr
|
||||
}
|
||||
break;
|
||||
case OT_ARRAY:
|
||||
if(!sq_isnumeric(key)) {Raise_Error(_SC("indexing %s with %s"),GetTypeName(self),GetTypeName(key)); return false; }
|
||||
if(!sq_isnumeric(key)) {Raise_Error("indexing %s with %s",GetTypeName(self),GetTypeName(key)); return false; }
|
||||
return _array(self)->Set(tointeger(key),val);
|
||||
default:
|
||||
Raise_Error(_SC("trying to set '%s'"),GetTypeName(self));
|
||||
Raise_Error("trying to set '%s'",GetTypeName(self));
|
||||
return false;
|
||||
}
|
||||
if(fetchroot) {
|
||||
@@ -1378,7 +1389,7 @@ cloned_mt:
|
||||
|
||||
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; }
|
||||
if(type(key) == OT_NULL) { Raise_Error("null cannot be used as index"); return false; }
|
||||
switch(type(self)) {
|
||||
case OT_TABLE: {
|
||||
bool rawcall = true;
|
||||
@@ -1396,25 +1407,25 @@ bool SQVM::NewSlot(const SQObjectPtr &self,const SQObjectPtr &key,const SQObject
|
||||
SQObjectPtr res;
|
||||
Push(self);Push(key);Push(val);
|
||||
if(!CallMetaMethod(_instance(self),MT_NEWSLOT,3,res)) {
|
||||
Raise_Error(_SC("class instances do not support the new slot operator"));
|
||||
Raise_Error("class instances do not support the new slot operator");
|
||||
return false;
|
||||
}
|
||||
break;}
|
||||
case OT_CLASS:
|
||||
if(!_class(self)->NewSlot(_ss(this),key,val,bstatic)) {
|
||||
if(_class(self)->_locked) {
|
||||
Raise_Error(_SC("trying to modify a class that has already been instantiated"));
|
||||
Raise_Error("trying to modify a class that has already been instantiated");
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
SQObjectPtr oval = PrintObjVal(key);
|
||||
Raise_Error(_SC("the property '%s' already exists"),_stringval(oval));
|
||||
Raise_Error("the property '%s' already exists",_stringval(oval));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
Raise_Error(_SC("indexing %s with %s"),GetTypeName(self),GetTypeName(key));
|
||||
Raise_Error("indexing %s with %s",GetTypeName(self),GetTypeName(key));
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
@@ -1445,7 +1456,7 @@ bool SQVM::DeleteSlot(const SQObjectPtr &self,const SQObjectPtr &key,SQObjectPtr
|
||||
}
|
||||
}
|
||||
else {
|
||||
Raise_Error(_SC("cannot delete a slot from %s"),GetTypeName(self));
|
||||
Raise_Error("cannot delete a slot from %s",GetTypeName(self));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1453,7 +1464,7 @@ bool SQVM::DeleteSlot(const SQObjectPtr &self,const SQObjectPtr &key,SQObjectPtr
|
||||
}
|
||||
break;
|
||||
default:
|
||||
Raise_Error(_SC("attempt to delete a slot from a %s"),GetTypeName(self));
|
||||
Raise_Error("attempt to delete a slot from a %s",GetTypeName(self));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -1557,37 +1568,37 @@ void SQVM::dumpstack(SQInteger stackbase,bool dumpall)
|
||||
{
|
||||
SQInteger size=dumpall?_stack.size():_top;
|
||||
SQInteger n=0;
|
||||
scprintf(_SC("\n>>>>stack dump<<<<\n"));
|
||||
printf("\n>>>>stack dump<<<<\n");
|
||||
CallInfo &ci=_callsstack[_callsstacksize-1];
|
||||
scprintf(_SC("IP: %p\n"),ci._ip);
|
||||
scprintf(_SC("prev stack base: %d\n"),ci._prevstkbase);
|
||||
scprintf(_SC("prev top: %d\n"),ci._prevtop);
|
||||
printf("IP: %p\n",ci._ip);
|
||||
printf("prev stack base: %d\n",ci._prevstkbase);
|
||||
printf("prev top: %d\n",ci._prevtop);
|
||||
for(SQInteger i=0;i<size;i++){
|
||||
SQObjectPtr &obj=_stack[i];
|
||||
if(stackbase==i)scprintf(_SC(">"));else scprintf(_SC(" "));
|
||||
scprintf(_SC("[%d]:"),n);
|
||||
if(stackbase==i)printf(">");else printf(" ");
|
||||
printf("[%d]:",n);
|
||||
switch(type(obj)){
|
||||
case OT_FLOAT: scprintf(_SC("FLOAT %.3f"),_float(obj));break;
|
||||
case OT_INTEGER: scprintf(_SC("INTEGER %d"),_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;
|
||||
case OT_TABLE: scprintf(_SC("TABLE %p[%p]"),_table(obj),_table(obj)->_delegate);break;
|
||||
case OT_ARRAY: scprintf(_SC("ARRAY %p"),_array(obj));break;
|
||||
case OT_CLOSURE: scprintf(_SC("CLOSURE [%p]"),_closure(obj));break;
|
||||
case OT_NATIVECLOSURE: scprintf(_SC("NATIVECLOSURE"));break;
|
||||
case OT_USERDATA: scprintf(_SC("USERDATA %p[%p]"),_userdataval(obj),_userdata(obj)->_delegate);break;
|
||||
case OT_GENERATOR: scprintf(_SC("GENERATOR %p"),_generator(obj));break;
|
||||
case OT_THREAD: scprintf(_SC("THREAD [%p]"),_thread(obj));break;
|
||||
case OT_USERPOINTER: scprintf(_SC("USERPOINTER %p"),_userpointer(obj));break;
|
||||
case OT_CLASS: scprintf(_SC("CLASS %p"),_class(obj));break;
|
||||
case OT_INSTANCE: scprintf(_SC("INSTANCE %p"),_instance(obj));break;
|
||||
case OT_WEAKREF: scprintf(_SC("WEAKERF %p"),_weakref(obj));break;
|
||||
case OT_FLOAT: printf("FLOAT %.3f",_float(obj));break;
|
||||
case OT_INTEGER: printf("INTEGER %d",_integer(obj));break;
|
||||
case OT_BOOL: printf("BOOL %s",_integer(obj)?"true":"false");break;
|
||||
case OT_STRING: printf("STRING %s",_stringval(obj));break;
|
||||
case OT_NULL: printf("NULL"); break;
|
||||
case OT_TABLE: printf("TABLE %p[%p]",_table(obj),_table(obj)->_delegate);break;
|
||||
case OT_ARRAY: printf("ARRAY %p",_array(obj));break;
|
||||
case OT_CLOSURE: printf("CLOSURE [%p]",_closure(obj));break;
|
||||
case OT_NATIVECLOSURE: printf("NATIVECLOSURE");break;
|
||||
case OT_USERDATA: printf("USERDATA %p[%p]",_userdataval(obj),_userdata(obj)->_delegate);break;
|
||||
case OT_GENERATOR: printf("GENERATOR %p",_generator(obj));break;
|
||||
case OT_THREAD: printf("THREAD [%p]",_thread(obj));break;
|
||||
case OT_USERPOINTER: printf("USERPOINTER %p",_userpointer(obj));break;
|
||||
case OT_CLASS: printf("CLASS %p",_class(obj));break;
|
||||
case OT_INSTANCE: printf("INSTANCE %p",_instance(obj));break;
|
||||
case OT_WEAKREF: printf("WEAKERF %p",_weakref(obj));break;
|
||||
default:
|
||||
assert(0);
|
||||
break;
|
||||
};
|
||||
scprintf(_SC("\n"));
|
||||
printf("\n");
|
||||
++n;
|
||||
}
|
||||
}
|
||||
|
7
src/3rdparty/squirrel/squirrel/sqvm.h
vendored
7
src/3rdparty/squirrel/squirrel/sqvm.h
vendored
@@ -170,6 +170,7 @@ public:
|
||||
|
||||
SQBool _can_suspend;
|
||||
SQInteger _ops_till_suspend;
|
||||
SQBool _in_stackoverflow;
|
||||
|
||||
bool ShouldSuspend()
|
||||
{
|
||||
@@ -200,8 +201,10 @@ inline SQObjectPtr &stack_get(HSQUIRRELVM v,SQInteger idx){return ((idx>=0)?(v->
|
||||
|
||||
#define PUSH_CALLINFO(v,nci){ \
|
||||
if(v->_callsstacksize == v->_alloccallsstacksize) { \
|
||||
if (v->_callsstacksize > 65535) {\
|
||||
v->Raise_Error(_SC("stack overflow"));\
|
||||
if (v->_callsstacksize > 65535 && !v->_in_stackoverflow) {\
|
||||
v->_in_stackoverflow = true; \
|
||||
v->Raise_Error("stack overflow");\
|
||||
v->CallErrorHandler(v->_lasterror);\
|
||||
return false;\
|
||||
}\
|
||||
v->GrowCallStack(); \
|
||||
|
@@ -14,6 +14,7 @@
|
||||
|
||||
#include "../script/api/script_event_types.hpp"
|
||||
#include "../core/string_compare_type.hpp"
|
||||
#include "ai_scanner.hpp"
|
||||
#include <map>
|
||||
|
||||
/** A list that maps AI names to their AIInfo object. */
|
||||
@@ -25,7 +26,7 @@ typedef std::map<const char *, class ScriptInfo *, StringCompare> ScriptInfoList
|
||||
class AI {
|
||||
public:
|
||||
/**
|
||||
* The default months AIs start after eachother.
|
||||
* The default months AIs start after each other.
|
||||
*/
|
||||
enum StartNext {
|
||||
START_NEXT_EASY = DAYS_IN_YEAR * 2,
|
||||
@@ -67,13 +68,30 @@ public:
|
||||
static void Stop(CompanyID company);
|
||||
|
||||
/**
|
||||
* Suspend an AI for the reminder of the current tick. If the AI is
|
||||
* in a state when it cannot be suspended, it will continue to run
|
||||
* until it can be suspended.
|
||||
* @param company The company for which the AI should be suspended.
|
||||
* Suspend the AI and then pause execution of the script. The script
|
||||
* will not be resumed from its suspended state until the script has
|
||||
* been unpaused.
|
||||
* @param company The company for which the AI should be paused.
|
||||
* @pre Company::IsValidAiID(company)
|
||||
*/
|
||||
static void Suspend(CompanyID company);
|
||||
static void Pause(CompanyID company);
|
||||
|
||||
/**
|
||||
* Resume execution of the AI. This function will not actually execute
|
||||
* the script, but set a flag so that the script is executed my the usual
|
||||
* mechanism that executes the script.
|
||||
* @param company The company for which the AI should be unpaused.
|
||||
* @pre Company::IsValidAiID(company)
|
||||
*/
|
||||
static void Unpause(CompanyID company);
|
||||
|
||||
/**
|
||||
* Checks if the AI is paused.
|
||||
* @param company The company for which to check if the AI is paused.
|
||||
* @pre Company::IsValidAiID(company)
|
||||
* @return true if the AI is paused, otherwise false.
|
||||
*/
|
||||
static bool IsPaused(CompanyID company);
|
||||
|
||||
/**
|
||||
* Kill any and all AIs we manage.
|
||||
@@ -140,6 +158,12 @@ public:
|
||||
* found it is removed from the config.
|
||||
*/
|
||||
static void Rescan();
|
||||
|
||||
/** Gets the ScriptScanner instance that is used to find AIs */
|
||||
static AIScannerInfo *GetScannerInfo();
|
||||
/** Gets the ScriptScanner instance that is used to find AI Libraries */
|
||||
static AIScannerLibrary *GetScannerLibrary();
|
||||
|
||||
#if defined(ENABLE_NETWORK)
|
||||
/** Wrapper function for AIScanner::HasAI */
|
||||
static bool HasAI(const struct ContentInfo *ci, bool md5sum);
|
||||
|
@@ -11,10 +11,13 @@
|
||||
|
||||
#include "../stdafx.h"
|
||||
#include "../settings_type.h"
|
||||
#include "../string_func.h"
|
||||
#include "ai.hpp"
|
||||
#include "ai_config.hpp"
|
||||
#include "ai_info.hpp"
|
||||
|
||||
#include "../safeguards.h"
|
||||
|
||||
/** Configuration for AI start date, every AI has this setting. */
|
||||
ScriptConfigItem _start_date_config = {
|
||||
"start_date",
|
||||
@@ -28,7 +31,8 @@ ScriptConfigItem _start_date_config = {
|
||||
AI::START_NEXT_DEVIATION,
|
||||
30,
|
||||
SCRIPTCONFIG_NONE,
|
||||
NULL
|
||||
NULL,
|
||||
false
|
||||
};
|
||||
|
||||
/* static */ AIConfig *AIConfig::GetConfig(CompanyID company, ScriptSettingSource source)
|
||||
@@ -79,13 +83,13 @@ int AIConfig::GetSetting(const char *name) const
|
||||
{
|
||||
if (this->info == NULL) {
|
||||
SettingValueList::const_iterator it = this->settings.find(name);
|
||||
if (it == this->settings.end() || GetGameSettings().difficulty.diff_level != 3) {
|
||||
if (it == this->settings.end()) {
|
||||
assert(strcmp("start_date", name) == 0);
|
||||
switch (GetGameSettings().difficulty.diff_level) {
|
||||
case 0: return AI::START_NEXT_EASY;
|
||||
case 1: return AI::START_NEXT_MEDIUM;
|
||||
case 2: return AI::START_NEXT_HARD;
|
||||
case 3: return AI::START_NEXT_MEDIUM;
|
||||
switch (GetGameSettings().script.settings_profile) {
|
||||
case SP_EASY: return AI::START_NEXT_EASY;
|
||||
case SP_MEDIUM: return AI::START_NEXT_MEDIUM;
|
||||
case SP_HARD: return AI::START_NEXT_HARD;
|
||||
case SP_CUSTOM: return AI::START_NEXT_MEDIUM;
|
||||
default: NOT_REACHED();
|
||||
}
|
||||
}
|
||||
@@ -106,7 +110,7 @@ void AIConfig::SetSetting(const char *name, int value)
|
||||
if (it != this->settings.end()) {
|
||||
(*it).second = value;
|
||||
} else {
|
||||
this->settings[strdup(name)] = value;
|
||||
this->settings[stredup(name)] = value;
|
||||
}
|
||||
|
||||
return;
|
||||
|
@@ -22,6 +22,8 @@
|
||||
#include "ai_info.hpp"
|
||||
#include "ai.hpp"
|
||||
|
||||
#include "../safeguards.h"
|
||||
|
||||
/* static */ uint AI::frame_counter = 0;
|
||||
/* static */ AIScannerInfo *AI::scanner_info = NULL;
|
||||
/* static */ AIScannerLibrary *AI::scanner_library = NULL;
|
||||
@@ -47,6 +49,7 @@
|
||||
/* Load default data and store the name in the settings */
|
||||
config->Change(info->GetName(), -1, false, true);
|
||||
}
|
||||
config->AnchorUnchangeableSettings();
|
||||
|
||||
Backup<CompanyByte> cur_company(_current_company, company, FILE_LINE);
|
||||
Company *c = Company::Get(company);
|
||||
@@ -112,16 +115,37 @@
|
||||
DeleteWindowById(WC_AI_SETTINGS, company);
|
||||
}
|
||||
|
||||
/* static */ void AI::Suspend(CompanyID company)
|
||||
/* static */ void AI::Pause(CompanyID company)
|
||||
{
|
||||
if (_networking && !_network_server) return;
|
||||
/* The reason why dedicated servers are forbidden to execute this
|
||||
* command is not because it is unsafe, but because there is no way
|
||||
* for the server owner to unpause the script again. */
|
||||
if (_network_dedicated) return;
|
||||
|
||||
Backup<CompanyByte> cur_company(_current_company, company, FILE_LINE);
|
||||
Company::Get(company)->ai_instance->Suspend();
|
||||
Company::Get(company)->ai_instance->Pause();
|
||||
|
||||
cur_company.Restore();
|
||||
}
|
||||
|
||||
/* static */ void AI::Unpause(CompanyID company)
|
||||
{
|
||||
Backup<CompanyByte> cur_company(_current_company, company, FILE_LINE);
|
||||
Company::Get(company)->ai_instance->Unpause();
|
||||
|
||||
cur_company.Restore();
|
||||
}
|
||||
|
||||
/* static */ bool AI::IsPaused(CompanyID company)
|
||||
{
|
||||
Backup<CompanyByte> cur_company(_current_company, company, FILE_LINE);
|
||||
bool paused = Company::Get(company)->ai_instance->IsPaused();
|
||||
|
||||
cur_company.Restore();
|
||||
|
||||
return paused;
|
||||
}
|
||||
|
||||
/* static */ void AI::KillAll()
|
||||
{
|
||||
/* It might happen there are no companies .. than we have nothing to loop */
|
||||
@@ -176,7 +200,7 @@
|
||||
|
||||
/* static */ void AI::ResetConfig()
|
||||
{
|
||||
/* Check for both newgame as current game if we can reload the AIInfo insde
|
||||
/* Check for both newgame as current game if we can reload the AIInfo inside
|
||||
* the AIConfig. If not, remove the AI from the list (which will assign
|
||||
* a random new AI on reload). */
|
||||
for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; c++) {
|
||||
@@ -352,3 +376,14 @@
|
||||
}
|
||||
|
||||
#endif /* defined(ENABLE_NETWORK) */
|
||||
|
||||
/* static */ AIScannerInfo *AI::GetScannerInfo()
|
||||
{
|
||||
return AI::scanner_info;
|
||||
}
|
||||
|
||||
/* static */ AIScannerLibrary *AI::GetScannerLibrary()
|
||||
{
|
||||
return AI::scanner_library;
|
||||
}
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -14,7 +14,7 @@
|
||||
|
||||
#include "../company_type.h"
|
||||
|
||||
void ShowAIDebugWindow(CompanyID show_company = INVALID_COMPANY);
|
||||
Window* ShowAIDebugWindow(CompanyID show_company = INVALID_COMPANY);
|
||||
void ShowAIConfigWindow();
|
||||
void ShowAIDebugWindowIfAIError();
|
||||
void InitializeAIGui();
|
||||
|
@@ -15,15 +15,20 @@
|
||||
#include "ai_info.hpp"
|
||||
#include "ai_scanner.hpp"
|
||||
#include "../debug.h"
|
||||
#include "../string_func.h"
|
||||
#include "../rev.h"
|
||||
|
||||
#include "../safeguards.h"
|
||||
|
||||
/**
|
||||
* Check if the API version provided by the AI is supported.
|
||||
* @param api_version The API version as provided by the AI.
|
||||
*/
|
||||
static bool CheckAPIVersion(const char *api_version)
|
||||
{
|
||||
return strcmp(api_version, "0.7") == 0 || strcmp(api_version, "1.0") == 0 || strcmp(api_version, "1.1") == 0 || strcmp(api_version, "1.2") == 0 || strcmp(api_version, "1.3") == 0;
|
||||
return strcmp(api_version, "0.7") == 0 || strcmp(api_version, "1.0") == 0 || strcmp(api_version, "1.1") == 0 ||
|
||||
strcmp(api_version, "1.2") == 0 || strcmp(api_version, "1.3") == 0 || strcmp(api_version, "1.4") == 0 ||
|
||||
strcmp(api_version, "1.5") == 0 || strcmp(api_version, "1.6") == 0;
|
||||
}
|
||||
|
||||
#if defined(WIN32)
|
||||
@@ -60,15 +65,15 @@ template <> const char *GetClassName<AIInfo, ST_AI>() { return "AIInfo"; }
|
||||
{
|
||||
/* Get the AIInfo */
|
||||
SQUserPointer instance = NULL;
|
||||
if (SQ_FAILED(sq_getinstanceup(vm, 2, &instance, 0)) || instance == NULL) return sq_throwerror(vm, _SC("Pass an instance of a child class of AIInfo to RegisterAI"));
|
||||
if (SQ_FAILED(sq_getinstanceup(vm, 2, &instance, 0)) || instance == NULL) return sq_throwerror(vm, "Pass an instance of a child class of AIInfo to RegisterAI");
|
||||
AIInfo *info = (AIInfo *)instance;
|
||||
|
||||
SQInteger res = ScriptInfo::Constructor(vm, info);
|
||||
if (res != 0) return res;
|
||||
|
||||
ScriptConfigItem config = _start_date_config;
|
||||
config.name = strdup(config.name);
|
||||
config.description = strdup(config.description);
|
||||
config.name = stredup(config.name);
|
||||
config.description = stredup(config.description);
|
||||
info->config_list.push_front(config);
|
||||
|
||||
if (info->engine->MethodExists(*info->SQ_instance, "MinVersionToLoad")) {
|
||||
@@ -90,7 +95,7 @@ template <> const char *GetClassName<AIInfo, ST_AI>() { return "AIInfo"; }
|
||||
return SQ_ERROR;
|
||||
}
|
||||
} else {
|
||||
info->api_version = strdup("0.7");
|
||||
info->api_version = stredup("0.7");
|
||||
}
|
||||
|
||||
/* Remove the link to the real instance, else it might get deleted by RegisterAI() */
|
||||
@@ -113,7 +118,7 @@ template <> const char *GetClassName<AIInfo, ST_AI>() { return "AIInfo"; }
|
||||
|
||||
char buf[8];
|
||||
seprintf(buf, lastof(buf), "%d.%d", GB(_openttd_newgrf_version, 28, 4), GB(_openttd_newgrf_version, 24, 4));
|
||||
info->api_version = strdup(buf);
|
||||
info->api_version = stredup(buf);
|
||||
|
||||
/* Remove the link to the real instance, else it might get deleted by RegisterAI() */
|
||||
sq_setinstanceup(vm, 2, NULL);
|
||||
|
@@ -81,7 +81,8 @@
|
||||
|
||||
#include "../company_base.h"
|
||||
#include "../company_func.h"
|
||||
#include "../fileio_func.h"
|
||||
|
||||
#include "../safeguards.h"
|
||||
|
||||
AIInstance::AIInstance() :
|
||||
ScriptInstance("AI")
|
||||
@@ -128,13 +129,16 @@ void AIInstance::RegisterAPI()
|
||||
SQAIEventCompanyInTrouble_Register(this->engine);
|
||||
SQAIEventCompanyMerger_Register(this->engine);
|
||||
SQAIEventCompanyNew_Register(this->engine);
|
||||
SQAIEventCompanyTown_Register(this->engine);
|
||||
SQAIEventController_Register(this->engine);
|
||||
SQAIEventDisasterZeppelinerCleared_Register(this->engine);
|
||||
SQAIEventDisasterZeppelinerCrashed_Register(this->engine);
|
||||
SQAIEventEngineAvailable_Register(this->engine);
|
||||
SQAIEventEnginePreview_Register(this->engine);
|
||||
SQAIEventExclusiveTransportRights_Register(this->engine);
|
||||
SQAIEventIndustryClose_Register(this->engine);
|
||||
SQAIEventIndustryOpen_Register(this->engine);
|
||||
SQAIEventRoadReconstruction_Register(this->engine);
|
||||
SQAIEventStationFirstVehicle_Register(this->engine);
|
||||
SQAIEventSubsidyAwarded_Register(this->engine);
|
||||
SQAIEventSubsidyExpired_Register(this->engine);
|
||||
@@ -167,6 +171,17 @@ void AIInstance::RegisterAPI()
|
||||
SQAISignList_Register(this->engine);
|
||||
SQAIStation_Register(this->engine);
|
||||
SQAIStationList_Register(this->engine);
|
||||
SQAIStationList_Cargo_Register(this->engine);
|
||||
SQAIStationList_CargoPlanned_Register(this->engine);
|
||||
SQAIStationList_CargoPlannedByFrom_Register(this->engine);
|
||||
SQAIStationList_CargoPlannedByVia_Register(this->engine);
|
||||
SQAIStationList_CargoPlannedFromByVia_Register(this->engine);
|
||||
SQAIStationList_CargoPlannedViaByFrom_Register(this->engine);
|
||||
SQAIStationList_CargoWaiting_Register(this->engine);
|
||||
SQAIStationList_CargoWaitingByFrom_Register(this->engine);
|
||||
SQAIStationList_CargoWaitingByVia_Register(this->engine);
|
||||
SQAIStationList_CargoWaitingFromByVia_Register(this->engine);
|
||||
SQAIStationList_CargoWaitingViaByFrom_Register(this->engine);
|
||||
SQAIStationList_Vehicle_Register(this->engine);
|
||||
SQAISubsidy_Register(this->engine);
|
||||
SQAISubsidyList_Register(this->engine);
|
||||
@@ -191,29 +206,7 @@ void AIInstance::RegisterAPI()
|
||||
SQAIWaypointList_Register(this->engine);
|
||||
SQAIWaypointList_Vehicle_Register(this->engine);
|
||||
|
||||
if (!this->LoadCompatibilityScripts(this->versionAPI)) this->Died();
|
||||
}
|
||||
|
||||
bool AIInstance::LoadCompatibilityScripts(const char *api_version)
|
||||
{
|
||||
char script_name[32];
|
||||
seprintf(script_name, lastof(script_name), "compat_%s.nut", api_version);
|
||||
char buf[MAX_PATH];
|
||||
Searchpath sp;
|
||||
FOR_ALL_SEARCHPATHS(sp) {
|
||||
FioAppendDirectory(buf, MAX_PATH, sp, AI_DIR);
|
||||
ttd_strlcat(buf, script_name, MAX_PATH);
|
||||
if (!FileExists(buf)) continue;
|
||||
|
||||
if (this->engine->LoadScript(buf)) return true;
|
||||
|
||||
ScriptLog::Error("Failed to load API compatibility script");
|
||||
DEBUG(script, 0, "Error compiling / running API compatibility script: %s", buf);
|
||||
return false;
|
||||
}
|
||||
|
||||
ScriptLog::Warning("API compatibility script not found");
|
||||
return true;
|
||||
if (!this->LoadCompatibilityScripts(this->versionAPI, AI_DIR)) this->Died();
|
||||
}
|
||||
|
||||
void AIInstance::Died()
|
||||
@@ -258,8 +251,17 @@ ScriptInfo *AIInstance::FindLibrary(const char *library, int version)
|
||||
*/
|
||||
void CcAI(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
|
||||
{
|
||||
Company::Get(_current_company)->ai_instance->DoCommandCallback(result, tile, p1, p2);
|
||||
Company::Get(_current_company)->ai_instance->Continue();
|
||||
/*
|
||||
* The company might not exist anymore. Check for this.
|
||||
* The command checks are not useful since this callback
|
||||
* is also called when the command fails, which is does
|
||||
* when the company does not exist anymore.
|
||||
*/
|
||||
const Company *c = Company::GetIfValid(_current_company);
|
||||
if (c == NULL || c->ai_instance == NULL) return;
|
||||
|
||||
c->ai_instance->DoCommandCallback(result, tile, p1, p2);
|
||||
c->ai_instance->Continue();
|
||||
}
|
||||
|
||||
CommandCallback *AIInstance::GetDoCommandCallback()
|
||||
|
@@ -29,17 +29,10 @@ public:
|
||||
/* virtual */ ScriptInfo *FindLibrary(const char *library, int version);
|
||||
|
||||
private:
|
||||
const char *versionAPI; ///< Current API used by this script.
|
||||
|
||||
/* virtual */ void RegisterAPI();
|
||||
/* virtual */ void Died();
|
||||
/* virtual */ CommandCallback *GetDoCommandCallback();
|
||||
/* virtual */ void LoadDummyScript();
|
||||
|
||||
/**
|
||||
* Load squirrel scripts to emulate an older API.
|
||||
*/
|
||||
bool LoadCompatibilityScripts(const char *api_version);
|
||||
};
|
||||
|
||||
#endif /* AI_INSTANCE_HPP */
|
||||
|
@@ -18,6 +18,8 @@
|
||||
#include "ai_info.hpp"
|
||||
#include "ai_scanner.hpp"
|
||||
|
||||
#include "../safeguards.h"
|
||||
|
||||
|
||||
AIScannerInfo::AIScannerInfo() :
|
||||
ScriptScanner(),
|
||||
@@ -31,7 +33,7 @@ void AIScannerInfo::Initialize()
|
||||
|
||||
/* Create the dummy AI */
|
||||
free(this->main_script);
|
||||
this->main_script = strdup("%_dummy");
|
||||
this->main_script = stredup("%_dummy");
|
||||
extern void Script_CreateDummyInfo(HSQUIRRELVM vm, const char *type, const char *dir);
|
||||
Script_CreateDummyInfo(this->engine->GetVM(), "AI", "ai");
|
||||
}
|
||||
@@ -46,9 +48,9 @@ AIScannerInfo::~AIScannerInfo()
|
||||
delete this->info_dummy;
|
||||
}
|
||||
|
||||
void AIScannerInfo::GetScriptName(ScriptInfo *info, char *name, int len)
|
||||
void AIScannerInfo::GetScriptName(ScriptInfo *info, char *name, const char *last)
|
||||
{
|
||||
snprintf(name, len, "%s", info->GetName());
|
||||
seprintf(name, last, "%s", info->GetName());
|
||||
}
|
||||
|
||||
void AIScannerInfo::RegisterAPI(class Squirrel *engine)
|
||||
@@ -96,7 +98,7 @@ AIInfo *AIScannerInfo::FindInfo(const char *nameParam, int versionParam, bool fo
|
||||
if (nameParam == NULL) return NULL;
|
||||
|
||||
char ai_name[1024];
|
||||
ttd_strlcpy(ai_name, nameParam, sizeof(ai_name));
|
||||
strecpy(ai_name, nameParam, lastof(ai_name));
|
||||
strtolower(ai_name);
|
||||
|
||||
AIInfo *info = NULL;
|
||||
@@ -118,7 +120,7 @@ AIInfo *AIScannerInfo::FindInfo(const char *nameParam, int versionParam, bool fo
|
||||
if (force_exact_match) {
|
||||
/* Try to find a direct 'name.version' match */
|
||||
char ai_name_tmp[1024];
|
||||
snprintf(ai_name_tmp, sizeof(ai_name_tmp), "%s.%d", ai_name, versionParam);
|
||||
seprintf(ai_name_tmp, lastof(ai_name_tmp), "%s.%d", ai_name, versionParam);
|
||||
strtolower(ai_name_tmp);
|
||||
if (this->info_list.find(ai_name_tmp) != this->info_list.end()) return static_cast<AIInfo *>(this->info_list[ai_name_tmp]);
|
||||
}
|
||||
@@ -143,10 +145,10 @@ void AIScannerLibrary::Initialize()
|
||||
ScriptScanner::Initialize("AIScanner");
|
||||
}
|
||||
|
||||
void AIScannerLibrary::GetScriptName(ScriptInfo *info, char *name, int len)
|
||||
void AIScannerLibrary::GetScriptName(ScriptInfo *info, char *name, const char *last)
|
||||
{
|
||||
AILibrary *library = static_cast<AILibrary *>(info);
|
||||
snprintf(name, len, "%s.%s", library->GetCategory(), library->GetInstanceName());
|
||||
seprintf(name, last, "%s.%s", library->GetCategory(), library->GetInstanceName());
|
||||
}
|
||||
|
||||
void AIScannerLibrary::RegisterAPI(class Squirrel *engine)
|
||||
@@ -158,7 +160,7 @@ AILibrary *AIScannerLibrary::FindLibrary(const char *library, int version)
|
||||
{
|
||||
/* Internally we store libraries as 'library.version' */
|
||||
char library_name[1024];
|
||||
snprintf(library_name, sizeof(library_name), "%s.%d", library, version);
|
||||
seprintf(library_name, lastof(library_name), "%s.%d", library, version);
|
||||
strtolower(library_name);
|
||||
|
||||
/* Check if the library + version exists */
|
||||
|
@@ -30,7 +30,7 @@ public:
|
||||
/**
|
||||
* Check if we have an AI by name and version available in our list.
|
||||
* @param nameParam The name of the AI.
|
||||
* @param versionParam The versionof the AI, or -1 if you want the latest.
|
||||
* @param versionParam The version of the AI, or -1 if you want the latest.
|
||||
* @param force_exact_match Only match name+version, never latest.
|
||||
* @return NULL if no match found, otherwise the AI that matched.
|
||||
*/
|
||||
@@ -42,7 +42,7 @@ public:
|
||||
void SetDummyAI(class AIInfo *info);
|
||||
|
||||
protected:
|
||||
/* virtual */ void GetScriptName(ScriptInfo *info, char *name, int len);
|
||||
/* virtual */ void GetScriptName(ScriptInfo *info, char *name, const char *last);
|
||||
/* virtual */ const char *GetFileName() const { return PATHSEP "info.nut"; }
|
||||
/* virtual */ Subdirectory GetDirectory() const { return AI_DIR; }
|
||||
/* virtual */ const char *GetScannerName() const { return "AIs"; }
|
||||
@@ -65,7 +65,7 @@ public:
|
||||
class AILibrary *FindLibrary(const char *library, int version);
|
||||
|
||||
protected:
|
||||
/* virtual */ void GetScriptName(ScriptInfo *info, char *name, int len);
|
||||
/* virtual */ void GetScriptName(ScriptInfo *info, char *name, const char *last);
|
||||
/* virtual */ const char *GetFileName() const { return PATHSEP "library.nut"; }
|
||||
/* virtual */ Subdirectory GetDirectory() const { return AI_LIBRARY_DIR; }
|
||||
/* virtual */ const char *GetScannerName() const { return "AI Libraries"; }
|
||||
|
@@ -15,6 +15,17 @@
|
||||
#include "station_map.h"
|
||||
#include "vehicle_base.h"
|
||||
|
||||
/**
|
||||
* Base values for flight levels above ground level for 'normal' flight and holding patterns.
|
||||
* Due to speed and direction, the actual flight level may be higher.
|
||||
*/
|
||||
enum AircraftFlyingAltitude {
|
||||
AIRCRAFT_MIN_FLYING_ALTITUDE = 120, ///< Minimum flying altitude above tile.
|
||||
AIRCRAFT_MAX_FLYING_ALTITUDE = 360, ///< Maximum flying altitude above tile.
|
||||
PLANE_HOLD_MAX_FLYING_ALTITUDE = 150, ///< holding flying altitude above tile of planes.
|
||||
HELICOPTER_HOLD_MAX_FLYING_ALTITUDE = 184 ///< holding flying altitude above tile of helicopters.
|
||||
};
|
||||
|
||||
struct Aircraft;
|
||||
|
||||
/** An aircraft can be one of those types. */
|
||||
@@ -25,21 +36,31 @@ enum AircraftSubType {
|
||||
AIR_ROTOR = 6, ///< rotor of an helicopter
|
||||
};
|
||||
|
||||
/** Aircraft flags. */
|
||||
enum VehicleAirFlags {
|
||||
VAF_DEST_TOO_FAR = 0, ///< Next destination is too far away.
|
||||
/** Flags for air vehicles; shared with disaster vehicles. */
|
||||
enum AirVehicleFlags {
|
||||
VAF_DEST_TOO_FAR = 0, ///< Next destination is too far away.
|
||||
|
||||
/* The next two flags are to prevent stair climbing of the aircraft. The idea is that the aircraft
|
||||
* will ascend or descend multiple flight levels at a time instead of following the contours of the
|
||||
* landscape at a fixed altitude. This only has effect when there are more than 15 height levels. */
|
||||
VAF_IN_MAX_HEIGHT_CORRECTION = 1, ///< The vehicle is currently lowering its altitude because it hit the upper bound.
|
||||
VAF_IN_MIN_HEIGHT_CORRECTION = 2, ///< The vehicle is currently raising its altitude because it hit the lower bound.
|
||||
};
|
||||
|
||||
static const int ROTOR_Z_OFFSET = 5; ///< Z Offset between helicopter- and rotorsprite.
|
||||
|
||||
void HandleAircraftEnterHangar(Aircraft *v);
|
||||
void GetAircraftSpriteSize(EngineID engine, uint &width, uint &height, EngineImageType image_type);
|
||||
void GetAircraftSpriteSize(EngineID engine, uint &width, uint &height, int &xoffs, int &yoffs, EngineImageType image_type);
|
||||
void UpdateAirplanesOnNewStation(const Station *st);
|
||||
void UpdateAircraftCache(Aircraft *v, bool update_range = false);
|
||||
|
||||
void AircraftLeaveHangar(Aircraft *v, Direction exit_dir);
|
||||
void AircraftNextAirportPos_and_Order(Aircraft *v);
|
||||
void SetAircraftPosition(Aircraft *v, int x, int y, int z);
|
||||
int GetAircraftFlyingAltitude(const Aircraft *v);
|
||||
|
||||
void GetAircraftFlightLevelBounds(const Vehicle *v, int *min, int *max);
|
||||
template <class T>
|
||||
int GetAircraftFlightLevel(T *v, bool takeoff = false);
|
||||
|
||||
/** Variables that are cached to improve performance and such. */
|
||||
struct AircraftCache {
|
||||
@@ -59,7 +80,7 @@ struct Aircraft FINAL : public SpecializedVehicle<Aircraft, VEH_AIRCRAFT> {
|
||||
DirectionByte last_direction;
|
||||
byte number_consecutive_turns; ///< Protection to prevent the aircraft of making a lot of turns in order to reach a specific point.
|
||||
byte turn_counter; ///< Ticks between each turn to prevent > 45 degree turns.
|
||||
byte flags; ///< Aircraft flags. @see VehicleAirFlags
|
||||
byte flags; ///< Aircraft flags. @see AirVehicleFlags
|
||||
|
||||
AircraftCache acache;
|
||||
|
||||
@@ -76,8 +97,15 @@ struct Aircraft FINAL : public SpecializedVehicle<Aircraft, VEH_AIRCRAFT> {
|
||||
int GetDisplaySpeed() const { return this->cur_speed; }
|
||||
int GetDisplayMaxSpeed() const { return this->vcache.cached_max_speed; }
|
||||
int GetSpeedOldUnits() const { return this->vcache.cached_max_speed * 10 / 128; }
|
||||
int GetCurrentMaxSpeed() const { return this->GetSpeedOldUnits(); }
|
||||
Money GetRunningCost() const;
|
||||
bool IsInDepot() const { return (this->vehstatus & VS_HIDDEN) != 0 && IsHangarTile(this->tile); }
|
||||
|
||||
bool IsInDepot() const
|
||||
{
|
||||
assert(this->IsPrimaryVehicle());
|
||||
return (this->vehstatus & VS_HIDDEN) != 0 && IsHangarTile(this->tile);
|
||||
}
|
||||
|
||||
bool Tick();
|
||||
void OnNewDay();
|
||||
uint Crash(bool flooded = false);
|
||||
|
@@ -37,14 +37,11 @@
|
||||
#include "core/backup_type.hpp"
|
||||
#include "infrastructure_func.h"
|
||||
#include "zoom_func.h"
|
||||
#include "disaster_vehicle.h"
|
||||
|
||||
#include "table/strings.h"
|
||||
|
||||
static const int ROTOR_Z_OFFSET = 5; ///< Z Offset between helicopter- and rotorsprite.
|
||||
|
||||
static const int PLANE_HOLDING_ALTITUDE = 150; ///< Altitude of planes in holding pattern (= lowest flight altitude).
|
||||
static const int HELI_FLIGHT_ALTITUDE = 184; ///< Normal flight altitude of helicopters.
|
||||
|
||||
#include "safeguards.h"
|
||||
|
||||
void Aircraft::UpdateDeltaXY(Direction direction)
|
||||
{
|
||||
@@ -100,6 +97,12 @@ static const SpriteID _aircraft_sprite[] = {
|
||||
0x0EBD, 0x0EC5
|
||||
};
|
||||
|
||||
template <>
|
||||
bool IsValidImageIndex<VEH_AIRCRAFT>(uint8 image_index)
|
||||
{
|
||||
return image_index < lengthof(_aircraft_sprite);
|
||||
}
|
||||
|
||||
/** Helicopter rotor animation states */
|
||||
enum HelicopterRotorStates {
|
||||
HRS_ROTOR_STOPPED,
|
||||
@@ -137,6 +140,11 @@ static StationID FindNearestHangar(const Aircraft *v)
|
||||
|
||||
/* v->tile can't be used here, when aircraft is flying v->tile is set to 0 */
|
||||
uint distance = DistanceSquare(vtile, st->airport.tile);
|
||||
if (v->acache.cached_max_range_sqr != 0) {
|
||||
/* Check if our current destination can be reached from the depot airport. */
|
||||
const Station *cur_dest = GetTargetAirportIfValid(v);
|
||||
if (cur_dest != NULL && DistanceSquare(st->airport.tile, cur_dest->airport.tile) > v->acache.cached_max_range_sqr) continue;
|
||||
}
|
||||
if (distance < best || index == INVALID_STATION) {
|
||||
best = distance;
|
||||
index = st->index;
|
||||
@@ -156,6 +164,7 @@ SpriteID Aircraft::GetImage(Direction direction, EngineImageType image_type) con
|
||||
spritenum = this->GetEngine()->original_image_index;
|
||||
}
|
||||
|
||||
assert(IsValidImageIndex<VEH_AIRCRAFT>(spritenum));
|
||||
return direction + _aircraft_sprite[spritenum];
|
||||
}
|
||||
|
||||
@@ -185,6 +194,7 @@ static SpriteID GetAircraftIcon(EngineID engine, EngineImageType image_type)
|
||||
spritenum = e->original_image_index;
|
||||
}
|
||||
|
||||
assert(IsValidImageIndex<VEH_AIRCRAFT>(spritenum));
|
||||
return DIR_W + _aircraft_sprite[spritenum];
|
||||
}
|
||||
|
||||
@@ -192,28 +202,35 @@ void DrawAircraftEngine(int left, int right, int preferred_x, int y, EngineID en
|
||||
{
|
||||
SpriteID sprite = GetAircraftIcon(engine, image_type);
|
||||
const Sprite *real_sprite = GetSprite(sprite, ST_NORMAL);
|
||||
preferred_x = Clamp(preferred_x, left - UnScaleByZoom(real_sprite->x_offs, ZOOM_LVL_GUI), right - UnScaleByZoom(real_sprite->width, ZOOM_LVL_GUI) - UnScaleByZoom(real_sprite->x_offs, ZOOM_LVL_GUI));
|
||||
preferred_x = Clamp(preferred_x,
|
||||
left - UnScaleGUI(real_sprite->x_offs),
|
||||
right - UnScaleGUI(real_sprite->width) - UnScaleGUI(real_sprite->x_offs));
|
||||
DrawSprite(sprite, pal, preferred_x, y);
|
||||
|
||||
if (!(AircraftVehInfo(engine)->subtype & AIR_CTOL)) {
|
||||
SpriteID rotor_sprite = GetCustomRotorIcon(engine, image_type);
|
||||
if (rotor_sprite == 0) rotor_sprite = SPR_ROTOR_STOPPED;
|
||||
DrawSprite(rotor_sprite, PAL_NONE, preferred_x, y - 5);
|
||||
DrawSprite(rotor_sprite, PAL_NONE, preferred_x, y - ScaleGUITrad(5));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the size of the sprite of an aircraft sprite heading west (used for lists)
|
||||
* @param engine The engine to get the sprite from
|
||||
* @param width The width of the sprite
|
||||
* @param height The height of the sprite
|
||||
* Get the size of the sprite of an aircraft sprite heading west (used for lists).
|
||||
* @param engine The engine to get the sprite from.
|
||||
* @param[out] width The width of the sprite.
|
||||
* @param[out] height The height of the sprite.
|
||||
* @param[out] xoffs Number of pixels to shift the sprite to the right.
|
||||
* @param[out] yoffs Number of pixels to shift the sprite downwards.
|
||||
* @param image_type Context the sprite is used in.
|
||||
*/
|
||||
void GetAircraftSpriteSize(EngineID engine, uint &width, uint &height, EngineImageType image_type)
|
||||
void GetAircraftSpriteSize(EngineID engine, uint &width, uint &height, int &xoffs, int &yoffs, EngineImageType image_type)
|
||||
{
|
||||
const Sprite *spr = GetSprite(GetAircraftIcon(engine, image_type), ST_NORMAL);
|
||||
|
||||
width = UnScaleByZoom(spr->width, ZOOM_LVL_GUI);
|
||||
height = UnScaleByZoom(spr->height, ZOOM_LVL_GUI);
|
||||
width = UnScaleGUI(spr->width);
|
||||
height = UnScaleGUI(spr->height);
|
||||
xoffs = UnScaleGUI(spr->x_offs);
|
||||
yoffs = UnScaleGUI(spr->y_offs);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -233,7 +250,7 @@ CommandCost CmdBuildAircraft(TileIndex tile, DoCommandFlag flags, const Engine *
|
||||
/* Prevent building aircraft types at places which can't handle them */
|
||||
if (!CanVehicleUseStation(e->index, st)) return CMD_ERROR;
|
||||
|
||||
/* Make sure all aircraft end up in the first tile of the hanger. */
|
||||
/* Make sure all aircraft end up in the first tile of the hangar. */
|
||||
tile = st->airport.GetHangarTile(st->airport.GetHangarNum(tile));
|
||||
|
||||
if (flags & DC_EXEC) {
|
||||
@@ -262,13 +279,16 @@ CommandCost CmdBuildAircraft(TileIndex tile, DoCommandFlag flags, const Engine *
|
||||
v->spritenum = avi->image_index;
|
||||
|
||||
v->cargo_cap = avi->passenger_capacity;
|
||||
v->refit_cap = 0;
|
||||
u->cargo_cap = avi->mail_capacity;
|
||||
u->refit_cap = 0;
|
||||
|
||||
v->cargo_type = e->GetDefaultCargoType();
|
||||
u->cargo_type = CT_MAIL;
|
||||
|
||||
v->name = NULL;
|
||||
v->last_station_visited = INVALID_STATION;
|
||||
v->last_loading_station = INVALID_STATION;
|
||||
|
||||
v->acceleration = avi->acceleration;
|
||||
v->engine_type = e->index;
|
||||
@@ -293,7 +313,7 @@ CommandCost CmdBuildAircraft(TileIndex tile, DoCommandFlag flags, const Engine *
|
||||
v->targetairport = GetStationIndex(tile);
|
||||
v->SetNext(u);
|
||||
|
||||
v->service_interval = Company::Get(_current_company)->settings.vehicle.servint_aircraft;
|
||||
v->SetServiceInterval(Company::Get(_current_company)->settings.vehicle.servint_aircraft);
|
||||
|
||||
v->date_of_last_service = _date;
|
||||
v->build_year = u->build_year = _cur_year;
|
||||
@@ -305,6 +325,7 @@ CommandCost CmdBuildAircraft(TileIndex tile, DoCommandFlag flags, const Engine *
|
||||
|
||||
v->vehicle_flags = 0;
|
||||
if (e->flags & ENGINE_EXCLUSIVE_PREVIEW) SetBit(v->vehicle_flags, VF_BUILT_AS_PROTOTYPE);
|
||||
v->SetServiceIntervalIsPercent(Company::Get(_current_company)->settings.vehicle.servint_ispercent);
|
||||
|
||||
v->InvalidateNewGRFCacheOfChain();
|
||||
|
||||
@@ -314,8 +335,8 @@ CommandCost CmdBuildAircraft(TileIndex tile, DoCommandFlag flags, const Engine *
|
||||
|
||||
UpdateAircraftCache(v, true);
|
||||
|
||||
VehicleUpdatePosition(v);
|
||||
VehicleUpdatePosition(u);
|
||||
v->UpdatePosition();
|
||||
u->UpdatePosition();
|
||||
|
||||
/* Aircraft with 3 vehicles (chopper)? */
|
||||
if (v->subtype == AIR_HELICOPTER) {
|
||||
@@ -336,7 +357,7 @@ CommandCost CmdBuildAircraft(TileIndex tile, DoCommandFlag flags, const Engine *
|
||||
w->UpdateDeltaXY(INVALID_DIR);
|
||||
|
||||
u->SetNext(w);
|
||||
VehicleUpdatePosition(w);
|
||||
w->UpdatePosition();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -366,7 +387,7 @@ bool Aircraft::FindClosestDepot(TileIndex *location, DestinationID *destination,
|
||||
static void CheckIfAircraftNeedsService(Aircraft *v)
|
||||
{
|
||||
if (Company::Get(v->owner)->settings.vehicle.servint_aircraft == 0 || !v->NeedsAutomaticServicing()) return;
|
||||
if (v->IsInDepot()) {
|
||||
if (v->IsChainInDepot()) {
|
||||
VehicleServiceInDepot(v);
|
||||
return;
|
||||
}
|
||||
@@ -464,7 +485,7 @@ static void HelicopterTickHandler(Aircraft *v)
|
||||
|
||||
u->cur_image = img;
|
||||
|
||||
VehicleUpdatePositionAndViewport(u);
|
||||
u->UpdatePositionAndViewport();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -480,7 +501,7 @@ void SetAircraftPosition(Aircraft *v, int x, int y, int z)
|
||||
v->y_pos = y;
|
||||
v->z_pos = z;
|
||||
|
||||
VehicleUpdatePosition(v);
|
||||
v->UpdatePosition();
|
||||
v->UpdateViewport(true, false);
|
||||
if (v->subtype == AIR_HELICOPTER) v->Next()->Next()->cur_image = GetRotorImage(v, EIT_ON_MAP);
|
||||
|
||||
@@ -495,7 +516,7 @@ void SetAircraftPosition(Aircraft *v, int x, int y, int z)
|
||||
u->z_pos = GetSlopePixelZ(safe_x, safe_y);
|
||||
u->cur_image = v->cur_image;
|
||||
|
||||
VehicleUpdatePositionAndViewport(u);
|
||||
u->UpdatePositionAndViewport();
|
||||
|
||||
u = u->Next();
|
||||
if (u != NULL) {
|
||||
@@ -503,7 +524,7 @@ void SetAircraftPosition(Aircraft *v, int x, int y, int z)
|
||||
u->y_pos = y;
|
||||
u->z_pos = z + ROTOR_Z_OFFSET;
|
||||
|
||||
VehicleUpdatePositionAndViewport(u);
|
||||
u->UpdatePositionAndViewport();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -588,7 +609,14 @@ enum AircraftSpeedLimits {
|
||||
*/
|
||||
static int UpdateAircraftSpeed(Aircraft *v, uint speed_limit = SPEED_LIMIT_NONE, bool hard_limit = true)
|
||||
{
|
||||
uint spd = v->acceleration * 16;
|
||||
/**
|
||||
* 'acceleration' has the unit 3/8 mph/tick. This function is called twice per tick.
|
||||
* So the speed amount we need to accelerate is:
|
||||
* acceleration * 3 / 16 mph = acceleration * 3 / 16 * 16 / 10 km-ish/h
|
||||
* = acceleration * 3 / 10 * 256 * (km-ish/h / 256)
|
||||
* ~ acceleration * 77 (km-ish/h / 256)
|
||||
*/
|
||||
uint spd = v->acceleration * 77;
|
||||
byte t;
|
||||
|
||||
/* Adjust speed limits by plane speed factor to prevent taxiing
|
||||
@@ -626,7 +654,7 @@ static int UpdateAircraftSpeed(Aircraft *v, uint speed_limit = SPEED_LIMIT_NONE,
|
||||
/* Adjust distance moved by plane speed setting */
|
||||
if (_settings_game.vehicle.plane_speed > 1) spd /= _settings_game.vehicle.plane_speed;
|
||||
|
||||
/* Convert direction-indepenent speed into direction-dependent speed. (old movement method) */
|
||||
/* Convert direction-independent speed into direction-dependent speed. (old movement method) */
|
||||
spd = v->GetOldAdvanceSpeed(spd);
|
||||
|
||||
spd += v->progress;
|
||||
@@ -635,23 +663,38 @@ static int UpdateAircraftSpeed(Aircraft *v, uint speed_limit = SPEED_LIMIT_NONE,
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the cruise altitude of an aircraft.
|
||||
* The cruise altitude is determined by the velocity of the vehicle
|
||||
* and the direction it is moving
|
||||
* @param v The vehicle. Should be an aircraft
|
||||
* @returns Altitude in pixel units
|
||||
* Get the tile height below the aircraft.
|
||||
* This function is needed because aircraft can leave the mapborders.
|
||||
*
|
||||
* @param v The vehicle to get the height for.
|
||||
* @return The height in pixels from 'z_pos' 0.
|
||||
*/
|
||||
int GetAircraftFlyingAltitude(const Aircraft *v)
|
||||
int GetTileHeightBelowAircraft(const Vehicle *v)
|
||||
{
|
||||
if (v->subtype == AIR_HELICOPTER) return HELI_FLIGHT_ALTITUDE;
|
||||
int safe_x = Clamp(v->x_pos, 0, MapMaxX() * TILE_SIZE);
|
||||
int safe_y = Clamp(v->y_pos, 0, MapMaxY() * TILE_SIZE);
|
||||
return TileHeight(TileVirtXY(safe_x, safe_y)) * TILE_HEIGHT;
|
||||
}
|
||||
|
||||
/* Make sure Aircraft fly no lower so that they don't conduct
|
||||
* CFITs (controlled flight into terrain)
|
||||
*/
|
||||
int base_altitude = PLANE_HOLDING_ALTITUDE;
|
||||
/**
|
||||
* Get the 'flight level' bounds, in pixels from 'z_pos' 0 for a particular
|
||||
* vehicle for normal flight situation.
|
||||
* When the maximum is reached the vehicle should consider descending.
|
||||
* When the minimum is reached the vehicle should consider ascending.
|
||||
*
|
||||
* @param v The vehicle to get the flight levels for.
|
||||
* @param [out] min_level The minimum bounds for flight level.
|
||||
* @param [out] max_level The maximum bounds for flight level.
|
||||
*/
|
||||
void GetAircraftFlightLevelBounds(const Vehicle *v, int *min_level, int *max_level)
|
||||
{
|
||||
int base_altitude = GetTileHeightBelowAircraft(v);
|
||||
if (v->type == VEH_AIRCRAFT && Aircraft::From(v)->subtype == AIR_HELICOPTER) {
|
||||
base_altitude += HELICOPTER_HOLD_MAX_FLYING_ALTITUDE - PLANE_HOLD_MAX_FLYING_ALTITUDE;
|
||||
}
|
||||
|
||||
/* Make sure eastbound and westbound planes do not "crash" into each
|
||||
* other by providing them with vertical seperation
|
||||
* other by providing them with vertical separation
|
||||
*/
|
||||
switch (v->direction) {
|
||||
case DIR_N:
|
||||
@@ -665,11 +708,67 @@ int GetAircraftFlyingAltitude(const Aircraft *v)
|
||||
}
|
||||
|
||||
/* Make faster planes fly higher so that they can overtake slower ones */
|
||||
base_altitude += min(20 * (v->vcache.cached_max_speed / 200), 90);
|
||||
base_altitude += min(20 * (v->vcache.cached_max_speed / 200) - 90, 0);
|
||||
|
||||
return base_altitude;
|
||||
if (min_level != NULL) *min_level = base_altitude + AIRCRAFT_MIN_FLYING_ALTITUDE;
|
||||
if (max_level != NULL) *max_level = base_altitude + AIRCRAFT_MAX_FLYING_ALTITUDE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the maximum 'flight level' for the holding pattern of the aircraft,
|
||||
* in pixels 'z_pos' 0, depending on terrain below..
|
||||
*
|
||||
* @param v The aircraft that may or may not need to decrease its altitude.
|
||||
* @return Maximal aircraft holding altitude, while in normal flight, in pixels.
|
||||
*/
|
||||
int GetAircraftHoldMaxAltitude(const Aircraft *v)
|
||||
{
|
||||
int tile_height = GetTileHeightBelowAircraft(v);
|
||||
|
||||
return tile_height + ((v->subtype == AIR_HELICOPTER) ? HELICOPTER_HOLD_MAX_FLYING_ALTITUDE : PLANE_HOLD_MAX_FLYING_ALTITUDE);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
int GetAircraftFlightLevel(T *v, bool takeoff)
|
||||
{
|
||||
/* Aircraft is in flight. We want to enforce it being somewhere
|
||||
* between the minimum and the maximum allowed altitude. */
|
||||
int aircraft_min_altitude;
|
||||
int aircraft_max_altitude;
|
||||
GetAircraftFlightLevelBounds(v, &aircraft_min_altitude, &aircraft_max_altitude);
|
||||
int aircraft_middle_altitude = (aircraft_min_altitude + aircraft_max_altitude) / 2;
|
||||
|
||||
/* If those assumptions would be violated, aircrafts would behave fairly strange. */
|
||||
assert(aircraft_min_altitude < aircraft_middle_altitude);
|
||||
assert(aircraft_middle_altitude < aircraft_max_altitude);
|
||||
|
||||
int z = v->z_pos;
|
||||
if (z < aircraft_min_altitude ||
|
||||
(HasBit(v->flags, VAF_IN_MIN_HEIGHT_CORRECTION) && z < aircraft_middle_altitude)) {
|
||||
/* Ascend. And don't fly into that mountain right ahead.
|
||||
* And avoid our aircraft become a stairclimber, so if we start
|
||||
* correcting altitude, then we stop correction not too early. */
|
||||
SetBit(v->flags, VAF_IN_MIN_HEIGHT_CORRECTION);
|
||||
z += takeoff ? 2 : 1;
|
||||
} else if (!takeoff && (z > aircraft_max_altitude ||
|
||||
(HasBit(v->flags, VAF_IN_MAX_HEIGHT_CORRECTION) && z > aircraft_middle_altitude))) {
|
||||
/* Descend lower. You are an aircraft, not an space ship.
|
||||
* And again, don't stop correcting altitude too early. */
|
||||
SetBit(v->flags, VAF_IN_MAX_HEIGHT_CORRECTION);
|
||||
z--;
|
||||
} else if (HasBit(v->flags, VAF_IN_MIN_HEIGHT_CORRECTION) && z >= aircraft_middle_altitude) {
|
||||
/* Now, we have corrected altitude enough. */
|
||||
ClrBit(v->flags, VAF_IN_MIN_HEIGHT_CORRECTION);
|
||||
} else if (HasBit(v->flags, VAF_IN_MAX_HEIGHT_CORRECTION) && z <= aircraft_middle_altitude) {
|
||||
/* Now, we have corrected altitude enough. */
|
||||
ClrBit(v->flags, VAF_IN_MAX_HEIGHT_CORRECTION);
|
||||
}
|
||||
|
||||
return z;
|
||||
}
|
||||
|
||||
template int GetAircraftFlightLevel(DisasterVehicle *v, bool takeoff);
|
||||
|
||||
/**
|
||||
* Find the entry point to an airport depending on direction which
|
||||
* the airport is being approached from. Each airport can have up to
|
||||
@@ -682,7 +781,7 @@ int GetAircraftFlyingAltitude(const Aircraft *v)
|
||||
* @param v The vehicle that is approaching the airport
|
||||
* @param apc The Airport Class being approached.
|
||||
* @param rotation The rotation of the airport.
|
||||
* @returns The index of the entry point
|
||||
* @return The index of the entry point
|
||||
*/
|
||||
static byte AircraftGetEntryPoint(const Aircraft *v, const AirportFTAClass *apc, Direction rotation)
|
||||
{
|
||||
@@ -759,7 +858,7 @@ static bool AircraftController(Aircraft *v)
|
||||
UpdateAircraftCache(v);
|
||||
AircraftNextAirportPos_and_Order(v);
|
||||
/* get aircraft back on running altitude */
|
||||
SetAircraftPosition(v, v->x_pos, v->y_pos, GetAircraftFlyingAltitude(v));
|
||||
SetAircraftPosition(v, v->x_pos, v->y_pos, GetAircraftFlightLevel(v));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -787,7 +886,9 @@ static bool AircraftController(Aircraft *v)
|
||||
count = UpdateAircraftSpeed(v);
|
||||
if (count > 0) {
|
||||
v->tile = 0;
|
||||
int z_dest = GetAircraftFlyingAltitude(v);
|
||||
|
||||
int z_dest;
|
||||
GetAircraftFlightLevelBounds(v, &z_dest, NULL);
|
||||
|
||||
/* Reached altitude? */
|
||||
if (v->z_pos >= z_dest) {
|
||||
@@ -944,12 +1045,14 @@ static bool AircraftController(Aircraft *v)
|
||||
int z = v->z_pos;
|
||||
|
||||
if (amd.flag & AMED_TAKEOFF) {
|
||||
z = min(z + 2, GetAircraftFlyingAltitude(v));
|
||||
z = GetAircraftFlightLevel(v, true);
|
||||
} else if (amd.flag & AMED_HOLD) {
|
||||
/* Let the plane drop from normal flight altitude to holding pattern altitude */
|
||||
if (z > GetAircraftHoldMaxAltitude(v)) z--;
|
||||
} else if ((amd.flag & AMED_SLOWTURN) && (amd.flag & AMED_NOSPDCLAMP)) {
|
||||
z = GetAircraftFlightLevel(v);
|
||||
}
|
||||
|
||||
/* Let the plane drop from normal flight altitude to holding pattern altitude */
|
||||
if ((amd.flag & AMED_HOLD) && (z > PLANE_HOLDING_ALTITUDE)) z--;
|
||||
|
||||
if (amd.flag & AMED_LAND) {
|
||||
if (st->airport.tile == INVALID_TILE) {
|
||||
/* Airport has been removed, abort the landing procedure */
|
||||
@@ -957,7 +1060,7 @@ static bool AircraftController(Aircraft *v)
|
||||
UpdateAircraftCache(v);
|
||||
AircraftNextAirportPos_and_Order(v);
|
||||
/* get aircraft back on running altitude */
|
||||
SetAircraftPosition(v, gp.x, gp.y, GetAircraftFlyingAltitude(v));
|
||||
SetAircraftPosition(v, gp.x, gp.y, GetAircraftFlightLevel(v));
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -1004,7 +1107,7 @@ static bool HandleCrashedAircraft(Aircraft *v)
|
||||
|
||||
/* make aircraft crash down to the ground */
|
||||
if (v->crashed_counter < 500 && st == NULL && ((v->crashed_counter % 3) == 0) ) {
|
||||
int z = GetSlopePixelZ(v->x_pos, v->y_pos);
|
||||
int z = GetSlopePixelZ(Clamp(v->x_pos, 0, MapMaxX() * TILE_SIZE), Clamp(v->y_pos, 0, MapMaxY() * TILE_SIZE));
|
||||
v->z_pos -= 1;
|
||||
if (v->z_pos == z) {
|
||||
v->crashed_counter = 500;
|
||||
@@ -1049,7 +1152,12 @@ static bool HandleCrashedAircraft(Aircraft *v)
|
||||
}
|
||||
|
||||
|
||||
static void HandleAircraftSmoke(Aircraft *v)
|
||||
/**
|
||||
* Handle smoke of broken aircraft.
|
||||
* @param v Aircraft
|
||||
* @param mode Is this the non-first call for this vehicle in this tick?
|
||||
*/
|
||||
static void HandleAircraftSmoke(Aircraft *v, bool mode)
|
||||
{
|
||||
static const struct {
|
||||
int8 x;
|
||||
@@ -1067,13 +1175,15 @@ static void HandleAircraftSmoke(Aircraft *v)
|
||||
|
||||
if (!(v->vehstatus & VS_AIRCRAFT_BROKEN)) return;
|
||||
|
||||
/* Stop smoking when landed */
|
||||
if (v->cur_speed < 10) {
|
||||
v->vehstatus &= ~VS_AIRCRAFT_BROKEN;
|
||||
v->breakdown_ctr = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
if ((v->tick_counter & 0x1F) == 0) {
|
||||
/* Spawn effect et most once per Tick, i.e. !mode */
|
||||
if (!mode && (v->tick_counter & 0x0F) == 0) {
|
||||
CreateEffectVehicleRel(v,
|
||||
smoke_pos[v->direction].x,
|
||||
smoke_pos[v->direction].y,
|
||||
@@ -1126,7 +1236,8 @@ TileIndex Aircraft::GetOrderStationLocation(StationID station)
|
||||
|
||||
void Aircraft::MarkDirty()
|
||||
{
|
||||
this->UpdateViewport(false, false);
|
||||
this->colourmap = PAL_NONE;
|
||||
this->UpdateViewport(true, false);
|
||||
if (this->subtype == AIR_HELICOPTER) this->Next()->Next()->cur_image = GetRotorImage(this, EIT_ON_MAP);
|
||||
}
|
||||
|
||||
@@ -1150,8 +1261,8 @@ static void CrashAirplane(Aircraft *v)
|
||||
uint pass = v->Crash();
|
||||
SetDParam(0, pass);
|
||||
|
||||
v->cargo.Truncate(0);
|
||||
v->Next()->cargo.Truncate(0);
|
||||
v->cargo.Truncate();
|
||||
v->Next()->cargo.Truncate();
|
||||
const Station *st = GetTargetAirportIfValid(v);
|
||||
StringID newsitem;
|
||||
if (st == NULL) {
|
||||
@@ -1164,13 +1275,10 @@ static void CrashAirplane(Aircraft *v)
|
||||
AI::NewEvent(v->owner, new ScriptEventVehicleCrashed(v->index, v->tile, st == NULL ? ScriptEventVehicleCrashed::CRASH_AIRCRAFT_NO_AIRPORT : ScriptEventVehicleCrashed::CRASH_PLANE_LANDING));
|
||||
Game::NewEvent(new ScriptEventVehicleCrashed(v->index, v->tile, st == NULL ? ScriptEventVehicleCrashed::CRASH_AIRCRAFT_NO_AIRPORT : ScriptEventVehicleCrashed::CRASH_PLANE_LANDING));
|
||||
|
||||
AddVehicleNewsItem(newsitem,
|
||||
NS_ACCIDENT,
|
||||
v->index,
|
||||
st != NULL ? st->index : INVALID_STATION);
|
||||
AddVehicleNewsItem(newsitem, NT_ACCIDENT, v->index, st != NULL ? st->index : INVALID_STATION);
|
||||
|
||||
ModifyStationRatingAround(v->tile, v->owner, -160, 30);
|
||||
SndPlayVehicleFx(SND_12_EXPLOSION, v);
|
||||
if (_settings_client.sound.disaster) SndPlayVehicleFx(SND_12_EXPLOSION, v);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1198,7 +1306,7 @@ static void MaybeCrashAirplane(Aircraft *v)
|
||||
/* Crash the airplane. Remove all goods stored at the station. */
|
||||
for (CargoID i = 0; i < NUM_CARGO; i++) {
|
||||
st->goods[i].rating = 1;
|
||||
st->goods[i].cargo.Truncate(0);
|
||||
st->goods[i].cargo.Truncate();
|
||||
}
|
||||
|
||||
CrashAirplane(v);
|
||||
@@ -1223,7 +1331,7 @@ static void AircraftEntersTerminal(Aircraft *v)
|
||||
/* show newsitem of celebrating citizens */
|
||||
AddVehicleNewsItem(
|
||||
STR_NEWS_FIRST_AIRCRAFT_ARRIVAL,
|
||||
(v->owner == _local_company) ? NS_ARRIVAL_COMPANY : NS_ARRIVAL_OTHER,
|
||||
(v->owner == _local_company) ? NT_ARRIVAL_COMPANY : NT_ARRIVAL_OTHER,
|
||||
v->index,
|
||||
st->index
|
||||
);
|
||||
@@ -1374,7 +1482,7 @@ static void AircraftEventHandler_AtTerminal(Aircraft *v, const AirportFTAClass *
|
||||
* and get serviced at the same time - setting */
|
||||
if (_settings_game.order.serviceathelipad) {
|
||||
if (v->subtype == AIR_HELICOPTER && apc->num_helipads > 0) {
|
||||
/* an exerpt of ServiceAircraft, without the invisibility stuff */
|
||||
/* an excerpt of ServiceAircraft, without the invisibility stuff */
|
||||
v->date_of_last_service = _date;
|
||||
v->breakdowns_since_last_service = 0;
|
||||
v->reliability = v->GetEngine()->reliability;
|
||||
@@ -1396,7 +1504,7 @@ static void AircraftEventHandler_AtTerminal(Aircraft *v, const AirportFTAClass *
|
||||
switch (v->current_order.GetType()) {
|
||||
case OT_GOTO_STATION: // ready to fly to another airport
|
||||
break;
|
||||
case OT_GOTO_DEPOT: // visit hangar for serivicing, sale, etc.
|
||||
case OT_GOTO_DEPOT: // visit hangar for servicing, sale, etc.
|
||||
go_to_hangar = v->current_order.GetDestination() == v->targetairport;
|
||||
break;
|
||||
case OT_CONDITIONAL:
|
||||
@@ -1462,8 +1570,8 @@ static void AircraftEventHandler_Flying(Aircraft *v, const AirportFTAClass *apc)
|
||||
{
|
||||
Station *st = Station::Get(v->targetairport);
|
||||
|
||||
/* runway busy or not allowed to use this airstation, circle */
|
||||
if (CanVehicleUseStation(v, st) && IsInfraUsageAllowed(VEH_AIRCRAFT, v->owner, st->owner)) {
|
||||
/* Runway busy, not allowed to use this airstation or closed, circle. */
|
||||
if (CanVehicleUseStation(v, st) && IsInfraUsageAllowed(VEH_AIRCRAFT, v->owner, st->owner) && !(st->airport.flags & AIRPORT_CLOSED_block)) {
|
||||
/* {32,FLYING,NOTHING_block,37}, {32,LANDING,N,33}, {32,HELILANDING,N,41},
|
||||
* if it is an airplane, look for LANDING, for helicopter HELILANDING
|
||||
* it is possible to choose from multiple landing runways, so loop until a free one is found */
|
||||
@@ -1863,7 +1971,7 @@ static void AircraftHandleDestTooFar(Aircraft *v, bool too_far)
|
||||
if (v->owner == _local_company) {
|
||||
/* Post a news message. */
|
||||
SetDParam(0, v->index);
|
||||
AddVehicleNewsItem(STR_NEWS_AIRCRAFT_DEST_TOO_FAR, NS_ADVICE, v->index);
|
||||
AddVehicleAdviceNewsItem(STR_NEWS_AIRCRAFT_DEST_TOO_FAR, v->index);
|
||||
}
|
||||
}
|
||||
return;
|
||||
@@ -1879,8 +1987,6 @@ static void AircraftHandleDestTooFar(Aircraft *v, bool too_far)
|
||||
|
||||
static bool AircraftEventHandler(Aircraft *v, int loop)
|
||||
{
|
||||
v->tick_counter++;
|
||||
|
||||
if (v->vehstatus & VS_CRASHED) {
|
||||
return HandleCrashedAircraft(v);
|
||||
}
|
||||
@@ -1889,7 +1995,7 @@ static bool AircraftEventHandler(Aircraft *v, int loop)
|
||||
|
||||
v->HandleBreakdown();
|
||||
|
||||
HandleAircraftSmoke(v);
|
||||
HandleAircraftSmoke(v, loop != 0);
|
||||
ProcessOrders(v);
|
||||
v->HandleLoading(loop != 0);
|
||||
|
||||
@@ -1919,6 +2025,8 @@ bool Aircraft::Tick()
|
||||
{
|
||||
if (!this->IsNormalAircraft()) return true;
|
||||
|
||||
this->tick_counter++;
|
||||
|
||||
if (!(this->vehstatus & VS_STOPPED)) this->running_ticks++;
|
||||
|
||||
if (this->subtype == AIR_HELICOPTER) HelicopterTickHandler(this);
|
||||
|
@@ -21,6 +21,8 @@
|
||||
|
||||
#include "table/strings.h"
|
||||
|
||||
#include "safeguards.h"
|
||||
|
||||
/**
|
||||
* Draw the details for the given vehicle at the given position
|
||||
*
|
||||
@@ -39,7 +41,7 @@ void DrawAircraftDetails(const Aircraft *v, int left, int right, int y)
|
||||
SetDParam(0, u->engine_type);
|
||||
SetDParam(1, u->build_year);
|
||||
SetDParam(2, u->value);
|
||||
DrawString(left, right, y, STR_VEHICLE_INFO_BUILT_VALUE, TC_FROMSTRING, SA_LEFT | SA_STRIP);
|
||||
DrawString(left, right, y, STR_VEHICLE_INFO_BUILT_VALUE);
|
||||
|
||||
SetDParam(0, u->cargo_type);
|
||||
SetDParam(1, u->cargo_cap);
|
||||
@@ -50,7 +52,7 @@ void DrawAircraftDetails(const Aircraft *v, int left, int right, int y)
|
||||
}
|
||||
|
||||
if (u->cargo_cap != 0) {
|
||||
uint cargo_count = u->cargo.Count();
|
||||
uint cargo_count = u->cargo.StoredCount();
|
||||
|
||||
y_offset += FONT_HEIGHT_NORMAL + 1;
|
||||
if (cargo_count != 0) {
|
||||
@@ -84,22 +86,26 @@ void DrawAircraftImage(const Vehicle *v, int left, int right, int y, VehicleID s
|
||||
SpriteID sprite = v->GetImage(rtl ? DIR_E : DIR_W, image_type);
|
||||
const Sprite *real_sprite = GetSprite(sprite, ST_NORMAL);
|
||||
|
||||
int width = UnScaleByZoom(real_sprite->width, ZOOM_LVL_GUI);
|
||||
int x_offs = UnScaleByZoom(real_sprite->x_offs, ZOOM_LVL_GUI);
|
||||
int width = UnScaleGUI(real_sprite->width);
|
||||
int x_offs = UnScaleGUI(real_sprite->x_offs);
|
||||
int x = rtl ? right - width - x_offs : left - x_offs;
|
||||
bool helicopter = v->subtype == AIR_HELICOPTER;
|
||||
|
||||
int y_offs = ScaleGUITrad(10);
|
||||
int heli_offs = 0;
|
||||
|
||||
PaletteID pal = (v->vehstatus & VS_CRASHED) ? PALETTE_CRASH : GetVehiclePalette(v);
|
||||
DrawSprite(sprite, pal, x, y + 10);
|
||||
DrawSprite(sprite, pal, x, y + y_offs);
|
||||
if (helicopter) {
|
||||
const Aircraft *a = Aircraft::From(v);
|
||||
SpriteID rotor_sprite = GetCustomRotorSprite(a, true, image_type);
|
||||
if (rotor_sprite == 0) rotor_sprite = SPR_ROTOR_STOPPED;
|
||||
DrawSprite(rotor_sprite, PAL_NONE, x, y + 5);
|
||||
heli_offs = ScaleGUITrad(5);
|
||||
DrawSprite(rotor_sprite, PAL_NONE, x, y + y_offs - heli_offs);
|
||||
}
|
||||
if (v->index == selection) {
|
||||
x += x_offs;
|
||||
y += UnScaleByZoom(real_sprite->y_offs, ZOOM_LVL_GUI) + 10 - (helicopter ? 5 : 0);
|
||||
DrawFrameRect(x - 1, y - 1, x + width + 1, y + UnScaleByZoom(real_sprite->height, ZOOM_LVL_GUI) + (helicopter ? 5 : 0) + 1, COLOUR_WHITE, FR_BORDERONLY);
|
||||
y += UnScaleGUI(real_sprite->y_offs) + y_offs - heli_offs;
|
||||
DrawFrameRect(x - 1, y - 1, x + width + 1, y + UnScaleGUI(real_sprite->height) + heli_offs + 1, COLOUR_WHITE, FR_BORDERONLY);
|
||||
}
|
||||
}
|
||||
|
@@ -15,6 +15,8 @@
|
||||
#include "table/airport_movement.h"
|
||||
#include "table/airporttile_ids.h"
|
||||
|
||||
#include "safeguards.h"
|
||||
|
||||
|
||||
/**
|
||||
* Define a generic airport.
|
||||
@@ -22,7 +24,7 @@
|
||||
* @param terminals The terminals.
|
||||
* @param num_helipads Number of heli pads.
|
||||
* @param flags Information about the class of FTA.
|
||||
* @param delta_z Height of the arport above the land.
|
||||
* @param delta_z Height of the airport above the land.
|
||||
*/
|
||||
#define AIRPORT_GENERIC(name, terminals, num_helipads, flags, delta_z) \
|
||||
static AirportFTAClass _airportfta_ ## name(_airport_moving_data_ ## name, terminals, \
|
||||
@@ -41,7 +43,7 @@
|
||||
* Define a heliport.
|
||||
* @param name Suffix of the names of the helipad data.
|
||||
* @param num_helipads Number of heli pads.
|
||||
* @param delta_z Height of the arport above the land.
|
||||
* @param delta_z Height of the airport above the land.
|
||||
*/
|
||||
#define HELIPORT(name, num_helipads, delta_z) \
|
||||
AIRPORT_GENERIC(name, NULL, num_helipads, AirportFTAClass::HELICOPTERS, delta_z)
|
||||
|
@@ -20,7 +20,9 @@ static const uint MAX_TERMINALS = 8; ///< maximum number
|
||||
static const uint MAX_HELIPADS = 3; ///< maximum number of helipads per airport
|
||||
static const uint MAX_ELEMENTS = 255; ///< maximum number of aircraft positions at airport
|
||||
|
||||
static const uint NUM_AIRPORTTILES = 256; ///< total number of airport tiles
|
||||
static const uint NUM_AIRPORTTILES_PER_GRF = 255; ///< Number of airport tiles per NewGRF; limited to 255 to allow extending Action3 with an extended byte later on.
|
||||
|
||||
static const uint NUM_AIRPORTTILES = 256; ///< Total number of airport tiles.
|
||||
static const uint NEW_AIRPORTTILE_OFFSET = 74; ///< offset of first newgrf airport tile
|
||||
static const uint INVALID_AIRPORTTILE = NUM_AIRPORTTILES; ///< id for an invalid airport tile
|
||||
|
||||
@@ -37,7 +39,8 @@ enum AirportTypes {
|
||||
AT_HELISTATION = 8, ///< Heli station airport.
|
||||
AT_OILRIG = 9, ///< Oilrig airport.
|
||||
NEW_AIRPORT_OFFSET = 10, ///< Number of the first newgrf airport.
|
||||
NUM_AIRPORTS = 128, ///< Maximal number of airports.
|
||||
NUM_AIRPORTS_PER_GRF = 128, ///< Maximal number of airports per NewGRF.
|
||||
NUM_AIRPORTS = 128, ///< Maximal number of airports in total.
|
||||
AT_INVALID = 254, ///< Invalid airport.
|
||||
AT_DUMMY = 255, ///< Dummy airport.
|
||||
};
|
||||
@@ -122,7 +125,8 @@ static const uint64
|
||||
OUT_WAY_block2 = 1ULL << 31,
|
||||
/* end of new blocks */
|
||||
|
||||
NOTHING_block = 1ULL << 30;
|
||||
NOTHING_block = 1ULL << 30,
|
||||
AIRPORT_CLOSED_block = 1ULL << 63; ///< Dummy block for indicating a closed airport.
|
||||
|
||||
/** A single location on an airport where aircraft can move to. */
|
||||
struct AirportMovingData {
|
||||
|
@@ -27,9 +27,12 @@
|
||||
#include "core/geometry_func.hpp"
|
||||
#include "hotkeys.h"
|
||||
#include "vehicle_func.h"
|
||||
#include "gui.h"
|
||||
|
||||
#include "widgets/airport_widget.h"
|
||||
|
||||
#include "safeguards.h"
|
||||
|
||||
|
||||
static AirportClassID _selected_airport_class; ///< the currently visible airport class
|
||||
static int _selected_airport_index; ///< the index of the selected airport in the current class or -1
|
||||
@@ -43,7 +46,7 @@ void CcBuildAirport(const CommandCost &result, TileIndex tile, uint32 p1, uint32
|
||||
{
|
||||
if (result.Failed()) return;
|
||||
|
||||
SndPlayTileFx(SND_1F_SPLAT, tile);
|
||||
if (_settings_client.sound.confirm) SndPlayTileFx(SND_1F_SPLAT_OTHER, tile);
|
||||
if (!_settings_client.gui.persistent_buildingtools) ResetObjectToPlace();
|
||||
}
|
||||
|
||||
@@ -57,7 +60,7 @@ static void PlaceAirport(TileIndex tile)
|
||||
uint32 p2 = _ctrl_pressed;
|
||||
SB(p2, 16, 16, INVALID_STATION); // no station to join
|
||||
|
||||
uint32 p1 = AirportClass::Get(_selected_airport_class, _selected_airport_index)->GetIndex();
|
||||
uint32 p1 = AirportClass::Get(_selected_airport_class)->GetSpec(_selected_airport_index)->GetIndex();
|
||||
p1 |= _selected_airport_layout << 8;
|
||||
CommandContainer cmdcont = { tile, p1, p2, CMD_BUILD_AIRPORT | CMD_MSG(STR_ERROR_CAN_T_BUILD_AIRPORT_HERE), CcBuildAirport, "" };
|
||||
ShowSelectStationIfNeeded(cmdcont, TileArea(tile, _thd.size.x / TILE_SIZE, _thd.size.y / TILE_SIZE));
|
||||
@@ -67,9 +70,9 @@ static void PlaceAirport(TileIndex tile)
|
||||
struct BuildAirToolbarWindow : Window {
|
||||
int last_user_action; // Last started user action.
|
||||
|
||||
BuildAirToolbarWindow(const WindowDesc *desc, WindowNumber window_number) : Window()
|
||||
BuildAirToolbarWindow(WindowDesc *desc, WindowNumber window_number) : Window(desc)
|
||||
{
|
||||
this->InitNested(desc, window_number);
|
||||
this->InitNested(window_number);
|
||||
if (_settings_client.gui.link_terraform_toolbar) ShowTerraformToolbar(this);
|
||||
this->last_user_action = WIDGET_LIST_END;
|
||||
}
|
||||
@@ -79,6 +82,18 @@ struct BuildAirToolbarWindow : Window {
|
||||
if (_settings_client.gui.link_terraform_toolbar) DeleteWindowById(WC_SCEN_LAND_GEN, 0, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Some data on this window has become invalid.
|
||||
* @param data Information about the changed data.
|
||||
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
|
||||
*/
|
||||
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
|
||||
{
|
||||
if (!gui_scope) return;
|
||||
|
||||
if (!CanBuildVehicleInfrastructure(VEH_AIRCRAFT)) delete this;
|
||||
}
|
||||
|
||||
virtual void OnClick(Point pt, int widget, int click_count)
|
||||
{
|
||||
switch (widget) {
|
||||
@@ -99,14 +114,6 @@ struct BuildAirToolbarWindow : Window {
|
||||
}
|
||||
|
||||
|
||||
virtual EventState OnKeyPress(uint16 key, uint16 keycode)
|
||||
{
|
||||
int num = CheckHotkeyMatch(airtoolbar_hotkeys, keycode, this);
|
||||
if (num == -1) return ES_NOT_HANDLED;
|
||||
this->OnClick(Point(), num, 1);
|
||||
return ES_HANDLED;
|
||||
}
|
||||
|
||||
virtual void OnPlaceObject(Point pt, TileIndex tile)
|
||||
{
|
||||
switch (this->last_user_action) {
|
||||
@@ -142,15 +149,28 @@ struct BuildAirToolbarWindow : Window {
|
||||
DeleteWindowById(WC_SELECT_STATION, 0);
|
||||
}
|
||||
|
||||
static Hotkey<BuildAirToolbarWindow> airtoolbar_hotkeys[];
|
||||
static HotkeyList hotkeys;
|
||||
};
|
||||
|
||||
Hotkey<BuildAirToolbarWindow> BuildAirToolbarWindow::airtoolbar_hotkeys[] = {
|
||||
Hotkey<BuildAirToolbarWindow>('1', "airport", WID_AT_AIRPORT),
|
||||
Hotkey<BuildAirToolbarWindow>('2', "demolish", WID_AT_DEMOLISH),
|
||||
HOTKEY_LIST_END(BuildAirToolbarWindow)
|
||||
/**
|
||||
* Handler for global hotkeys of the BuildAirToolbarWindow.
|
||||
* @param hotkey Hotkey
|
||||
* @return ES_HANDLED if hotkey was accepted.
|
||||
*/
|
||||
static EventState AirportToolbarGlobalHotkeys(int hotkey)
|
||||
{
|
||||
if (_game_mode != GM_NORMAL || !CanBuildVehicleInfrastructure(VEH_AIRCRAFT)) return ES_NOT_HANDLED;
|
||||
Window *w = ShowBuildAirToolbar();
|
||||
if (w == NULL) return ES_NOT_HANDLED;
|
||||
return w->OnHotkey(hotkey);
|
||||
}
|
||||
|
||||
static Hotkey airtoolbar_hotkeys[] = {
|
||||
Hotkey('1', "airport", WID_AT_AIRPORT),
|
||||
Hotkey('2', "demolish", WID_AT_DEMOLISH),
|
||||
HOTKEY_LIST_END
|
||||
};
|
||||
Hotkey<BuildAirToolbarWindow> *_airtoolbar_hotkeys = BuildAirToolbarWindow::airtoolbar_hotkeys;
|
||||
HotkeyList BuildAirToolbarWindow::hotkeys("airtoolbar", airtoolbar_hotkeys, AirportToolbarGlobalHotkeys);
|
||||
|
||||
static const NWidgetPart _nested_air_toolbar_widgets[] = {
|
||||
NWidget(NWID_HORIZONTAL),
|
||||
@@ -165,11 +185,12 @@ static const NWidgetPart _nested_air_toolbar_widgets[] = {
|
||||
EndContainer(),
|
||||
};
|
||||
|
||||
static const WindowDesc _air_toolbar_desc(
|
||||
WDP_ALIGN_TOOLBAR, 0, 0,
|
||||
static WindowDesc _air_toolbar_desc(
|
||||
WDP_ALIGN_TOOLBAR, "toolbar_air", 0, 0,
|
||||
WC_BUILD_TOOLBAR, WC_NONE,
|
||||
WDF_CONSTRUCTION,
|
||||
_nested_air_toolbar_widgets, lengthof(_nested_air_toolbar_widgets)
|
||||
_nested_air_toolbar_widgets, lengthof(_nested_air_toolbar_widgets),
|
||||
&BuildAirToolbarWindow::hotkeys
|
||||
);
|
||||
|
||||
/**
|
||||
@@ -187,16 +208,6 @@ Window *ShowBuildAirToolbar()
|
||||
return AllocateWindowDescFront<BuildAirToolbarWindow>(&_air_toolbar_desc, TRANSPORT_AIR);
|
||||
}
|
||||
|
||||
EventState AirportToolbarGlobalHotkeys(uint16 key, uint16 keycode)
|
||||
{
|
||||
if (!CanBuildVehicleInfrastructure(VEH_AIRCRAFT)) return ES_NOT_HANDLED;
|
||||
int num = CheckHotkeyMatch<BuildAirToolbarWindow>(_airtoolbar_hotkeys, keycode, NULL, true);
|
||||
if (num == -1) return ES_NOT_HANDLED;
|
||||
Window *w = ShowBuildAirToolbar();
|
||||
if (w == NULL) return ES_NOT_HANDLED;
|
||||
return w->OnKeyPress(key, keycode);
|
||||
}
|
||||
|
||||
class BuildAirportWindow : public PickerWindowBase {
|
||||
SpriteID preview_sprite; ///< Cached airport preview sprite.
|
||||
int line_height;
|
||||
@@ -207,30 +218,49 @@ class BuildAirportWindow : public PickerWindowBase {
|
||||
{
|
||||
DropDownList *list = new DropDownList();
|
||||
|
||||
for (uint i = 0; i < AirportClass::GetCount(); i++) {
|
||||
list->push_back(new DropDownListStringItem(AirportClass::GetName((AirportClassID)i), i, false));
|
||||
for (uint i = 0; i < AirportClass::GetClassCount(); i++) {
|
||||
*list->Append() = new DropDownListStringItem(AirportClass::Get((AirportClassID)i)->name, i, false);
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
public:
|
||||
BuildAirportWindow(const WindowDesc *desc, Window *parent) : PickerWindowBase(parent)
|
||||
BuildAirportWindow(WindowDesc *desc, Window *parent) : PickerWindowBase(desc, parent)
|
||||
{
|
||||
this->CreateNestedTree(desc);
|
||||
this->CreateNestedTree();
|
||||
|
||||
this->vscroll = this->GetScrollbar(WID_AP_SCROLLBAR);
|
||||
this->vscroll->SetCapacity(5);
|
||||
this->vscroll->SetPosition(0);
|
||||
|
||||
this->FinishInitNested(desc, TRANSPORT_AIR);
|
||||
this->FinishInitNested(TRANSPORT_AIR);
|
||||
|
||||
this->SetWidgetLoweredState(WID_AP_BTN_DONTHILIGHT, !_settings_client.gui.station_show_coverage);
|
||||
this->SetWidgetLoweredState(WID_AP_BTN_DOHILIGHT, _settings_client.gui.station_show_coverage);
|
||||
this->OnInvalidateData();
|
||||
|
||||
this->vscroll->SetCount(AirportClass::GetCount(_selected_airport_class));
|
||||
this->SelectFirstAvailableAirport(true);
|
||||
/* Ensure airport class is valid (changing NewGRFs). */
|
||||
_selected_airport_class = Clamp(_selected_airport_class, APC_BEGIN, (AirportClassID)(AirportClass::GetClassCount() - 1));
|
||||
const AirportClass *ac = AirportClass::Get(_selected_airport_class);
|
||||
this->vscroll->SetCount(ac->GetSpecCount());
|
||||
|
||||
/* Ensure the airport index is valid for this class (changing NewGRFs). */
|
||||
_selected_airport_index = Clamp(_selected_airport_index, -1, ac->GetSpecCount() - 1);
|
||||
|
||||
/* Only when no valid airport was selected, we want to select the first airport. */
|
||||
bool selectFirstAirport = true;
|
||||
if (_selected_airport_index != -1) {
|
||||
const AirportSpec *as = ac->GetSpec(_selected_airport_index);
|
||||
if (as->IsAvailable()) {
|
||||
/* Ensure the airport layout is valid. */
|
||||
_selected_airport_layout = Clamp(_selected_airport_layout, 0, as->num_table - 1);
|
||||
selectFirstAirport = false;
|
||||
this->UpdateSelectSize();
|
||||
}
|
||||
}
|
||||
|
||||
if (selectFirstAirport) this->SelectFirstAvailableAirport(true);
|
||||
}
|
||||
|
||||
virtual ~BuildAirportWindow()
|
||||
@@ -242,13 +272,13 @@ public:
|
||||
{
|
||||
switch (widget) {
|
||||
case WID_AP_CLASS_DROPDOWN:
|
||||
SetDParam(0, AirportClass::GetName(_selected_airport_class));
|
||||
SetDParam(0, AirportClass::Get(_selected_airport_class)->name);
|
||||
break;
|
||||
|
||||
case WID_AP_LAYOUT_NUM:
|
||||
SetDParam(0, STR_EMPTY);
|
||||
if (_selected_airport_index != -1) {
|
||||
const AirportSpec *as = AirportClass::Get(_selected_airport_class, _selected_airport_index);
|
||||
const AirportSpec *as = AirportClass::Get(_selected_airport_class)->GetSpec(_selected_airport_index);
|
||||
StringID string = GetAirportTextCallback(as, _selected_airport_layout, CBID_AIRPORT_LAYOUT_NAME);
|
||||
if (string != STR_UNDEFINED) {
|
||||
SetDParam(0, string);
|
||||
@@ -268,8 +298,8 @@ public:
|
||||
switch (widget) {
|
||||
case WID_AP_CLASS_DROPDOWN: {
|
||||
Dimension d = {0, 0};
|
||||
for (uint i = 0; i < AirportClass::GetCount(); i++) {
|
||||
SetDParam(0, AirportClass::GetName((AirportClassID)i));
|
||||
for (uint i = 0; i < AirportClass::GetClassCount(); i++) {
|
||||
SetDParam(0, AirportClass::Get((AirportClassID)i)->name);
|
||||
d = maxdim(d, GetStringBoundingBox(STR_BLACK_STRING));
|
||||
}
|
||||
d.width += padding.width;
|
||||
@@ -287,7 +317,7 @@ public:
|
||||
}
|
||||
|
||||
this->line_height = FONT_HEIGHT_NORMAL + WD_MATRIX_TOP + WD_MATRIX_BOTTOM;
|
||||
size->height = this->vscroll->GetCapacity() * this->line_height;
|
||||
size->height = 5 * this->line_height;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -332,12 +362,13 @@ public:
|
||||
switch (widget) {
|
||||
case WID_AP_AIRPORT_LIST: {
|
||||
int y = r.top;
|
||||
for (uint i = this->vscroll->GetPosition(); this->vscroll->IsVisible(i) && i < AirportClass::GetCount(_selected_airport_class); i++) {
|
||||
const AirportSpec *as = AirportClass::Get(_selected_airport_class, i);
|
||||
AirportClass *apclass = AirportClass::Get(_selected_airport_class);
|
||||
for (uint i = this->vscroll->GetPosition(); this->vscroll->IsVisible(i) && i < apclass->GetSpecCount(); i++) {
|
||||
const AirportSpec *as = apclass->GetSpec(i);
|
||||
if (!as->IsAvailable()) {
|
||||
GfxFillRect(r.left + 1, y + 1, r.right - 1, y + this->line_height - 2, PC_BLACK, FILLRECT_CHECKER);
|
||||
}
|
||||
DrawString(r.left + WD_MATRIX_LEFT, r.right + WD_MATRIX_RIGHT, y + WD_MATRIX_TOP, as->name, ((int)i == _selected_airport_index) ? TC_WHITE : TC_BLACK);
|
||||
DrawString(r.left + WD_MATRIX_LEFT, r.right - WD_MATRIX_RIGHT, y + WD_MATRIX_TOP, as->name, ((int)i == _selected_airport_index) ? TC_WHITE : TC_BLACK);
|
||||
y += this->line_height;
|
||||
}
|
||||
break;
|
||||
@@ -352,7 +383,7 @@ public:
|
||||
|
||||
case WID_AP_EXTRA_TEXT:
|
||||
if (_selected_airport_index != -1) {
|
||||
const AirportSpec *as = AirportClass::Get(_selected_airport_class, _selected_airport_index);
|
||||
const AirportSpec *as = AirportClass::Get(_selected_airport_class)->GetSpec(_selected_airport_index);
|
||||
StringID string = GetAirportTextCallback(as, _selected_airport_layout, CBID_AIRPORT_ADDITIONAL_TEXT);
|
||||
if (string != STR_UNDEFINED) {
|
||||
SetDParam(0, string);
|
||||
@@ -374,7 +405,7 @@ public:
|
||||
int bottom = panel_nwi->pos_y + panel_nwi->current_y;
|
||||
|
||||
if (_selected_airport_index != -1) {
|
||||
const AirportSpec *as = AirportClass::Get(_selected_airport_class, _selected_airport_index);
|
||||
const AirportSpec *as = AirportClass::Get(_selected_airport_class)->GetSpec(_selected_airport_index);
|
||||
int rad = _settings_game.station.modified_catchment ? as->catchment : (uint)CA_UNMODIFIED;
|
||||
|
||||
/* only show the station (airport) noise, if the noise option is activated */
|
||||
@@ -390,9 +421,11 @@ public:
|
||||
top = DrawStationCoverageAreaText(panel_nwi->pos_x + WD_FRAMERECT_LEFT, right - WD_FRAMERECT_RIGHT, top, SCT_ALL, rad, true) + WD_PAR_VSEP_NORMAL;
|
||||
}
|
||||
|
||||
/* Resize background if the text is not equally long as the window. */
|
||||
if (top > bottom || (top < bottom && panel_nwi->current_y > panel_nwi->smallest_y)) {
|
||||
ResizeWindow(this, 0, top - bottom);
|
||||
/* Resize background if the window is too small.
|
||||
* Never make the window smaller to avoid oscillating if the size change affects the acceptance.
|
||||
* (This is the case, if making the window bigger moves the mouse into the window.) */
|
||||
if (top > bottom) {
|
||||
ResizeWindow(this, 0, top - bottom, false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -412,7 +445,7 @@ public:
|
||||
this->DisableWidget(WID_AP_LAYOUT_DECREASE);
|
||||
this->DisableWidget(WID_AP_LAYOUT_INCREASE);
|
||||
} else {
|
||||
const AirportSpec *as = AirportClass::Get(_selected_airport_class, _selected_airport_index);
|
||||
const AirportSpec *as = AirportClass::Get(_selected_airport_class)->GetSpec(_selected_airport_index);
|
||||
int w = as->size_x;
|
||||
int h = as->size_y;
|
||||
Direction rotation = as->rotation[_selected_airport_layout];
|
||||
@@ -439,7 +472,7 @@ public:
|
||||
case WID_AP_AIRPORT_LIST: {
|
||||
int num_clicked = this->vscroll->GetPosition() + (pt.y - this->nested_array[widget]->pos_y) / this->line_height;
|
||||
if (num_clicked >= this->vscroll->GetCount()) break;
|
||||
const AirportSpec *as = AirportClass::Get(_selected_airport_class, num_clicked);
|
||||
const AirportSpec *as = AirportClass::Get(_selected_airport_class)->GetSpec(num_clicked);
|
||||
if (as->IsAvailable()) this->SelectOtherAirport(num_clicked);
|
||||
break;
|
||||
}
|
||||
@@ -449,7 +482,7 @@ public:
|
||||
this->SetWidgetLoweredState(WID_AP_BTN_DONTHILIGHT, !_settings_client.gui.station_show_coverage);
|
||||
this->SetWidgetLoweredState(WID_AP_BTN_DOHILIGHT, _settings_client.gui.station_show_coverage);
|
||||
this->SetDirty();
|
||||
SndPlayFx(SND_15_BEEP);
|
||||
if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
|
||||
this->UpdateSelectSize();
|
||||
break;
|
||||
|
||||
@@ -475,8 +508,9 @@ public:
|
||||
void SelectFirstAvailableAirport(bool change_class)
|
||||
{
|
||||
/* First try to select an airport in the selected class. */
|
||||
for (uint i = 0; i < AirportClass::GetCount(_selected_airport_class); i++) {
|
||||
const AirportSpec *as = AirportClass::Get(_selected_airport_class, i);
|
||||
AirportClass *sel_apclass = AirportClass::Get(_selected_airport_class);
|
||||
for (uint i = 0; i < sel_apclass->GetSpecCount(); i++) {
|
||||
const AirportSpec *as = sel_apclass->GetSpec(i);
|
||||
if (as->IsAvailable()) {
|
||||
this->SelectOtherAirport(i);
|
||||
return;
|
||||
@@ -486,8 +520,9 @@ public:
|
||||
/* If that fails, select the first available airport
|
||||
* from a random class. */
|
||||
for (AirportClassID j = APC_BEGIN; j < APC_MAX; j++) {
|
||||
for (uint i = 0; i < AirportClass::GetCount(j); i++) {
|
||||
const AirportSpec *as = AirportClass::Get(j, i);
|
||||
AirportClass *apclass = AirportClass::Get(j);
|
||||
for (uint i = 0; i < apclass->GetSpecCount(); i++) {
|
||||
const AirportSpec *as = apclass->GetSpec(i);
|
||||
if (as->IsAvailable()) {
|
||||
_selected_airport_class = j;
|
||||
this->SelectOtherAirport(i);
|
||||
@@ -504,7 +539,7 @@ public:
|
||||
{
|
||||
assert(widget == WID_AP_CLASS_DROPDOWN);
|
||||
_selected_airport_class = (AirportClassID)index;
|
||||
this->vscroll->SetCount(AirportClass::GetCount(_selected_airport_class));
|
||||
this->vscroll->SetCount(AirportClass::Get(_selected_airport_class)->GetSpecCount());
|
||||
this->SelectFirstAvailableAirport(false);
|
||||
}
|
||||
|
||||
@@ -522,8 +557,9 @@ static const NWidgetPart _nested_build_airport_widgets[] = {
|
||||
NWidget(WWT_PANEL, COLOUR_DARK_GREEN), SetFill(1, 0), SetPIP(2, 0, 2),
|
||||
NWidget(WWT_LABEL, COLOUR_DARK_GREEN), SetDataTip(STR_STATION_BUILD_AIRPORT_CLASS_LABEL, STR_NULL), SetFill(1, 0),
|
||||
NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_AP_CLASS_DROPDOWN), SetFill(1, 0), SetDataTip(STR_BLACK_STRING, STR_STATION_BUILD_AIRPORT_TOOLTIP),
|
||||
NWidget(WWT_EMPTY, COLOUR_DARK_GREEN, WID_AP_AIRPORT_SPRITE), SetFill(1, 0),
|
||||
NWidget(NWID_HORIZONTAL),
|
||||
NWidget(WWT_MATRIX, COLOUR_GREY, WID_AP_AIRPORT_LIST), SetFill(1, 0), SetDataTip(0x501, STR_STATION_BUILD_AIRPORT_TOOLTIP), SetScrollbar(WID_AP_SCROLLBAR),
|
||||
NWidget(WWT_MATRIX, COLOUR_GREY, WID_AP_AIRPORT_LIST), SetFill(1, 0), SetMatrixDataTip(1, 5, STR_STATION_BUILD_AIRPORT_TOOLTIP), SetScrollbar(WID_AP_SCROLLBAR),
|
||||
NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_AP_SCROLLBAR),
|
||||
EndContainer(),
|
||||
NWidget(NWID_HORIZONTAL),
|
||||
@@ -531,7 +567,6 @@ static const NWidgetPart _nested_build_airport_widgets[] = {
|
||||
NWidget(WWT_LABEL, COLOUR_GREY, WID_AP_LAYOUT_NUM), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_BLACK_STRING, STR_NULL),
|
||||
NWidget(WWT_PUSHARROWBTN, COLOUR_GREY, WID_AP_LAYOUT_INCREASE), SetMinimalSize(12, 0), SetDataTip(AWV_INCREASE, STR_NULL),
|
||||
EndContainer(),
|
||||
NWidget(WWT_EMPTY, COLOUR_DARK_GREEN, WID_AP_AIRPORT_SPRITE), SetFill(1, 0),
|
||||
NWidget(WWT_EMPTY, COLOUR_DARK_GREEN, WID_AP_EXTRA_TEXT), SetFill(1, 0), SetMinimalSize(150, 0),
|
||||
EndContainer(),
|
||||
/* Bottom panel. */
|
||||
@@ -551,10 +586,10 @@ static const NWidgetPart _nested_build_airport_widgets[] = {
|
||||
EndContainer(),
|
||||
};
|
||||
|
||||
static const WindowDesc _build_airport_desc(
|
||||
WDP_AUTO, 0, 0,
|
||||
static WindowDesc _build_airport_desc(
|
||||
WDP_AUTO, "build_station_air", 0, 0,
|
||||
WC_BUILD_STATION, WC_BUILD_TOOLBAR,
|
||||
WDF_CONSTRUCTION | WDF_UNCLICK_BUTTONS,
|
||||
WDF_CONSTRUCTION,
|
||||
_nested_build_airport_widgets, lengthof(_nested_build_airport_widgets)
|
||||
);
|
||||
|
||||
|
@@ -14,6 +14,8 @@
|
||||
#include "tile_cmd.h"
|
||||
#include "viewport_func.h"
|
||||
|
||||
#include "safeguards.h"
|
||||
|
||||
/** The table/list with animated tiles. */
|
||||
TileIndex *_animated_tile_list = NULL;
|
||||
/** The number of animated tiles in the current state. */
|
||||
|
@@ -19,6 +19,8 @@
|
||||
|
||||
#include "table/strings.h"
|
||||
|
||||
#include "safeguards.h"
|
||||
|
||||
static const uint MAX_ARTICULATED_PARTS = 100; ///< Maximum of articulated parts per vehicle, i.e. when to abort calling the articulated vehicle callback.
|
||||
|
||||
/**
|
||||
@@ -68,7 +70,7 @@ bool IsArticulatedEngine(EngineID engine_type)
|
||||
* Count the number of articulated parts of an engine.
|
||||
* @param engine_type The engine to get the number of parts of.
|
||||
* @param purchase_window Whether we are in the scope of the purchase window or not, i.e. whether we cannot allocate vehicles.
|
||||
* @return The nmumber of parts.
|
||||
* @return The number of parts.
|
||||
*/
|
||||
uint CountArticulatedParts(EngineID engine_type, bool purchase_window)
|
||||
{
|
||||
@@ -98,7 +100,7 @@ uint CountArticulatedParts(EngineID engine_type, bool purchase_window)
|
||||
|
||||
/**
|
||||
* Returns the default (non-refitted) capacity of a specific EngineID.
|
||||
* @param engine the EngineID of iterest
|
||||
* @param engine the EngineID of interest
|
||||
* @param cargo_type returns the default cargo type, if needed
|
||||
* @return capacity
|
||||
*/
|
||||
@@ -113,7 +115,7 @@ static inline uint16 GetVehicleDefaultCapacity(EngineID engine, CargoID *cargo_t
|
||||
|
||||
/**
|
||||
* Returns all cargoes a vehicle can carry.
|
||||
* @param engine the EngineID of iterest
|
||||
* @param engine the EngineID of interest
|
||||
* @param include_initial_cargo_type if true the default cargo type of the vehicle is included; if false only the refit_mask
|
||||
* @return bit set of CargoIDs
|
||||
*/
|
||||
@@ -160,6 +162,41 @@ CargoArray GetCapacityOfArticulatedParts(EngineID engine)
|
||||
return capacity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default cargoes and refits of an articulated vehicle.
|
||||
* The refits are linked to a cargo rather than an articulated part to prevent a long list of parts.
|
||||
* @param engine Model to investigate.
|
||||
* @param[out] cargoes Total amount of units that can be transported, summed by cargo.
|
||||
* @param[out] refits Whether a (possibly partial) refit for each cargo is possible.
|
||||
*/
|
||||
void GetArticulatedVehicleCargoesAndRefits(EngineID engine, CargoArray *cargoes, uint32 *refits)
|
||||
{
|
||||
cargoes->Clear();
|
||||
*refits = 0;
|
||||
|
||||
const Engine *e = Engine::Get(engine);
|
||||
|
||||
CargoID cargo_type;
|
||||
uint16 cargo_capacity = GetVehicleDefaultCapacity(engine, &cargo_type);
|
||||
if (cargo_type < NUM_CARGO && cargo_capacity > 0) {
|
||||
(*cargoes)[cargo_type] += cargo_capacity;
|
||||
if (IsEngineRefittable(engine)) SetBit(*refits, cargo_type);
|
||||
}
|
||||
|
||||
if (!e->IsGroundVehicle() || !HasBit(e->info.callback_mask, CBM_VEHICLE_ARTIC_ENGINE)) return;
|
||||
|
||||
for (uint i = 1; i < MAX_ARTICULATED_PARTS; i++) {
|
||||
EngineID artic_engine = GetNextArticulatedPart(i, engine);
|
||||
if (artic_engine == INVALID_ENGINE) break;
|
||||
|
||||
cargo_capacity = GetVehicleDefaultCapacity(artic_engine, &cargo_type);
|
||||
if (cargo_type < NUM_CARGO && cargo_capacity > 0) {
|
||||
(*cargoes)[cargo_type] += cargo_capacity;
|
||||
if (IsEngineRefittable(artic_engine)) SetBit(*refits, cargo_type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether any of the articulated parts is refittable
|
||||
* @param engine the first part
|
||||
@@ -355,6 +392,7 @@ void AddArticulatedParts(Vehicle *first)
|
||||
t->cargo_type = front->cargo_type; // Needed for livery selection
|
||||
t->cargo_cap = 0;
|
||||
}
|
||||
t->refit_cap = 0;
|
||||
|
||||
t->SetArticulatedPart();
|
||||
break;
|
||||
@@ -381,6 +419,7 @@ void AddArticulatedParts(Vehicle *first)
|
||||
rv->cargo_type = front->cargo_type; // Needed for livery selection
|
||||
rv->cargo_cap = 0;
|
||||
}
|
||||
rv->refit_cap = 0;
|
||||
|
||||
rv->SetArticulatedPart();
|
||||
break;
|
||||
@@ -406,6 +445,6 @@ void AddArticulatedParts(Vehicle *first)
|
||||
|
||||
if (flip_image) v->spritenum++;
|
||||
|
||||
VehicleUpdatePosition(v);
|
||||
v->UpdatePosition();
|
||||
}
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user