Hello. I am a Java developer and happen to know a little bit of Lua as well. I've taken an interest in this project since it's a lot like Bukkit, except that these plugins aren't made in Java. But I'd like to ask, is there a way to convert Lua code into PHP?
This is the closest I've found. Credit to Thomas Andersen. " Ever since i started playing this game, I've been interested in getting data out of it. I've never really was able to find a LUA to PHP data converter, all though i got pretty close on some website which I don't remember. My found there is the basis of the result i came up with here. This should only be used on LUA files containing data. Not for scripts. Be adviced: I use eval() to set the returned array. So if there is php code in the lua file you can risk it will be executed, all though my test show it will most likely just fail instead. LuaConverter.class.php <?php class LuaConverter{ private $variables; private $debug; function __construct($dbg = false){ $this->variables = null; $this->debug = $dbg; } public function convert($lua_text){ if((explode("\n", $lua_text)) > 0){ $result = array(); $lua_text = preg_replace("/\ -- (.*?)\n/","\n",$lua_text); $lua_text = str_replace(",\n)", "\n)", str_replace("{", "array(", str_replace("}", ");", str_replace("},", "),", str_replace("[\"", "\"", str_replace("] = ", " => ", str_replace("\t", "", str_replace("{\n}", "false\n", $lua_text ) ) ) ) ) ) ) ); foreach(explode("\n", $lua_text) as $lua_line){ if($this->debug){print($lua_line."\n");} $lua_line = chop($lua_line); if(eregi("^[a-z]", $lua_line)){ if(is_numeric($lua_line[strlen($lua_line)-1]) || $lua_line[strlen($lua_line)-1] == "\""){ $lua_line.=";"; } if($this->debug){print("variable start: $lua_line\n");} $result[] = $lua_line; $this->variables[] = substr($lua_line, 0, strpos($lua_line, " ")); }else{ $result[] = $lua_line; } } } eval('$return = $'.implode("", $result)); return $return; } public function getVariables(){ return $this->variables; } public function variableCount(){ return(count($this->variables)); } } ?> An example of use: <?php include('LuaConverter.class.php'); // the class file //If you are reading and uploaded epgp log file. $myFile = $_FILES['upload_file']['tmp_name']; //The uploaded file $fh = fopen($myFile, 'r'); $theData = fread($fh, filesize($myFile)); fclose($fh); // The actual conversion $lua = new LuaConverter(); // Creating a new object $epgp_data = $lua->convert($theData); // converting the data. ?> The $epgp_data is an array matching the LUA array. Just iterate overit and get the data you need."
Sadly, I do not as I am focused on Java at this moment. So, I'm not exactly clear, do I run the Strings or something?
Hmm, I am not quite familiar with Lua, but if you know Java, you can easily learn PHP. Try http://codecademy.com
Ehh.. I'm not exactly sure if it's really worth learning another language just to make plugins for PocketMine. Although, you're probably right about that since I understand OOP concepts. Yes, I realize that.
He is right. PHP is really easy to learn. I started learning Java (but I never finished learning) and then I started learning PHP on codecademy.com to make plugins and if you put like a week of work into it, you'll be able to understand how things work.
Time is tight with high school and all, so it's very unlikely now. I may consider going on another learning streak in the summer, though.
Basically the hard point of 100% auto Java=>PHP translator/converter is the java classes. See this example: PHP: function convertScript($classFile){$varChars=array('a','b','c'/*blah blah blah, a-z, A-Z, '_', '$', 0-9*/);$negChars=array(' ','tab'/*tab character. Can't type it in browser*/,'\n');$content=file_get_content($classFile);#remove commentsfor($i=0;$i<strlen($content);$i++){#shall make an independent function for it. It just gets repeated by "\'" and "\"" and "//" and "/**/" if(/*substr($content, $i, 1)===" " and */in_array(substr($content, $i, 2), $varChars)){ $memory=0; for($j=$i;$j<strlen($content)-2;$j++){ if(!(in_array(substr($content, $j, 1),$varChars)))break; } if($memory===0)return "eval\'d code error at character $i"; if(substr($content, $j, 1)!=="("){#if it is not calling a function $content=substr($content, 0, $i)."$".substr($content, $i); continue; } $content=substr($content, 0, $i)."$"."this->".substr($content, $i));#IDK how to avoid "$this" be reconginzed as $this }} I had paid a lot of time to make a javascript reader coded in PHP (PocketMine), but finally I gave up because it is no longer as fun as originally it had been, and there was so much trouble. So you see, when I was making it, every night on my bed I found a new exception in the script (e.g. in this one if the originally script was not trying to resolve a variable but using a keyword like "for", "try", etc.)