用php寫了乙個統計Lua指令碼行數的工具

2021-06-14 11:13:23 字數 3357 閱讀 3426

在quick-cocos2d-x的打包編譯lua的php檔案裡面加入統計lua指令碼行數的功能

關鍵**就這麼一行,在windows上面用find函式

list($line,$file,$size) = explode(" ",shell_exec("find /v \"\" /c ".$path));

在linux上面直接由wc 函式可以返回文字行數的貌似。。替換一下就可以了。

<?php

define('ds', directory_separator);

define('luajit', false);

class luapackager

}function dumpzip($outputfilebasename)

$zipfilename = $outputfilebasename . '.zip';

$zip = new ziparchive();

if ($zip->open($zipfilename, ziparchive::overwrite | ziparchive::cm_store))

$zip->close();

printf("done.\n\n");

}printf("\n****************************************====: %d lines ",$this->totalline);

print <$this->modules = array();

print("compile script files\n");

$this->compile();

if (empty($this->files))

$headerfilename = $outputfilebasename . '.h';

printf("create c header file: %s\n", $headerfilename);

file_put_contents($headerfilename, $this->renderheaderfile($outputfilebasename));

$sourcefilename = $outputfilebasename . '.c';

printf("create c source file: %s\n", $sourcefilename);

file_put_contents($sourcefilename, $this->rendersourcefile($outputfilebasename));

printf("\n****************************************====: %d lines ",$this->totalline);

printf("done.\n\n");

$outputfilebasename = basename($outputfilebasename);

print getluastate());

pengine->executestring("require(\"main\")");

eot;

}private function compile()

foreach ($this->files as $path)

}if ($found) continue;

printf(' compile module: %s...', $modulename);

$bytes = $this->compilefile($path);

if ($bytes == false)

else}}

private function getfiles($dir)

while (($file = readdir($dh)) !== false)

== '.')

$path = $dir . $file;

if (is_dir($path))

elseif (is_file($path))

}closedir($dh);

return $files;

}private function getfileline($path)

return $size;

} private function compilefile($path)

else

passthru($command);

if (!file_exists($tmpfile)) return false;

$bytes = file_get_contents($tmpfile);

unlink($tmpfile);

return $bytes;

}private function renderheaderfile($outputfilebasename)

$contents = '*/';

$contents = <;';

$contents = '';

}$contents = '';

foreach ($this->modules as $module)

,',$module["modulename"],

$module["functionname"]);

}$contents = <}eot;

return implode("\n", $contents);

}private function encodebytes($bytes)

$offset++;

}if (!empty($buffer))

return implode("\n", $contents);

}private function encodebytesfast($bytes)

));}

return implode('', $output);

}private function encodebytesblock($buffer)

return implode('', $output);

}}function help()

else if ($argv[0] == '-x')

else

}$config['excludes'] = $excludes;

array_shift($argv);

}else if ($argv[0] == '-zip')

else if ($config['srcdir'] == '')

else

array_shift($argv);

} while (count($argv) > 0);

$packager = new luapackager($config);

if ($config['zip'])

else

用java寫了乙個漢諾塔

package com.brzhang 漢諾塔 開始盤子全部都放在第一根柱子上 目的 將第一根柱子上的盤子全部移動到第三根柱子上,規則是不能編號較大的盤子放在編號交小的盤子上面。public class hanota else 移動盤子,從from移動到to借助assite param from p...

用css3 js寫了乙個鐘錶

先給個成品圖,最終結果是個樣子的 動態的 html 如下 div class dial div div class bigdiv bigdiv1 id secondhand div class secondhand div div div class bigdiv bigdiv2 id minute...

寫了乙個簡單實用的PHP模板引擎

php模板引擎很多,但要麼很龐大,要麼效率很低,如果只是要實現php 與程式分離,就只要乙個簡單的模板引擎就行了。今天抽空寫了乙個。xt.class.php created on 2011 10 08 author xyl this is template engine for your site ...