1. package gui;
  2.  
  3. import org.luaj.vm2.Globals;
  4. import org.luaj.vm2.LuaValue;
  5. import org.luaj.vm2.ast.Chunk;
  6. import org.luaj.vm2.ast.Exp;
  7. import org.luaj.vm2.ast.Stat;
  8. import org.luaj.vm2.ast.Visitor;
  9. import org.luaj.vm2.lib.jse.JsePlatform;
  10. import org.luaj.vm2.parser.LuaParser;
  11. import org.luaj.vm2.parser.ParseException;
  12.  
  13. import javax.swing.*;
  14. import javax.swing.filechooser.FileFilter;
  15. import java.awt.*;
  16. import java.awt.event.ActionEvent;
  17. import java.awt.event.ActionListener;
  18. import java.io.File;
  19. import java.io.FileInputStream;
  20. import java.io.IOException;
  21.  
  22. /**
  23. * Created by 10159705 on 16-3-7.
  24. */
  25. public class GUIForDebug {
  26.  
  27. public static final int WIDTH = 400;
  28.  
  29. public static void main(String[] args) {
  30. final JFrame jFrame = new JFrame("For Lua Debug");
  31. jFrame.setLayout(new FlowLayout());
  32.  
  33. final JTextField jTextField = new JTextField("Lua Path:", WIDTH - 10);
  34. jFrame.add(jTextField);
  35. final JFileChooser jFileChooser = new JFileChooser();
  36. jFileChooser.setSelectedFile(new File("E:\\lang\\lua\\workspace\\LuaProject\\src\\main.lua"));
  37. jFileChooser.setFileFilter(new FileFilter() {
  38. @Override
  39. public String getDescription() {
  40. return "Lua(.lua)";
  41. }
  42.  
  43. @Override
  44. public boolean accept(File f) {
  45. if (f.isDirectory()) {
  46. return true;
  47. }
  48. return f.getName().toLowerCase().endsWith(".lua");
  49. }
  50. });
  51.  
  52. JButton jButton = new JButton("click");
  53. jFrame.add(jButton);
  54. jButton.addActionListener(new ActionListener() {
  55. @Override
  56. public void actionPerformed(ActionEvent e) {
  57. int result = jFileChooser.showOpenDialog(jFrame);
  58. if (result == JFileChooser.CANCEL_OPTION) {
  59. return;
  60. }
  61. File chooseFile = jFileChooser.getSelectedFile();
  62.  
  63. String luaFilePath = chooseFile.getAbsolutePath();
  64. jFrame.add(new JLabel("<html><font color=blue>" + luaFilePath));
  65. jTextField.setText(luaFilePath);
  66. jFrame.validate();
  67. // create an environment to run in
  68. Globals globals = JsePlatform.standardGlobals();
  69.  
  70. // Use the convenience function on Globals to load a chunk.
  71. LuaValue chunk = globals.loadfile(luaFilePath);
  72.  
  73. // Use any of the "call()" or "invoke()" functions directly on the chunk.
  74. chunk.call(LuaValue.valueOf(luaFilePath));
  75. }
  76. });
  77.  
  78. SwingConsole.run(jFrame, WIDTH, 200);
  79. }
  80.  
  81. protected static void parserUT(File fileFullName) {
  82. try {
  83.  
  84. // Create a LuaParser. This will fill in line and column number
  85. // information for most exceptions.
  86. LuaParser parser = new LuaParser(new FileInputStream(fileFullName));
  87.  
  88. // Perform the parsing.
  89. Chunk chunk = parser.Chunk();
  90.  
  91. // Print out line info for all function definitions.
  92. chunk.accept(new Visitor() {
  93. public void visit(Exp.AnonFuncDef exp) {
  94. System.out.println("Anonymous function definition at "
  95. + exp.beginLine + "." + exp.beginColumn + ","
  96. + exp.endLine + "." + exp.endColumn);
  97. }
  98.  
  99. public void visit(Stat.FuncDef stat) {
  100. System.out.println("Function definition '" + stat.name.name.name + "' at "
  101. + stat.beginLine + "." + stat.beginColumn + ","
  102. + stat.endLine + "." + stat.endColumn);
  103.  
  104. System.out.println("\tName location "
  105. + stat.name.beginLine + "." + stat.name.beginColumn + ","
  106. + stat.name.endLine + "." + stat.name.endColumn);
  107. }
  108.  
  109. public void visit(Stat.LocalFuncDef stat) {
  110. System.out.println("Local function definition '" + stat.name.name + "' at "
  111. + stat.beginLine + "." + stat.beginColumn + ","
  112. + stat.endLine + "." + stat.endColumn);
  113. }
  114. });
  115.  
  116. } catch (ParseException e) {
  117. System.out.println("parse failed: " + e.getMessage() + "\n"
  118. + "Token Image: '" + e.currentToken.image + "'\n"
  119. + "Location: " + e.currentToken.beginLine + ":" + e.currentToken.beginColumn
  120. + "-" + e.currentToken.endLine + "," + e.currentToken.endColumn);
  121.  
  122. } catch (IOException e) {
  123. System.out.println("IOException occurred: " + e);
  124. e.printStackTrace();
  125. }
  126. }
  127.  
  128. }
  129.  
  130. class SwingConsole {
  131.  
  132. public static void run(final JFrame frame, final int width, final int height) {
  133. SwingUtilities.invokeLater(new Runnable() {
  134.  
  135. @Override
  136. public void run() {
  137. frame.setSize(width, height);
  138. frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  139. frame.setLocationRelativeTo(null);
  140. frame.setVisible(true);
  141. }
  142. });
  143. }
  144. }
  1. --array={1,2,3,4,5}
  2. --for key, var in pairs(array) do
  3. -- print(key,var)
  4. --end
  5.  
  6. --
  7. --function f(a, b)
  8. --return a or b
  9. --end
  10. --
  11. --print ("output:",f(1,3));
  12.  
  13. require('mobdebug')
  14. function maximum (a)
  15. local mi = 1 -- maximum index
  16. local m = a[mi] -- maximum value
  17. for i,val in ipairs(a) do
  18. if val > m then
  19. mi = i
  20. m = val
  21. end
  22. end
  23. return m, mi
  24. end
  25.  
  26. print(maximum({8,10,23,12,5})) --> 23 3

  

  

GUIForDebug的更多相关文章

随机推荐

  1. Linux查看硬盘使用时间等信息

    查看硬盘信息的很多命令,都需要root权限,如果普通用户无法看到信息,请切换至root: 1.查看硬盘使用时间等信息 硬盘使用时间很重要,硬盘理论寿命是3万小时以上 $ sudo smartctl - ...

  2. linux它SQL声明简明教程---WHERE

    我们并不一定必须注意,每次格里面的信息是完全陷入了.在很多情况下,我们需要有选择性地捕捞数据.对于我们的样本.我们可以只抓住一个营业额超过 $1,000 轮廓. 做这个事情,我们就须要用到 WHERE ...

  3. 完整导出IntelliJ IDEA的快捷键

    工欲善其事,必先利其器. 常常和代码打交道的人,熟练使用IDE快捷键那是必须的,由于快捷键能够把你从各种罗嗦事中解放出来.比方,假设没有快捷键,你就须要常常性的暂停快速执行的大脑,右手凭记忆摸到鼠标, ...

  4. JQuery是继prototype之后又一个优秀的Javascript库

    JQuery是继prototype之后又一个优秀的Javascript库.它是轻量级的js库 ,它兼容CSS3,还兼容各种浏览器(IE 6.0+, FF 1.5+, Safari 2.0+, Oper ...

  5. Android 网络通信框架Volley基本介绍

    Volley主页 https://android.googlesource.com/platform/frameworks/volley http://www.youtube.com/watch?v= ...

  6. Windows 10Bash命令

    Windows 10预览版14316开启Bash命令支持 00x0 前言 4月7日凌晨,微软推送了最新的Windows 10一周年更新预览版14316,其中重要的是原生支持Linux Bash命令行支 ...

  7. Get与Post的差别

    Http定义了与server交互的不同方法,最主要的方法有4种,各自是GET,POST.PUT,DELETE. URL全称是资源描写叙述符.我们能够这样觉得:一个URL地址,它用于描写叙述一个网络上的 ...

  8. OpenStack及其构成简介1

    第一部分 OpenStack及其构成简介 一.云计算   云计算是一种计算模型,它将诸如运算能力.存储.网络和软件等资源抽象成为服务,以便让用户通过互联网远程享用,付费的形式也如同传统公共服务设施一样 ...

  9. 字符串匹配的KMP算法(转)

    字符串匹配是计算机的基本任务之一. 举例来说,有一个字符串"BBC ABCDAB ABCDABCDABDE",我想知道,里面是否包含另一个字符串"ABCDABD" ...

  10. Mvc 异常处理 ajax的 和 不是ajax的!

    using ImageUpload.Auth; using System; using System.Collections.Generic; using System.Linq; using Sys ...