Releasing lua-1.1.0

This commit is contained in:
Xinchen Hui
2013-10-23 12:20:42 +08:00
parent 781e123f5c
commit 5f0c471ea6
8 changed files with 133 additions and 23 deletions

68
LICENSE Normal file
View File

@@ -0,0 +1,68 @@
--------------------------------------------------------------------
The PHP License, version 3.01
Copyright (c) 1999 - 2011 The PHP Group. All rights reserved.
--------------------------------------------------------------------
Redistribution and use in source and binary forms, with or without
modification, is 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. The name "PHP" must not be used to endorse or promote products
derived from this software without prior written permission. For
written permission, please contact group@php.net.
4. Products derived from this software may not be called "PHP", nor
may "PHP" appear in their name, without prior written permission
from group@php.net. You may indicate that your software works in
conjunction with PHP by saying "Foo for PHP" instead of calling
it "PHP Foo" or "phpfoo"
5. The PHP Group may publish revised and/or new versions of the
license from time to time. Each version will be given a
distinguishing version number.
Once covered code has been published under a particular version
of the license, you may always continue to use it under the terms
of that version. You may also choose to use such covered code
under the terms of any subsequent version of the license
published by the PHP Group. No one other than the PHP Group has
the right to modify the terms applicable to covered code created
under this License.
6. Redistributions of any form whatsoever must retain the following
acknowledgment:
"This product includes PHP software, freely available from
<http://www.php.net/software/>".
THIS SOFTWARE IS PROVIDED BY THE PHP DEVELOPMENT TEAM ``AS IS'' AND
ANY EXPRESSED 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 PHP
DEVELOPMENT TEAM OR ITS 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.
--------------------------------------------------------------------
This software consists of voluntary contributions made by many
individuals on behalf of the PHP Group.
The PHP Group can be contacted via Email at group@php.net.
For more information on the PHP Group and the PHP project,
please see <http://www.php.net>.
PHP includes the Zend Engine, freely available at
<http://www.zend.com>.

26
lua.c
View File

@@ -638,7 +638,7 @@ static zval * php_lua_call_lua_function(zval *lua_obj, zval *func, zval *args, i
zend_hash_apply_with_argument(Z_ARRVAL_P(args), php_lua_arg_apply_func, (void *)L TSRMLS_CC); zend_hash_apply_with_argument(Z_ARRVAL_P(args), php_lua_arg_apply_func, (void *)L TSRMLS_CC);
} }
if (lua_pcall(L, arg_num, LUA_MULTRET, 0) != 0) { if (lua_pcall(L, arg_num, LUA_MULTRET, 0) != LUA_OK) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, php_error_docref(NULL TSRMLS_CC, E_WARNING,
"call to lua function %s failed", lua_tostring(L, -1)); "call to lua function %s failed", lua_tostring(L, -1));
lua_pop(L, lua_gettop(L) - bp); lua_pop(L, lua_gettop(L) - bp);
@@ -678,6 +678,7 @@ PHP_METHOD(lua, eval) {
lua_State *L = NULL; lua_State *L = NULL;
char *statements = NULL; char *statements = NULL;
long bp, len = 0; long bp, len = 0;
int ret;
L = Z_LUAVAL_P(getThis()); L = Z_LUAVAL_P(getThis());
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &statements, &len) == FAILURE) { if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &statements, &len) == FAILURE) {
@@ -685,9 +686,8 @@ PHP_METHOD(lua, eval) {
} }
bp = lua_gettop(L); bp = lua_gettop(L);
if (luaL_loadbuffer(L, statements, len, "line") || lua_pcall(L, 0, LUA_MULTRET, 0)) { if ((ret = luaL_loadbuffer(L, statements, len, "line")) != LUA_OK || (ret = lua_pcall(L, 0, LUA_MULTRET, 0) != LUA_OK)) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, zend_throw_exception_ex(lua_exception_ce, ret TSRMLS_CC, "%s", lua_tostring(L, -1));
"lua error: %s", lua_tostring(L, -1));
lua_pop(L, 1); lua_pop(L, 1);
RETURN_FALSE; RETURN_FALSE;
} else { } else {
@@ -718,6 +718,7 @@ PHP_METHOD(lua, include) {
lua_State *L = NULL; lua_State *L = NULL;
char *file = NULL; char *file = NULL;
long bp, len = 0; long bp, len = 0;
int ret;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &file, &len) == FAILURE) { if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &file, &len) == FAILURE) {
return; return;
@@ -728,16 +729,15 @@ PHP_METHOD(lua, include) {
|| (PG(safe_mode) || (PG(safe_mode)
&& !php_checkuid(file, "rb+", CHECKUID_CHECK_MODE_PARAM)) && !php_checkuid(file, "rb+", CHECKUID_CHECK_MODE_PARAM))
#endif #endif
){ ) {
RETURN_FALSE; RETURN_FALSE;
} }
L = Z_LUAVAL_P(getThis()); L = Z_LUAVAL_P(getThis());
bp = lua_gettop(L); bp = lua_gettop(L);
if (luaL_dofile(L, file)) { if ((ret = luaL_loadfile(L, file)) != LUA_OK || (ret = lua_pcall(L, 0, LUA_MULTRET, 0) != LUA_OK)) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, zend_throw_exception_ex(lua_exception_ce, ret TSRMLS_CC, "%s", lua_tostring(L, -1));
"lua error: %s", lua_tostring(L, -1));
lua_pop(L, 1); lua_pop(L, 1);
RETURN_FALSE; RETURN_FALSE;
} else { } else {
@@ -887,6 +887,16 @@ PHP_MINIT_FUNCTION(lua) {
INIT_CLASS_ENTRY(ce, "Lua", lua_class_methods); INIT_CLASS_ENTRY(ce, "Lua", lua_class_methods);
REGISTER_LONG_CONSTANT("LUA_OK", LUA_OK, CONST_PERSISTENT | CONST_CS);
REGISTER_LONG_CONSTANT("LUA_YIELD", LUA_YIELD, CONST_PERSISTENT | CONST_CS);
REGISTER_LONG_CONSTANT("LUA_ERRRUN", LUA_ERRRUN, CONST_PERSISTENT | CONST_CS);
REGISTER_LONG_CONSTANT("LUA_ERRSYNTAX", LUA_ERRSYNTAX, CONST_PERSISTENT | CONST_CS);
REGISTER_LONG_CONSTANT("LUA_ERRMEM", LUA_ERRMEM, CONST_PERSISTENT | CONST_CS);
REGISTER_LONG_CONSTANT("LUA_ERRGCMM", LUA_ERRGCMM, CONST_PERSISTENT | CONST_CS);
REGISTER_LONG_CONSTANT("LUA_ERRERR", LUA_ERRERR, CONST_PERSISTENT | CONST_CS);
REGISTER_LONG_CONSTANT("LUA_ERRFILE", LUA_ERRFILE, CONST_PERSISTENT | CONST_CS);
lua_ce = zend_register_internal_class(&ce TSRMLS_CC); lua_ce = zend_register_internal_class(&ce TSRMLS_CC);
lua_ce->create_object = php_lua_create_object; lua_ce->create_object = php_lua_create_object;
memcpy(&lua_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); memcpy(&lua_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));

View File

@@ -58,6 +58,7 @@
<file role="src" name="config.w32"/> <file role="src" name="config.w32"/>
<file role="src" name="CREDITS"/> <file role="src" name="CREDITS"/>
<file role="src" name="EXPERIMENTAL"/> <file role="src" name="EXPERIMENTAL"/>
<file role="src" name="LICENSE"/>
<file role="src" name="lua.c"/> <file role="src" name="lua.c"/>
<file role="src" name="lua_closure.c"/> <file role="src" name="lua_closure.c"/>
<file role="src" name="lua_closure.h"/> <file role="src" name="lua_closure.h"/>

View File

@@ -26,8 +26,8 @@
<date>2013-10-23</date> <date>2013-10-23</date>
<time>12:04:27</time> <time>12:04:27</time>
<version> <version>
<release>0.9.5</release> <release>1.1.0</release>
<api>0.9.5</api> <api>1.1.0</api>
</version> </version>
<stability> <stability>
<release>beta</release> <release>beta</release>
@@ -49,6 +49,7 @@
<file name="config.w32" role="src" /> <file name="config.w32" role="src" />
<file name="CREDITS" role="src" /> <file name="CREDITS" role="src" />
<file name="EXPERIMENTAL" role="src" /> <file name="EXPERIMENTAL" role="src" />
<file name="LICENSE" role="src" />
<dir name="tests"> <dir name="tests">
<file name="001.phpt" role="test" /> <file name="001.phpt" role="test" />
<file name="002.phpt" role="test" /> <file name="002.phpt" role="test" />
@@ -82,8 +83,8 @@
<release> <release>
<date>2012-10-23</date> <date>2012-10-23</date>
<version> <version>
<release>0.9.5</release> <release>1.1.0</release>
<api>0.9.5</api> <api>1.1.0</api>
</version> </version>
<stability> <stability>
<release>beta</release> <release>beta</release>
@@ -97,6 +98,21 @@
</notes> </notes>
</release> </release>
<release>
<date>2012-06-24</date>
<version>
<release>1.0.0</release>
<api>1.0.0</api>
</version>
<stability>
<release>stable</release>
<api>stable</api>
</stability>
<license uri="http://www.php.net/license">PHP License</license>
<notes>
- Release stable version
</notes>
</release>
<release> <release>
<date>2012-03-19</date> <date>2012-03-19</date>
<version> <version>

View File

@@ -49,7 +49,7 @@ extern zend_module_entry lua_module_entry;
#define Z_DELREF_P ZVAL_DELREF #define Z_DELREF_P ZVAL_DELREF
#endif #endif
#define PHP_LUA_VERSION "0.9.6-dev" #define PHP_LUA_VERSION "1.1.0"
#define Z_LUAVAL_P(obj) ((php_lua_object*)(zend_object_store_get_object(obj TSRMLS_CC)))->L #define Z_LUAVAL_P(obj) ((php_lua_object*)(zend_object_store_get_object(obj TSRMLS_CC)))->L
struct _php_lua_object { struct _php_lua_object {

View File

@@ -9,8 +9,13 @@ $l->assign("b", 12);
$l->eval("print(b)"); $l->eval("print(b)");
$l->eval('print("\n")'); $l->eval('print("\n")');
$l->eval("print(math.sin(b))"); $l->eval("print(math.sin(b))");
$l->eval("invalid code"); try {
$l->eval("invalid code");
} catch (LuaException $e) {
assert($e->getCode() == LUA_ERRSYNTAX);
echo "\n", $e->getMessage();
}
--EXPECTF-- --EXPECTF--
12 12
-0.53657291800043 -0.53657291800043
Warning: Lua::eval(): lua error: [string "line"]:1: %s near 'code' in %s on line %d [string "line"]:1: syntax error near 'code'

View File

@@ -17,19 +17,22 @@ $l = new lua();
foreach ($code as $n => $c) { foreach ($code as $n => $c) {
echo "\nTesting $n\n"; echo "\nTesting $n\n";
file_put_contents($filename, $c); file_put_contents($filename, $c);
$ret = $l->include($filename); try {
if ($ret) print_r($ret); $ret = $l->include($filename);
if ($ret) print_r($ret);
} catch (LuaException $e) {
assert($e->getCode() == LUA_ERRSYNTAX);
echo "\n".$e->getMessage();
}
@unlink($filename); @unlink($filename);
} }
?> ?>
--EXPECTF-- --EXPECTF--
Testing fine Testing fine
Hello PHP Hello PHP
Testing broken Testing broken
Warning: Lua::include(): lua error: %s near 'fdrg' in %s on line %d %s:%d: syntax error near 'fdrg'
Testing return Testing return
Array Array
( (

View File

@@ -1,11 +1,18 @@
--TEST-- --TEST--
Check for index 0 Lua::include() with error codes
--SKIPIF-- --SKIPIF--
<?php if (!extension_loaded("lua")) print "skip"; ?> <?php if (!extension_loaded("lua")) print "skip"; ?>
--FILE-- --FILE--
<?php <?php
$filename = __FILE__.'.tmp';
$l = new lua(); $l = new lua();
$l->assign("b", range(1, 0)); try {
$ret = $l->include($filename);
} catch (LuaException $e) {
assert($e->getCode() == LUA_ERRFILE);
echo "\n".$e->getMessage();
}
?> ?>
--EXPECTF-- --EXPECTF--
Strict Standards: Lua::assign(): attempt to pass an array index begin with 0 to lua in %s012.php on line %d cannot open %s012.php.tmp: No such file or directory