_extensionName = $extensionName; $this->_luabindingFilename = $luabindingFilename; $this->_inputPath = SRC_DIR . $extensionName . '.pkg'; $this->_outputCppPath = OUT_DIR . $luabindingFilename . '.cpp'; $this->_outputHeaderPath = OUT_DIR . $luabindingFilename . '.h'; $this->_luaopenFunctionName = sprintf('tolua_%s_open', $extensionName); $this->_fix = $fix; } function build() { $command = sprintf('%s -n %s -L basic.lua -o %s %s', TOLUA_BIN, $this->_extensionName, $this->_outputCppPath, $this->_inputPath); printf(" creating file: %s.cpp\n", $this->_luabindingFilename); printf(" command: %s\n", $command); passthru($command); if (file_exists($this->_outputCppPath)) { $this->_fixLuabindingFile(); } $includeOnce = sprintf('__%s_H_', strtoupper($this->_luabindingFilename)); $functionName = $this->_luaopenFunctionName; $header = <<_luabindingFilename); // file_put_contents($this->_outputHeaderPath, $header); } function getLuaopenFunctionName() { return $this->_luaopenFunctionName; } private function _fixLuabindingFile() { $contents = file_get_contents($this->_outputCppPath); $contents = str_replace("\t", ' ', $contents); foreach ($this->_fix as $find => $replace) { $find = str_replace('##EXTENSION_NAME##', $this->_extensionName, $find); $replace = str_replace('##EXTENSION_NAME##', $this->_extensionName, $replace); $contents = str_replace($find, $replace, $contents); } file_put_contents($this->_outputCppPath, $contents); } } $FIX = array(); // remove unused header $find = <<m_uID : -1; int* pLuaID = (tolua_ret) ? &tolua_ret->m_nLuaID : NULL; toluafix_pushusertype_ccobject(tolua_S, nID, pLuaID, (void*)tolua_ret EOT; $FIX[$find] = $replace; // fix LUA_STRING $find = '((LUA_STRING*)'; $replace = '('; $FIX[$find] = $replace; $find = 'tolua_usertype(tolua_S,"LUA_STRING");'; $replace = ''; $FIX[$find] = $replace; $find = <<build();