27 Commits

Author SHA1 Message Date
Xinchen Hui
e350b425f4 release 2.0.4 2017-07-12 11:42:06 +08:00
Xinchen Hui
527f927ead Fixed bug #73964 (Segmentation fault (11)) 2017-02-12 10:53:36 +08:00
Xinchen Hui
9be57325c6 back to dev 2017-02-10 19:14:10 +08:00
Xinchen Hui
1ff1eb10c9 releaseing 2.0.3 2017-02-10 19:13:44 +08:00
Xinchen Hui
cbe65b9ad6 Fixed issue #20 (PHP 7: Lua::eval(): unsupported type `unknown' for lua) 2016-05-30 11:44:12 +08:00
Xinchen Hui
04f7106631 back to dev 2016-05-26 17:42:59 +08:00
Xinchen Hui
7406b07f2c Prepare for 2.0.2 2016-05-26 17:42:22 +08:00
Xinchen Hui
17cbba8b77 Fixed issue #22 (Boolean FALSE is always TRUE) 2016-05-20 11:54:37 +08:00
Xinchen Hui
7cdb287c33 back to dev 2016-04-11 10:55:22 +08:00
Xinchen Hui
f3d6dca1a0 Prepareing for 2.0.1 2016-04-11 10:54:41 +08:00
Xinchen Hui
f177b21ff1 Added tests for bug #71997 2016-04-11 10:51:15 +08:00
Xinchen Hui
c7d9844cf1 Fixed default searching in centOS 2016-04-11 10:50:28 +08:00
Xinchen Hui
12c53f28eb Fixed nApplyCount checking 2016-04-11 10:37:11 +08:00
Xinchen Hui
86cb62e0b8 Merge pull request #19 from tony2001/php7_fixes
fix send_zval_to_lua()
2016-04-07 19:14:59 +08:00
Antony Dovgal
dc226c345d fix send_zval_to_lua() 2016-03-31 12:56:15 +03:00
Xinchen Hui
2d23b565e5 Merge branch 'master' into php7
Conflicts:
	README.md
2015-10-26 21:11:38 -07:00
Xinchen Hui
6a2bf0e8af Update README 2015-10-26 21:11:12 -07:00
Xinchen Hui
230a8af900 Update README 2015-10-26 21:10:51 -07:00
Xinchen Hui
468203ce7c Merge branch 'master' into php7 2015-10-26 21:05:54 -07:00
Xinchen Hui
aaf49be301 trigger triavis 2015-10-26 21:05:41 -07:00
Xinchen Hui
1bd4adf039 No valgrind is valiable 2015-10-26 20:59:34 -07:00
Xinchen Hui
18e2bb493d enable full test 2015-10-26 20:56:56 -07:00
Xinchen Hui
0b28ef4f55 Merge branch 'master' into php7
Conflicts:
	.travis.yml
	travis/compile.sh
2015-10-26 20:56:19 -07:00
Xinchen Hui
d3323aa9fe enable travis 2015-10-26 20:54:55 -07:00
Xinchen Hui
f6a2f09b19 User hjanuschka doesn't exists? 2015-10-27 11:16:04 +08:00
Xinchen Hui
6c2a37f99c back to dev 2015-10-27 11:14:10 +08:00
Xinchen Hui
50d32564d2 Master is only for PHP5.X now 2015-02-25 22:23:05 +08:00
10 changed files with 224 additions and 59 deletions

View File

@@ -1,21 +1,23 @@
language: php language: php
addons:
apt:
packages:
- liblua5.2-dev
php: php:
- 5.6 - 7.0
- 5.5
- 5.4
- 5.3
- 5.3.3
before_install: notifications:
- sudo apt-get update -qq email: false
- sudo apt-get install -y libjson0-dev libjson0 php5-cli php5-dev liblua5.2-dev irc: "irc.efnet.org#php.yaf"
env:
- REPORT_EXIT_STATUS=1 NO_INTERACTION=1
#Compile
before_script: before_script:
# Compile PHP
- ./travis/compile.sh - ./travis/compile.sh
script: # Run PHPs run-tests.php
- ./travis/build_check.sh script: TEST_PHP_ARGS="--show-diff" make test

View File

@@ -1,2 +1,6 @@
"Lua is a powerful, fast, light-weight, embeddable scripting language." # PHP Lua
[![Build Status](https://secure.travis-ci.org/laruence/php-lua.png)](https://travis-ci.org/laruence/php-lua)
This extension embeds the lua interpreter and offers an OO-API to lua variables and functions. This extension embeds the lua interpreter and offers an OO-API to lua variables and functions.
"Lua is a powerful, fast, light-weight, embeddable scripting language."

View File

@@ -3,6 +3,8 @@ PHP_ARG_WITH(lua, for lua support,
[ --with-lua=[DIR] Include php lua support]) [ --with-lua=[DIR] Include php lua support])
PHP_ARG_WITH(lua-version, to specify a custom lua version, [ --with-lua-version=[VERSION]] Use the specified lua version.) PHP_ARG_WITH(lua-version, to specify a custom lua version, [ --with-lua-version=[VERSION]] Use the specified lua version.)
PHP_ARG_WITH(lua-version, to specify a custom lua version, [ --with-lua-version=[VERSION]] Use the specified lua version.)
if test "$PHP_LUA" != "no"; then if test "$PHP_LUA" != "no"; then
if test -r $PHP_LUA/include/lua.h; then if test -r $PHP_LUA/include/lua.h; then
LUA_INCLUDE_DIR=$PHP_LUA/include LUA_INCLUDE_DIR=$PHP_LUA/include
@@ -15,6 +17,12 @@ if test "$PHP_LUA" != "no"; then
break break
fi fi
if test -r $i/include/lua.h; then
LUA_INCLUDE_DIR=$i/include
AC_MSG_RESULT(found in $i)
break
fi
if test "$PHP_LUA_VERSION" != "yes"; then if test "$PHP_LUA_VERSION" != "yes"; then
if test -r $i/include/lua$PHP_LUA_VERSION/lua.h; then if test -r $i/include/lua$PHP_LUA_VERSION/lua.h; then
LUA_INCLUDE_DIR=$i/include/lua$PHP_LUA_VERSION LUA_INCLUDE_DIR=$i/include/lua$PHP_LUA_VERSION

47
lua.c
View File

@@ -174,6 +174,11 @@ static void php_lua_dtor_object(zend_object *object) /* {{{ */ {
php_lua_object *lua_obj = php_lua_obj_from_obj(object); php_lua_object *lua_obj = php_lua_obj_from_obj(object);
zend_object_std_dtor(&(lua_obj->obj)); zend_object_std_dtor(&(lua_obj->obj));
}
/* }}} */
static void php_lua_free_object(zend_object *object) /* {{{ */ {
php_lua_object *lua_obj = php_lua_obj_from_obj(object);
if (lua_obj->L) { if (lua_obj->L) {
lua_close(lua_obj->L); lua_close(lua_obj->L);
@@ -351,7 +356,7 @@ zval *php_lua_get_zval_from_lua(lua_State *L, int index, zval *lua_obj, zval *rv
break; break;
} }
switch(Z_TYPE(key)) { switch (Z_TYPE(key)) {
case IS_DOUBLE: case IS_DOUBLE:
case IS_LONG: case IS_LONG:
add_index_zval(rv, Z_DVAL(key), &val); add_index_zval(rv, Z_DVAL(key), &val);
@@ -401,11 +406,15 @@ zval *php_lua_get_zval_from_lua(lua_State *L, int index, zval *lua_obj, zval *rv
int php_lua_send_zval_to_lua(lua_State *L, zval *val) /* {{{ */ { int php_lua_send_zval_to_lua(lua_State *L, zval *val) /* {{{ */ {
try_again:
switch (Z_TYPE_P(val)) { switch (Z_TYPE_P(val)) {
case IS_TRUE: case IS_TRUE:
case IS_FALSE: lua_pushboolean(L, 1);
lua_pushboolean(L, Z_LVAL_P(val));
break; break;
case IS_FALSE:
lua_pushboolean(L, 0);
break;
case IS_UNDEF:
case IS_NULL: case IS_NULL:
lua_pushnil(L); lua_pushnil(L);
break; break;
@@ -437,32 +446,46 @@ int php_lua_send_zval_to_lua(lua_State *L, zval *val) /* {{{ */ {
add_next_index_zval(callbacks, val); add_next_index_zval(callbacks, val);
} else { } else {
zval *v; zval *v;
ulong longkey;
zend_string *key; zend_string *key;
zval zkey; zval zkey;
HashTable *ht = HASH_OF(val); HashTable *ht = HASH_OF(val);
if (++ht->u.v.nApplyCount > 1) { if (ZEND_HASH_APPLY_PROTECTION(ht)) {
ZEND_HASH_INC_APPLY_COUNT(ht);
if (ZEND_HASH_GET_APPLY_COUNT(ht) > 1) {
php_error_docref(NULL, E_ERROR, "recursion found"); php_error_docref(NULL, E_ERROR, "recursion found");
--ht->u.v.nApplyCount; ZEND_HASH_DEC_APPLY_COUNT(ht);
break; break;
} }
}
lua_newtable(L); lua_newtable(L);
ZEND_HASH_FOREACH_STR_KEY_VAL(ht, key, v) { ZEND_HASH_FOREACH_KEY_VAL_IND(ht, longkey, key, v) {
if (Z_TYPE_P(v) == IS_STRING) { if (key) {
ZVAL_STR(&zkey, key); ZVAL_STR(&zkey, key);
} } else {
if (Z_TYPE_P(v) == IS_LONG) { ZVAL_LONG(&zkey, longkey);
ZVAL_LONG(&zkey, Z_LVAL_P(v));
} }
php_lua_send_zval_to_lua(L, &zkey); php_lua_send_zval_to_lua(L, &zkey);
php_lua_send_zval_to_lua(L, v); php_lua_send_zval_to_lua(L, v);
lua_settable(L, -3); lua_settable(L, -3);
} ZEND_HASH_FOREACH_END(); } ZEND_HASH_FOREACH_END();
--ht->u.v.nApplyCount; if (ZEND_HASH_APPLY_PROTECTION(ht)) {
ZEND_HASH_DEC_APPLY_COUNT(ht);
} }
} }
}
break;
case IS_REFERENCE:
ZVAL_DEREF(val);
goto try_again;
break;
case IS_INDIRECT:
val = Z_INDIRECT_P(val);
goto try_again;
break; break;
default: default:
php_error_docref(NULL, E_ERROR, "unsupported type `%s' for lua", zend_zval_type_name(val)); php_error_docref(NULL, E_ERROR, "unsupported type `%s' for lua", zend_zval_type_name(val));
@@ -813,7 +836,7 @@ PHP_MINIT_FUNCTION(lua) {
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));
lua_object_handlers.offset = XtOffsetOf(php_lua_object, obj); lua_object_handlers.offset = XtOffsetOf(php_lua_object, obj);
lua_object_handlers.dtor_obj = php_lua_dtor_object; lua_object_handlers.dtor_obj = php_lua_dtor_object;
lua_object_handlers.free_obj = NULL; lua_object_handlers.free_obj = php_lua_free_object;
lua_object_handlers.clone_obj = NULL; lua_object_handlers.clone_obj = NULL;
lua_object_handlers.write_property = php_lua_write_property; lua_object_handlers.write_property = php_lua_write_property;
lua_object_handlers.read_property = php_lua_read_property; lua_object_handlers.read_property = php_lua_read_property;

View File

@@ -23,25 +23,19 @@
<email>msaraujo@php.net</email> <email>msaraujo@php.net</email>
<active>yes</active> <active>yes</active>
</developer> </developer>
<developer> <date>2017-07-12</date>
<name>Helmut Januschka</name> <time>19:15:00</time>
<user>hjanuschka</user>
<email>helmut@januschka.com</email>
<active>yes</active>
</developer>
<date>2015-10-27</date>
<time>11:12:27</time>
<version> <version>
<release>2.0.0</release> <release>2.0.4</release>
<api>2.0.0</api> <api>2.0.4</api>
</version> </version>
<stability> <stability>
<release>beta</release> <release>stable</release>
<api>beta</api> <api>stable</api>
</stability> </stability>
<license uri="http://www.php.net/license">PHP</license> <license uri="http://www.php.net/license">PHP</license>
<notes> <notes>
- Release lua for PHP7 - Fixed bug #73964 (Segmentation fault)
</notes> </notes>
<contents> <contents>
<dir name="/"> <dir name="/">
@@ -68,7 +62,10 @@
<file name="011.phpt" role="test" /> <file name="011.phpt" role="test" />
<file name="012.phpt" role="test" /> <file name="012.phpt" role="test" />
<file name="013.phpt" role="test" /> <file name="013.phpt" role="test" />
<file name="issue012.phpt" role="test" />
<file name="bug65097.phpt" role="test" /> <file name="bug65097.phpt" role="test" />
<file name="bug71997.phpt" role="test" />
<file name="bug73964.phpt" role="test" />
</dir> </dir>
</dir> </dir>
</contents> </contents>
@@ -85,6 +82,68 @@
<providesextension>lua</providesextension> <providesextension>lua</providesextension>
<extsrcrelease /> <extsrcrelease />
<changelog> <changelog>
<release>
<date>2017-02-10</date>
<version>
<release>2.0.3</release>
<api>2.0.3</api>
</version>
<stability>
<release>stable</release>
<api>stable</api>
</stability>
<license uri="http://www.php.net/license">PHP License</license>
<notes>
- Fixed issue #20 (PHP 7: Lua::eval(): unsupported type `unknown' for lua)
</notes>
</release>
<release>
<date>2017-07-12</date>
<version>
<release>2.0.4</release>
<api>2.0.4</api>
</version>
<stability>
<release>stable</release>
<api>stable</api>
</stability>
<license uri="http://www.php.net/license">PHP License</license>
<notes>
- Fixed bug #73964 (Segmentation fault)
</notes>
</release>
<release>
<date>2016-05-26</date>
<version>
<release>2.0.2</release>
<api>2.0.2</api>
</version>
<stability>
<release>stable</release>
<api>stable</api>
</stability>
<license uri="http://www.php.net/license">PHP License</license>
<notes>
- Fixed issue #22 (Boolean FALSE is always TRUE)
</notes>
</release>
<release>
<date>2016-04-11</date>
<version>
<release>2.0.1</release>
<api>2.0.1</api>
</version>
<stability>
<release>beta</release>
<api>beta</api>
</stability>
<license uri="http://www.php.net/license">PHP License</license>
<notes>
- Fixed bug #71997 (One-Dimensional arrays cause segmentation faults)
</notes>
</release>
<release> <release>
<date>2015-10-27</date> <date>2015-10-27</date>
<version> <version>
@@ -100,7 +159,6 @@
- Release lua for PHP7 - Release lua for PHP7
</notes> </notes>
</release> </release>
<release> <release>
<date>2012-10-23</date> <date>2012-10-23</date>
<version> <version>

View File

@@ -48,7 +48,7 @@ extern zend_module_entry lua_module_entry;
#define LUA_G(v) (lua_globals.v) #define LUA_G(v) (lua_globals.v)
#endif #endif
#define PHP_LUA_VERSION "2.0.0" #define PHP_LUA_VERSION "2.0.4"
struct _php_lua_object { struct _php_lua_object {
lua_State *L; lua_State *L;

22
tests/bug71997.phpt Normal file
View File

@@ -0,0 +1,22 @@
--TEST--
Bug #71997 (One-Dimensional arrays cause segmentation faults)
--SKIPIF--
<?php
if (!extension_loaded("lua")) print "skip lua extension missing";
?>
--FILE--
<?php
$mylua = new \lua();
$mylua->eval(<<<CODE
function nicefunction(args)
print(args[1])
return args[1]
end
CODE
);
echo $mylua->call("nicefunction", array(array('hello', 'world')));
?>
done
--EXPECT--
worldworlddone

45
tests/bug73964.phpt Normal file
View File

@@ -0,0 +1,45 @@
--TEST--
Bug #73964 (Segmentation fault (11))
--SKIPIF--
<?php
if (!extension_loaded("lua")) print "skip lua extension missing";
?>
--FILE--
<?php
class LuaTest
{
function __construct()
{
$this->lua = new Lua();
$this->lua->registerCallback("log", array($this, "API_LuaLog"));
}
function API_LuaLog( $entry)
{
echo("from lua: $entry");
}
public function RunTest()
{
$this->lua->eval(<<<CODE
function TestFunc(str)
log(str)
end
CODE
);
$GamePackage = $this->lua->RootTable;
$this->lua->call("TestFunc", array("okey"));
}
}
$a = new LuaTest();
$a->runtest();
?>
--EXPECT--
from lua: okey

15
tests/issue012.phpt Normal file
View File

@@ -0,0 +1,15 @@
--TEST--
ISSUE #022 (Boolean FALSE is always TRUE)
--SKIPIF--
<?php
if (!extension_loaded("lua")) print "skip lua extension missing";
?>
--FILE--
<?php
$lua = new Lua();
$lua->assign('TEST', false);
$result = $lua->eval('return TEST');
var_dump($result)
?>
--EXPECT--
bool(false)

View File

@@ -1,14 +1,2 @@
phpize #!/bin/sh
phpize && ./configure --with-lua-version=5.2 && make
./configure --with-lua-version=5.2
make
EX=$?;
if [ $EX != 0 ];
then
echo "compile failed";
exit $EX;
fi;
exit $EX;