在Java中执行Lua脚本? [英] Execute Lua script in java?

查看:391
本文介绍了在Java中执行Lua脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我现在正在学习Java,并构建了一个可以按我想要的方式运行的GUI.但是我需要一种可以在我的Java脚本中调用lua脚本的方法.我对lua相当满意,并且已经在lua中使用下面的代码通过cmd从外部启动另一个lua脚本.

os.execute('开始数据保存" cmd/kcd"..path..&'..r_path..'bin\luae.exe testscript.lua&退出')

我是Java的新手,正在研究并且感到非常困惑.但这背后的原因是,我正在为仅读取lua代码的游戏进行外部对话.因此,计划是从对话框中获取信息,并使用新的对话框信息执行lua文件,然后使用lua中的:write()生成具有此信息的新lua文件.

我只需要能够在Java中执行带有其自变量的lua文件.

解决方案

我不知道这是否是您要寻找的答案,但是您可以使用Runtime类在Java中运行shell命令包含在java.lang包中,并且它的exec(String cmd)方法通常是java本身中的一个很好的os.execute替代品.

用法

 public class Test {
    public static void main(String[] args) {
        Runtime.getRuntime().exec('start "Data save" cmd /k "cd ' .. path .. ' & ' .. r_path .. 'bin\luae.exe testscript.lua & exit "')
    }
}
 

您可能通常希望进一步研究Runtime类.

但是,如果您真的想用Java解释Lua,那么我会听到 LuaJ 是一个不错的选择.

So I’m learning java right now and built a GUI which functions how I want. But I need a way I can call a lua script within my java script. I’m pretty good with lua and have used the code below in lua to launch another lua script externally through the cmd.

os.execute(‘start "Data save" cmd /k "cd ‘ .. path .. ‘ & ‘ .. r_path .. ‘bin\luae.exe testscript.lua & exit "‘)

Me being new to java was researching and was getting really confused. But the reason behind this is I’m making an external dialog for a game that only reads lua code. So the plan is to get the information from the dialog and execute the lua file with the new dialog info then generate a new lua file with this information with :write() in lua.

I just need to be able to execute a lua file within java with arguments that’s it.

解决方案

I don't know if this is the answer you're looking for, but you can run shell commands in Java with the Runtime class which is already included in the java.lang package, and its exec(String cmd) method is generally a good os.execute substitute in java itself.

Usage

public class Test {
    public static void main(String[] args) {
        Runtime.getRuntime().exec('start "Data save" cmd /k "cd ' .. path .. ' & ' .. r_path .. 'bin\luae.exe testscript.lua & exit "')
    }
}

You might want to look more into the Runtime class in general.

But if you're literally looking to interpret Lua in Java then I heard LuaJ is a good option.

这篇关于在Java中执行Lua脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆