2 +----------------------------------------------------------------------+
3 | LUA extension for PHP |
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2007 Johannes Schlueter |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
15 | Author: Johannes Schlueter <johannes@php.net> |
16 | Marcelo Araujo <msaraujo@php.net> |
17 | Andreas Streichardt <andreas.streichardt@globalpark.com |
18 +----------------------------------------------------------------------+
27 #include "ext/standard/info.h"
34 #define EXT_LUA_VERSION PHP_LUA_VERSION
36 #ifdef LUA_STACK_DEBUG
37 #define LUA_STACK_START(L) int __lua_old_top = lua_gettop(L)
38 #define LUA_STACK_END(L) \
39 if (__lua_old_top != lua_gettop(L)) { \
40 php_error_docref(NULL TSRMLS_CC, E_WARNING, "wrong stack size (%i before operation, %i now)", __lua_old_top, lua_gettop(L)); \
43 #define LUA_STACK_START(L)
44 #define LUA_STACK_END(L)
47 #define LUA_POP_ZVAL(L, z) \
48 php_lua_get_zval_from_stack(L, -1, z); \
51 ZEND_DECLARE_MODULE_GLOBALS(lua
)
53 #define getLuaZ(var) (((php_lua_object*)zend_object_store_get_object(var TSRMLS_CC))->L)
54 #define getLuaY() ((php_lua_object*)zend_object_store_get_object(getThis() TSRMLS_CC))
55 #define getLua() getLuaZ(getThis())
57 static zend_object_handlers lua_handlers
;
58 static zend_class_entry
*lua_ce
;
60 typedef struct _php_lua_object
{
67 static const luaL_Reg php_lualibs
[] = {
68 {"base", luaopen_base
},
69 {LUA_LOADLIBNAME
, luaopen_package
},
70 {LUA_TABLIBNAME
, luaopen_table
},
71 {LUA_IOLIBNAME
, luaopen_io
},
72 {LUA_OSLIBNAME
, luaopen_os
},
73 {LUA_STRLIBNAME
, luaopen_string
},
74 {LUA_MATHLIBNAME
, luaopen_math
},
75 {LUA_DBLIBNAME
, luaopen_debug
},
79 static void php_lua_push_zval(lua_State
*L
, zval
*val_p TSRMLS_DC
);
80 static void php_lua_write_real_property(lua_State
*L
,int index
,zval
*prop
, zval
*value TSRMLS_DC
);
82 static void *php_lua_alloc (void *ud
, void *ptr
, size_t osize
, size_t nsize
) { /* {{{ */
90 return erealloc(ptr
, nsize
);
92 return emalloc(nsize
);
98 static void php_lua_push_array(lua_State
*L
, zval
*array TSRMLS_DC
) /* {{{ */
102 HashPosition pointer
;
112 arr_hash
= Z_ARRVAL_P(array
);
113 array_count
= zend_hash_num_elements(arr_hash
);
117 for(zend_hash_internal_pointer_reset_ex(arr_hash
, &pointer
); zend_hash_get_current_data_ex(arr_hash
, (void**) &data
, &pointer
) == SUCCESS
; zend_hash_move_forward_ex(arr_hash
, &pointer
))
119 hash_key
=zend_hash_get_current_key_ex(arr_hash
, &key
, &key_len
, &index
, 0, &pointer
);
121 if (hash_key
== HASH_KEY_IS_LONG
&& index
== 0) {
122 php_error_docref(NULL TSRMLS_CC
, E_WARNING
, "Trying to push array index %ld to lua which is unsupported in lua. Element has been discarded",index
);
125 ALLOC_INIT_ZVAL(zkey
);
126 if (hash_key
== HASH_KEY_IS_STRING
) {
127 key_copy
=estrndup(key
,key_len
-1);
128 Z_TYPE_P(zkey
)=IS_STRING
;
129 Z_STRVAL_P(zkey
)=key_copy
;
130 Z_STRLEN_P(zkey
)=key_len
-1;
133 Z_TYPE_P(zkey
)=IS_LONG
;
134 Z_LVAL_P(zkey
)=index
;
137 php_lua_write_real_property(L
,-3,zkey
,*data TSRMLS_CC
);
138 zval_ptr_dtor(&zkey
);
146 static void php_lua_push_zval(lua_State
*L
, zval
*val_p TSRMLS_DC
) /* {{{ */
148 /* TODO: Use proper type for lua and separate only when needed */
150 /* push into lua stack properly */
151 switch (Z_TYPE_P(val_p
)) {
153 lua_pushlstring(L
, Z_STRVAL_P(val_p
), Z_STRLEN_P(val_p
));
161 lua_pushnumber(L
, Z_DVAL_P(val_p
));
165 lua_pushnumber(L
, Z_LVAL_P(val_p
));
169 lua_pushboolean(L
, Z_BVAL_P(val_p
));
173 php_lua_push_array(L
,val_p TSRMLS_CC
);
177 php_error_docref(NULL TSRMLS_CC
, E_WARNING
, "invalid type `%s' supported in lua", zend_zval_type_name(val_p
));
184 static int php_lua_push_apply_func(void *pDest
, void *argument TSRMLS_DC
) /* {{{ */
186 php_lua_push_zval((lua_State
*)argument
, *(zval
**)pDest TSRMLS_CC
);
187 return ZEND_HASH_APPLY_KEEP
;
190 static void php_lua_get_zval_from_stack(lua_State
*L
, int index
, zval
*ret TSRMLS_DC
) /* {{{ */
196 switch (lua_type(L
, index
)) {
198 ZVAL_BOOL(ret
, lua_toboolean(L
, index
));
202 ZVAL_DOUBLE(ret
, lua_tonumber(L
, index
));
206 value
= lua_tolstring(L
, index
, &value_len
);
207 ZVAL_STRINGL(ret
, (char*)value
, value_len
, 1);
212 /* notify lua to traverse the table */
215 /* table has been moved by one because of the pushnil */
216 /* this will ONLY work with negative indices! */
217 while (lua_next(L
, index
-1) != 0)
219 ALLOC_INIT_ZVAL(akey
);
220 ALLOC_INIT_ZVAL(aval
);
222 /* `key' is at index -2 and `value' at index -1 */
223 php_lua_get_zval_from_stack(L
,-2,akey TSRMLS_CC
);
224 php_lua_get_zval_from_stack(L
,-1,aval TSRMLS_CC
);
226 switch(Z_TYPE_P(akey
))
228 /* lua can't use (at least when i tried ;) ) floats as array keys so that should be safe */
230 add_index_zval(ret
,(long)Z_DVAL_P(akey
),aval
);
233 add_assoc_zval(ret
,Z_STRVAL_P(akey
),aval
);
236 lua_pop(L
, 1); /* removes `value'; keeps `key' for next iteration */
237 zval_ptr_dtor(&akey
);
243 /* TODO: Make this a PHP Function */
246 php_error_docref(NULL TSRMLS_CC
, E_WARNING
, "invalid type `%i' passed from lua.", lua_type(L
, index
));
256 static int php_lua_print(lua_State
*L
) /* {{{ */
259 int n
= lua_gettop(L
);
261 for (i
= 1; i
<= n
; i
++) {
262 php_printf("%s", lua_tostring(L
, i
));
268 static void php_lua_object_dtor(void *object
, zend_object_handle handle TSRMLS_DC
) /* {{{ */
271 php_lua_object
*intern
= (php_lua_object
*)object
;
272 zend_object_std_dtor(&(intern
->std
) TSRMLS_CC
);
274 for (i
=0;i
<intern
->callback_count
;i
++)
275 zval_dtor(&intern
->callbacks
[i
]);
276 efree(intern
->callbacks
);
278 lua_close(intern
->L
);
284 static zval
*php_lua_read_property(zval
*obj
, zval
*prop
, int type TSRMLS_DC
) /* {{{ */
287 lua_State
*L
= getLuaZ(obj
);
291 if (type
!= BP_VAR_R
) {
292 php_error_docref(NULL TSRMLS_CC
, E_WARNING
, "No write access using read_property.");
293 ALLOC_INIT_ZVAL(retval
);
297 if (Z_TYPE_P(prop
) == IS_STRING
) {
298 MAKE_STD_ZVAL(retval
);
299 lua_getfield(L
, LUA_GLOBALSINDEX
, Z_STRVAL_P(prop
));
300 php_lua_get_zval_from_stack(L
, -1, retval TSRMLS_CC
);
301 #if PHP_VERSION_ID>=50300
307 ALLOC_INIT_ZVAL(retval
);
318 static void php_lua_write_real_property(lua_State
*L
,int index
,zval
*prop
, zval
*value TSRMLS_DC
) /* {{{ */
321 php_lua_push_zval(L
, prop TSRMLS_CC
);
322 php_lua_push_zval(L
, value TSRMLS_CC
);
324 lua_settable(L
, index
);
330 static void php_lua_write_property(zval
*obj
, zval
*prop
, zval
*value TSRMLS_DC
) /* {{{ */
332 /* TODO: Use proper type for lua and separate only when needed */
333 lua_State
*L
= getLuaZ(obj
);
335 php_lua_write_real_property(L
,LUA_GLOBALSINDEX
,prop
,value TSRMLS_CC
);
338 static int php_lua_atpanic(lua_State
*L
) { /* {{{ */
340 php_error_docref(NULL TSRMLS_CC
, E_WARNING
, "lua panic (%s)", lua_tostring(L
, 1));
346 static zend_object_value
php_lua_create_object(zend_class_entry
*ce TSRMLS_DC
) /* {{{ */
349 zend_object_value retval
;
350 php_lua_object
*intern
;
353 L
= lua_newstate(php_lua_alloc
, NULL
);
354 lua_atpanic(L
, php_lua_atpanic
);
356 intern
= ecalloc(1, sizeof(php_lua_object
));
358 intern
->callback_count
=0;
359 intern
->callbacks
=emalloc(sizeof(zval
*));
360 zend_object_std_init(&(intern
->std
), ce TSRMLS_CC
);
361 zend_hash_copy(intern
->std
.properties
,
362 &ce
->default_properties
, (copy_ctor_func_t
) zval_add_ref
,
363 (void *) &tmp
, sizeof(zval
*));
365 retval
.handle
= zend_objects_store_put(intern
, php_lua_object_dtor
, NULL
, NULL TSRMLS_CC
);
366 retval
.handlers
= &lua_handlers
;
370 static int php_lua_callback(lua_State
*L
) /* {{{ */
373 php_lua_object
*object
=(php_lua_object
*)lua_topointer(L
, lua_upvalueindex(1));
374 long selected_callback_index
=(long)lua_tonumber(L
, lua_upvalueindex(2));
376 TSRMLS_D
=(void ***)lua_topointer(L
,lua_upvalueindex(3));
381 ALLOC_INIT_ZVAL(return_value
);
383 #if PHP_VERSION_ID>=50300
384 if (!zend_is_callable(&object
->callbacks
[selected_callback_index
],0,NULL TSRMLS_CC
))
386 if (!zend_is_callable(&object
->callbacks
[selected_callback_index
],0,NULL
))
390 n
= lua_gettop(L
); /* number of arguments */
392 params
=emalloc(n
*sizeof(zval
));
394 for (i
= 1; i
<= n
; i
++) {
395 ALLOC_INIT_ZVAL(params
[i
-1]);
396 /* php_lua_get_zval_from_stack won't work with positive indices */
397 php_lua_get_zval_from_stack(L
,-n
-1+i
,params
[i
-1] TSRMLS_CC
);
400 /* XXX no check - do we need one? :S */
401 /* johannes said i should use zend_call_method but this only allows up to 2 parameters?! */
402 call_user_function(EG(function_table
),NULL
,&object
->callbacks
[selected_callback_index
],return_value
,n
,params TSRMLS_CC
);
404 /* hmm...what if the result is NULL? should php return a return value (NULL) then or just return 0? :S */
405 php_lua_push_zval(L
,return_value TSRMLS_CC
);
407 for (i
= 0; i
< n
; i
++) {
408 zval_ptr_dtor(¶ms
[i
]);
412 zval_ptr_dtor(&return_value
);
414 /* PHP doesn't support multiple return values so this will always be 1 */
418 static void php_lua_call_table_with_arguments(lua_State
*L
,int level
,int table_index
,char *function
,int propagate_self
,zval
*args
,zval
*return_value TSRMLS_DC
) /* {{{ */
423 lua_getfield(L
,table_index
,function
);
424 if (lua_type(L
,lua_gettop(L
)) != LUA_TFUNCTION
) {
425 lua_pop(L
, lua_gettop(L
) - level
);
426 php_error_docref(NULL TSRMLS_CC
, E_WARNING
, "invalid lua callback. '%s' is not a defined function",function
);
430 /* push the table on the stack as the first argument */
432 lua_pushvalue(L
,table_index
+ lua_gettop(L
));
434 zend_hash_apply_with_argument(Z_ARRVAL_P(args
), php_lua_push_apply_func
, (void *)L TSRMLS_CC
);
436 if (lua_pcall(L
, zend_hash_num_elements(Z_ARRVAL_P(args
)) + propagate_self
, LUA_MULTRET
, 0) != 0) {
437 php_error_docref(NULL TSRMLS_CC
, E_WARNING
, "error running lua function `%s': %s", function
, lua_tostring(L
, -1));
438 lua_pop(L
, lua_gettop(L
) - level
);
442 /* always return an array. otherwise we couldn't distinguish between a table return or a multi return */
443 array_init(return_value
);
444 retcount
= lua_gettop(L
) - level
;
446 for (i
= -retcount
; i
< 0; i
++)
449 php_lua_get_zval_from_stack(L
, i
, val TSRMLS_CC
);
450 add_next_index_zval(return_value
, val
);
452 lua_pop(L
, retcount
);
457 static void php_lua_call_table_function(INTERNAL_FUNCTION_PARAMETERS
,int propagate_self
) /* {{{ */
459 zval
*callback
,*args
;
460 zval
**lua_table
,**lua_function
;
461 int array_count
,level
;
467 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "za", &callback
, &args
) == FAILURE
) {
471 array_count
=zend_hash_num_elements(Z_ARRVAL_P(callback
));
472 if (array_count
!=2) {
474 php_error_docref(NULL TSRMLS_CC
, E_WARNING
, "invalid callback supplied. must contain exactly 2 elements");
477 if (zend_hash_index_find(Z_ARRVAL_P(callback
), 0, (void**)&lua_table
) == FAILURE
) {
478 php_error_docref(NULL TSRMLS_CC
, E_WARNING
, "callback index 0 is empty");
481 if (zend_hash_index_find(Z_ARRVAL_P(callback
), 1, (void**)&lua_function
) == FAILURE
) {
482 php_error_docref(NULL TSRMLS_CC
, E_WARNING
, "callback index 1 is empty");
485 lua_getglobal(L
,Z_STRVAL_PP(lua_table
));
486 if (lua_type(L
,lua_gettop(L
)) != LUA_TTABLE
) {
488 php_error_docref(NULL TSRMLS_CC
, E_WARNING
, "trying to call an invalid table '%s'",Z_STRVAL_PP(lua_table
));
493 php_lua_call_table_with_arguments(L
,level
,-1,Z_STRVAL_PP(lua_function
),propagate_self
,args
,return_value TSRMLS_CC
);
495 /* remove the table which is still on top */
502 static int php_lua_binary_zval_writer(lua_State
* L
, const void* p
,size_t size
, void* u
)
504 Z_STRVAL_P((zval
*)u
)=erealloc(Z_STRVAL_P((zval
*)u
),(Z_STRLEN_P((zval
*)u
)+1+size
)*sizeof(char));
505 memcpy(&Z_STRVAL_P((zval
*)u
)[Z_STRLEN_P((zval
*)u
)],p
,size
);
506 Z_STRLEN_P((zval
*)u
)=Z_STRLEN_P((zval
*)u
)+size
;
507 Z_STRVAL_P((zval
*)u
)[Z_STRLEN_P((zval
*)u
)]='\0';
512 #define RETURN_STR "return %s"
515 /* {{{ lua::__construct()
516 Create new LUA instance */
517 PHP_METHOD(lua
, __construct
)
519 lua_State
*L
= getLua();
520 // mop: open standard libs if desired
521 if (INI_BOOL("lua.load_standard_libs")) {
524 lua_register(L
, "print", php_lua_print
);
528 /* {{{ lua::__call(string method, array args [, int nresults])
529 Call a lua function from within PHP */
530 PHP_METHOD(lua
, __call
)
533 char *function
, *func
;
536 long nresults
= LUA_MULTRET
;
537 lua_State
*L
= getLua();
541 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "sa|l", &function
, &function_len
, &args
, &nresults
) == FAILURE
) {
545 level
= lua_gettop(L
);
547 spprintf(&func
, sizeof(RETURN_STR
)-2-1+function_len
, RETURN_STR
, function
);
548 if (luaL_dostring(L
, func
)) {
550 php_error_docref(NULL TSRMLS_CC
, E_WARNING
, "error looking up lua function `%s': %s", function
, lua_tostring(L
, -1));
551 lua_pop(L
, lua_gettop(L
) - level
);
557 zend_hash_apply_with_argument(Z_ARRVAL_P(args
), php_lua_push_apply_func
, (void *)L TSRMLS_CC
);
559 if (lua_pcall(L
, zend_hash_num_elements(Z_ARRVAL_P(args
)), nresults
, 0) != 0) {
560 php_error_docref(NULL TSRMLS_CC
, E_WARNING
, "error running lua function `%s': %s", function
, lua_tostring(L
, -1));
561 lua_pop(L
, lua_gettop(L
) - level
);
566 retcount
= lua_gettop(L
) - level
;
569 /* No vlaue returned -> return null */
571 /* multiple return values -> build an array */
575 array_init(return_value
);
576 for (i
= -retcount
; i
< 0; i
++)
579 php_lua_get_zval_from_stack(L
, i
, val TSRMLS_CC
);
580 add_next_index_zval(return_value
, val
);
582 lua_pop(L
, retcount
);
589 /* {{{ lua::call_function(string function, array args)
590 Call a lua function from within PHP */
591 PHP_METHOD(lua
, call_function
)
604 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "sa", &function
, &function_len
, &args
) == FAILURE
) {
608 php_lua_call_table_with_arguments(L
,level
,LUA_GLOBALSINDEX
,function
,0,args
,return_value TSRMLS_CC
);
613 /* {{{ lua::call_table(array lua_callback, array args)
614 Call a lua table from within PHP (lua_table.lua_function()) */
615 PHP_METHOD(lua
, call_table
)
617 php_lua_call_table_function(INTERNAL_FUNCTION_PARAM_PASSTHRU
,0);
620 /* {{{ lua::call_table_self(array lua_callback, array args)
621 Call a lua table from within PHP and propagate self (lua_table:lua_function()) */
622 PHP_METHOD(lua
, call_table_self
)
624 php_lua_call_table_function(INTERNAL_FUNCTION_PARAM_PASSTHRU
,1);
627 /* {{{ void lua::evaluate(string code)
628 Evaluates code with lua */
629 PHP_METHOD(lua
, evaluate
)
637 lua_State
*L
= getLua();
641 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "s", &code
, &code_len
) == FAILURE
) {
645 error
= luaL_loadbuffer(L
, code
, code_len
, "line") || lua_pcall(L
, 0, LUA_MULTRET
, 0);
647 php_error_docref(NULL TSRMLS_CC
, E_WARNING
, "lua error: %s", lua_tostring(L
, -1));
648 lua_pop(L
, 1); /* pop error message from the stack */
651 /* always return an array. otherwise we couldn't distinguish between a table return or a multi return */
652 array_init(return_value
);
653 retcount
= lua_gettop(L
);
655 for (i
= -retcount
; i
< 0; i
++)
658 php_lua_get_zval_from_stack(L
, i
, val TSRMLS_CC
);
659 add_next_index_zval(return_value
, val
);
661 lua_pop(L
, retcount
);
667 /* {{{ void lua::evaluatefile(string file)
668 Evaluates a lua script */
669 PHP_METHOD(lua
, evaluatefile
)
674 lua_State
*L
= getLua();
681 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "s", &file
, &file_len
) == FAILURE
) {
685 if (php_check_open_basedir(file TSRMLS_CC
) || (PG(safe_mode
) && !php_checkuid(file
, "rb+", CHECKUID_CHECK_MODE_PARAM
))) {
690 error
= luaL_dofile(L
, file
);
693 php_error_docref(NULL TSRMLS_CC
, E_WARNING
, "lua error: %s", lua_tostring(L
, -1));
696 retcount
=lua_gettop(L
);
697 array_init(return_value
);
699 for (i
= -retcount
; i
< 0; i
++)
702 php_lua_get_zval_from_stack(L
, i
, val TSRMLS_CC
);
703 add_next_index_zval(return_value
, val
);
705 lua_pop(L
, retcount
);
711 /* {{{ string lua::getVersion()
712 Return Lua's version */
713 PHP_METHOD(lua
, getversion
)
715 RETURN_STRING(LUA_RELEASE
, 1);
720 PHP_METHOD(lua
,expose_function
)
727 php_lua_object
*object
=getLuaY();
728 lua_State
*L
= object
->L
;
730 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
,"sz",&lua_name
,&len
,&callback
) == FAILURE
)
733 #if PHP_VERSION_ID>=50300
734 if (zend_is_callable(callback
,0,NULL TSRMLS_CC
)) {
736 if (zend_is_callable(callback
,0,NULL
)) {
738 lua_pushlightuserdata(L
,object
);
739 lua_pushnumber(L
,object
->callback_count
);
741 lua_pushlightuserdata(L
,TSRMLS_C
);
746 lua_pushcclosure(L
, php_lua_callback
,param_count
);
747 lua_setglobal(L
, lua_name
);
749 /* hmm...out of memory check? */
750 object
->callbacks
=erealloc(object
->callbacks
,sizeof(zval
)*(object
->callback_count
+1));
751 object
->callbacks
[object
->callback_count
] = *callback
;
752 zval_copy_ctor(&object
->callbacks
[object
->callback_count
]);
753 object
->callback_count
++;
758 PHP_METHOD(lua
,compile
)
764 lua_State
*L
= lua_newstate(php_lua_alloc
, NULL
);
765 lua_atpanic(L
, php_lua_atpanic
);
769 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
,"s",&chunk
,&len
) == FAILURE
)
775 error
= luaL_loadbuffer(L
, chunk
, len
, "line");
777 php_error_docref(NULL TSRMLS_CC
, E_WARNING
, "lua error: %s", lua_tostring(L
, -1));
778 lua_pop(L
, 1); /* pop error message from the stack */
785 error
=lua_dump(L
,php_lua_binary_zval_writer
,return_value
);
786 lua_pop(L
, 1); /* clean stack */
790 php_error_docref(NULL TSRMLS_CC
, E_WARNING
, "Couldn't dump code");
798 ZEND_BEGIN_ARG_INFO_EX(arginfo_lua_call
, 0, 0, 2)
799 ZEND_ARG_INFO(0, method
)
800 ZEND_ARG_INFO(0, args
)
803 ZEND_BEGIN_ARG_INFO_EX(arginfo_lua_call_table
, 0, 0, 2)
804 ZEND_ARG_INFO(0, callback
)
805 ZEND_ARG_INFO(0, args
)
808 ZEND_BEGIN_ARG_INFO_EX(arginfo_lua_call_function
, 0, 0, 2)
809 ZEND_ARG_INFO(0, function
)
810 ZEND_ARG_INFO(0, args
)
813 ZEND_BEGIN_ARG_INFO_EX(arginfo_lua_evaluate
, 0, 0, 1)
814 ZEND_ARG_INFO(0, code
)
817 ZEND_BEGIN_ARG_INFO_EX(arginfo_lua_evaluatefile
, 0, 0, 1)
818 ZEND_ARG_INFO(0, file
)
821 ZEND_BEGIN_ARG_INFO_EX(arginfo_lua_expose_function
, 0, 0, 2)
822 ZEND_ARG_INFO(0, lua_name
)
823 ZEND_ARG_INFO(0, callback
)
826 ZEND_BEGIN_ARG_INFO_EX(arginfo_lua_compile
, 0, 0, 1)
827 ZEND_ARG_INFO(0, chunk
)
832 /* {{{ lua_class_functions[] */
833 zend_function_entry lua_class_functions
[] = {
834 PHP_ME(lua
, __construct
, NULL
, ZEND_ACC_PUBLIC
)
835 PHP_ME(lua
, __call
, arginfo_lua_call
, ZEND_ACC_PUBLIC
)
836 PHP_ME(lua
, call_function
, arginfo_lua_call_function
, ZEND_ACC_PUBLIC
)
837 PHP_ME(lua
, call_table
, arginfo_lua_call_table
, ZEND_ACC_PUBLIC
)
838 PHP_ME(lua
, call_table_self
, arginfo_lua_call_table
, ZEND_ACC_PUBLIC
)
839 PHP_ME(lua
, evaluate
, arginfo_lua_evaluate
, ZEND_ACC_PUBLIC
)
840 PHP_ME(lua
, evaluatefile
, arginfo_lua_evaluatefile
, ZEND_ACC_PUBLIC
)
841 PHP_ME(lua
, getversion
, NULL
, ZEND_ACC_PUBLIC
)
842 PHP_ME(lua
, expose_function
, arginfo_lua_expose_function
, ZEND_ACC_PUBLIC
)
843 PHP_ME(lua
, compile
, arginfo_lua_compile
, ZEND_ACC_PUBLIC
|ZEND_ACC_STATIC
)
848 #ifdef COMPILE_DL_LUA
855 STD_PHP_INI_BOOLEAN("lua.load_standard_libs","1", PHP_INI_ALL
, OnUpdateBool
, load_standard_libs
, zend_lua_globals
, lua_globals
)
859 /* {{{ php_lua_init_globals
861 static void php_lua_init_globals(zend_lua_globals
*lua_globals
)
866 /* {{{ PHP_MINIT_FUNCTION
868 PHP_MINIT_FUNCTION(lua
)
871 ZEND_INIT_MODULE_GLOBALS(lua
, php_lua_init_globals
, NULL
);
873 REGISTER_INI_ENTRIES();
874 INIT_CLASS_ENTRY(ce
, "lua", lua_class_functions
);
875 lua_ce
= zend_register_internal_class(&ce TSRMLS_CC
);
876 lua_ce
->create_object
= php_lua_create_object
;
877 memcpy(&lua_handlers
, zend_get_std_object_handlers(),
878 sizeof(zend_object_handlers
));
879 lua_handlers
.write_property
= php_lua_write_property
;
880 lua_handlers
.read_property
= php_lua_read_property
;
881 lua_ce
->ce_flags
|= ZEND_ACC_FINAL
;
883 zend_declare_class_constant_long(lua_ce
, "MULTRET", sizeof("MULTRET")-1, LUA_MULTRET TSRMLS_CC
);
889 /* {{{ PHP_MSHUTDOWN_FUNCTION
891 PHP_MSHUTDOWN_FUNCTION(lua
)
893 UNREGISTER_INI_ENTRIES();
898 /* {{{ PHP_RINIT_FUNCTION
900 PHP_RINIT_FUNCTION(lua
)
906 /* {{{ PHP_RSHUTDOWN_FUNCTION
908 PHP_RSHUTDOWN_FUNCTION(lua
)
914 /* {{{ PHP_MINFO_FUNCTION
916 PHP_MINFO_FUNCTION(lua
)
918 php_info_print_table_start();
919 php_info_print_table_row(2, "lua support", "enabled");
920 php_info_print_table_row(2, "lua extension version", EXT_LUA_VERSION
);
921 php_info_print_table_row(2, "lua release", LUA_RELEASE
);
922 php_info_print_table_row(2, "lua copyright", LUA_COPYRIGHT
);
923 php_info_print_table_row(2, "lua authors", LUA_AUTHORS
);
924 php_info_print_table_end();
926 DISPLAY_INI_ENTRIES();
930 /* {{{ lua_module_entry
932 zend_module_entry lua_module_entry
= {
933 STANDARD_MODULE_HEADER
,
942 STANDARD_MODULE_PROPERTIES
950 * vim: set noet sw=4 ts=4:
951 * vim600: noet sw=4 ts=4 fdm=marker: