Advertisement
timia2109

to_lua

Nov 1st, 2014
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.04 KB | None | 0 0
  1. function to_lua($data, $forHTML = false, $layer = "") {
  2.       $space = $layer."    ";
  3.       if ($forHTML) {
  4.         $lua_table = $layer."{<br/>";
  5.       }
  6.       else {
  7.         $lua_table = "{";
  8.         $space = "";
  9.       }
  10.      
  11.       foreach ($data as $index => $value) {
  12.             if ($forHTML) {
  13.                 $lua_table .= $space.(is_numeric($index) ? "[$index] = " : "[\"$index\"] = ");
  14.             }
  15.             else {
  16.                 $lua_table .= (is_numeric($index) ? "[".$index."]=" : "[\"".$index."\"]=");
  17.             }
  18.             if (is_array($value) or is_object($value)) {
  19.               $lua_table .= to_lua($value, $forHTML, $space);
  20.             }
  21.             elseif (is_bool($value)) {
  22.               $lua_table .= ($value ? "true" : "false");
  23.             }
  24.             elseif (is_numeric($value)) {
  25.               $lua_table .= $value;
  26.             }
  27.             else {
  28.               $lua_table .= "\"".$value."\"";
  29.             }
  30.             $lua_table .= ",";
  31.             if ($forHTML) {
  32.                 $lua_table .= "<br/>";
  33.             }
  34.       }
  35.       $lua_table .= $layer."}";
  36.       return $lua_table;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement