コード例 #1
0
 /** Parser hook for the <lua> tag */
 public static function renderTag($input, $args, $parser)
 {
     try {
         global $wgLua;
         # Create a new LuaWrapper if needed
         if (!isset($wgLua)) {
             $wgLua = new LuaWrapper();
         }
         # Process the tag's arguments into a chunk of Lua code
         # that initializes them in the Lua sandbox
         $arglist = '';
         foreach ($args as $key => $value) {
             $arglist .= preg_replace('/\\W/', '', $key) . '=\'' . addslashes($parser->recursiveTagParse($value)) . '\';';
         }
         if ($arglist) {
             try {
                 $wgLua->wrap($arglist);
             } catch (LuaError $e) {
                 return $e->getMessage();
             }
         }
         # Execute this Lua chunk, and send the results through the
         # Parser.
         return $parser->recursiveTagParse($wgLua->wrap($input));
     } catch (LuaError $e) {
         return $e->getMessage();
     }
 }
コード例 #2
0
ファイル: Lua.hooks.php プロジェクト: Tjorriemorrie/app
 /**
  * Parser function hook for the #luaexpr function
  * @param $parser Parser
  * @param $param1 bool
  * @return string
  */
 public static function renderExpr(&$parser, $param1 = FALSE)
 {
     global $wgLua;
     # Create a new LuaWrapper if needed
     if ($wgLua === null) {
         $wgLua = new LuaWrapper();
     }
     # Execute this Lua chunk, wrapped in io.write().
     if ($param1 == false) {
         return '';
     }
     try {
         return $wgLua->wrap("io.write({$param1})");
     } catch (LuaError $e) {
         return $e->getMessage();
     }
 }