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的更多相关文章
随机推荐
- Android 结合实例学会AsyncTask的使用方法
AsyncTask运行时经过四个步骤,运行四个方法: 1.onPreExecute(),执行在UI线程,能够设置或改动UI控件,如显示一个进度条 2.doInB ...
- 基于TFTP协议的远程升级设计
说明:因为CSDN博客编辑器对word格式近乎不支持.因此对表格使用了图片方式(最后一个表格未使用图片格式.大家能够看看效果),CSDN博客编辑器上传图片十分不人性化(直接复制图片是不显示的),因此本 ...
- HBase经常使用操作之namespace
1.介绍 在HBase中,namespace命名空间指对一组表的逻辑分组,类似RDBMS中的database,方便对表在业务上划分.Apache HBase从0.98.0, 0.95.2两个版本号開始 ...
- ZOJ 3635 Cinema in Akiba(线段树)
Cinema in Akiba (CIA) is a small but very popular cinema in Akihabara. Every night the cinema is ful ...
- HDU1789Doing Homework again(贪婪)
HDU1789Doing Homework again(贪心) 题目链接 题目大意:给你n们作业的最后期限和过了这个期限没做须要扣的分数.问如何安排能够使得扣分最少. 解题思路:贪心,将扣分多的作业排 ...
- 关于split与StringTokenizer的理解
关于split与StringTokenizer的理解 一.split 依据匹配给定的正則表達式来拆分此字符串.此方法返回的数组包括此字符串的子字符串,每一个子字符串都由还有一个匹配给定表达式的子 ...
- 【Unity Shaders】使用CgInclude让你的Shader模块化——Unity内置的CgInclude文件
本系列主要參考<Unity Shaders and Effects Cookbook>一书(感谢原书作者),同一时候会加上一点个人理解或拓展. 这里是本书全部的插图. 这里是本书所需的代码 ...
- Knockout应用开发指南 第三章:绑定语法(3)
原文:Knockout应用开发指南 第三章:绑定语法(3) 12 value 绑定 目的 value绑定是关联DOM元素的值到view model的属性上.主要是用在表单控件<input&g ...
- malloc一次性最大能申请多大内存空间
受用户态内存地址空间的限制.64 位系统下分配几个 T 不成问题. 著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处.作者:zz matrix链接:http://www.zhihu. ...
- asp.net用户身份验证时读不到用户信息的问题 您的登录尝试不成功。请重试。 Login控件
原文:asp.net用户身份验证时读不到用户信息的问题 您的登录尝试不成功.请重试. Login控件 现象1.asp.net使用自定义sql server身份验证数据库,在A机器新增用户A,可以登录成 ...