GUIForDebug
Posted 沧海一滴
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了GUIForDebug相关的知识,希望对你有一定的参考价值。
package gui; import org.luaj.vm2.Globals; import org.luaj.vm2.LuaValue; import org.luaj.vm2.ast.Chunk; import org.luaj.vm2.ast.Exp; import org.luaj.vm2.ast.Stat; import org.luaj.vm2.ast.Visitor; import org.luaj.vm2.lib.jse.JsePlatform; import org.luaj.vm2.parser.LuaParser; import org.luaj.vm2.parser.ParseException; import javax.swing.*; import javax.swing.filechooser.FileFilter; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.File; import java.io.FileInputStream; import java.io.IOException; /** * Created by 10159705 on 16-3-7. */ public class GUIForDebug { public static final int WIDTH = 400; public static void main(String[] args) { final JFrame jFrame = new JFrame("For Lua Debug"); jFrame.setLayout(new FlowLayout()); final JTextField jTextField = new JTextField("Lua Path:", WIDTH - 10); jFrame.add(jTextField); final JFileChooser jFileChooser = new JFileChooser(); jFileChooser.setSelectedFile(new File("E:\\lang\\lua\\workspace\\LuaProject\\src\\main.lua")); jFileChooser.setFileFilter(new FileFilter() { @Override public String getDescription() { return "Lua(.lua)"; } @Override public boolean accept(File f) { if (f.isDirectory()) { return true; } return f.getName().toLowerCase().endsWith(".lua"); } }); JButton jButton = new JButton("click"); jFrame.add(jButton); jButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int result = jFileChooser.showOpenDialog(jFrame); if (result == JFileChooser.CANCEL_OPTION) { return; } File chooseFile = jFileChooser.getSelectedFile(); String luaFilePath = chooseFile.getAbsolutePath(); jFrame.add(new JLabel("<html><font color=blue>" + luaFilePath)); jTextField.setText(luaFilePath); jFrame.validate(); // create an environment to run in Globals globals = JsePlatform.standardGlobals(); // Use the convenience function on Globals to load a chunk. LuaValue chunk = globals.loadfile(luaFilePath); // Use any of the "call()" or "invoke()" functions directly on the chunk. chunk.call(LuaValue.valueOf(luaFilePath)); } }); SwingConsole.run(jFrame, WIDTH, 200); } protected static void parserUT(File fileFullName) { try { // Create a LuaParser. This will fill in line and column number // information for most exceptions. LuaParser parser = new LuaParser(new FileInputStream(fileFullName)); // Perform the parsing. Chunk chunk = parser.Chunk(); // Print out line info for all function definitions. chunk.accept(new Visitor() { public void visit(Exp.AnonFuncDef exp) { System.out.println("Anonymous function definition at " + exp.beginLine + "." + exp.beginColumn + "," + exp.endLine + "." + exp.endColumn); } public void visit(Stat.FuncDef stat) { System.out.println("Function definition ‘" + stat.name.name.name + "‘ at " + stat.beginLine + "." + stat.beginColumn + "," + stat.endLine + "." + stat.endColumn); System.out.println("\tName location " + stat.name.beginLine + "." + stat.name.beginColumn + "," + stat.name.endLine + "." + stat.name.endColumn); } public void visit(Stat.LocalFuncDef stat) { System.out.println("Local function definition ‘" + stat.name.name + "‘ at " + stat.beginLine + "." + stat.beginColumn + "," + stat.endLine + "." + stat.endColumn); } }); } catch (ParseException e) { System.out.println("parse failed: " + e.getMessage() + "\n" + "Token Image: ‘" + e.currentToken.image + "‘\n" + "Location: " + e.currentToken.beginLine + ":" + e.currentToken.beginColumn + "-" + e.currentToken.endLine + "," + e.currentToken.endColumn); } catch (IOException e) { System.out.println("IOException occurred: " + e); e.printStackTrace(); } } } class SwingConsole { public static void run(final JFrame frame, final int width, final int height) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { frame.setSize(width, height); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLocationRelativeTo(null); frame.setVisible(true); } }); } }
--array={1,2,3,4,5} --for key, var in pairs(array) do -- print(key,var) --end -- --function f(a, b) --return a or b --end -- --print ("output:",f(1,3)); require(‘mobdebug‘) function maximum (a) local mi = 1 -- maximum index local m = a[mi] -- maximum value for i,val in ipairs(a) do if val > m then mi = i m = val end end return m, mi end print(maximum({8,10,23,12,5})) --> 23 3
以上是关于GUIForDebug的主要内容,如果未能解决你的问题,请参考以下文章