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的更多相关文章
随机推荐
- Linux查看硬盘使用时间等信息
查看硬盘信息的很多命令,都需要root权限,如果普通用户无法看到信息,请切换至root: 1.查看硬盘使用时间等信息 硬盘使用时间很重要,硬盘理论寿命是3万小时以上 $ sudo smartctl - ...
- linux它SQL声明简明教程---WHERE
我们并不一定必须注意,每次格里面的信息是完全陷入了.在很多情况下,我们需要有选择性地捕捞数据.对于我们的样本.我们可以只抓住一个营业额超过 $1,000 轮廓. 做这个事情,我们就须要用到 WHERE ...
- 完整导出IntelliJ IDEA的快捷键
工欲善其事,必先利其器. 常常和代码打交道的人,熟练使用IDE快捷键那是必须的,由于快捷键能够把你从各种罗嗦事中解放出来.比方,假设没有快捷键,你就须要常常性的暂停快速执行的大脑,右手凭记忆摸到鼠标, ...
- JQuery是继prototype之后又一个优秀的Javascript库
JQuery是继prototype之后又一个优秀的Javascript库.它是轻量级的js库 ,它兼容CSS3,还兼容各种浏览器(IE 6.0+, FF 1.5+, Safari 2.0+, Oper ...
- Android 网络通信框架Volley基本介绍
Volley主页 https://android.googlesource.com/platform/frameworks/volley http://www.youtube.com/watch?v= ...
- Windows 10Bash命令
Windows 10预览版14316开启Bash命令支持 00x0 前言 4月7日凌晨,微软推送了最新的Windows 10一周年更新预览版14316,其中重要的是原生支持Linux Bash命令行支 ...
- Get与Post的差别
Http定义了与server交互的不同方法,最主要的方法有4种,各自是GET,POST.PUT,DELETE. URL全称是资源描写叙述符.我们能够这样觉得:一个URL地址,它用于描写叙述一个网络上的 ...
- OpenStack及其构成简介1
第一部分 OpenStack及其构成简介 一.云计算 云计算是一种计算模型,它将诸如运算能力.存储.网络和软件等资源抽象成为服务,以便让用户通过互联网远程享用,付费的形式也如同传统公共服务设施一样 ...
- 字符串匹配的KMP算法(转)
字符串匹配是计算机的基本任务之一. 举例来说,有一个字符串"BBC ABCDAB ABCDABCDABDE",我想知道,里面是否包含另一个字符串"ABCDABD" ...
- Mvc 异常处理 ajax的 和 不是ajax的!
using ImageUpload.Auth; using System; using System.Collections.Generic; using System.Linq; using Sys ...