我正在研究如何在lua字符串(双括号)中嵌入lua函数。我只想详细解释一下我的情况:
example.lua:
function my_message(msg)
return "Your message: " + msg
end
function makeString()
page = [[
<html>
<body>
<!--
I want to call my_message(..) lua function and embed the value here.
我尝试将表写入ini文件,所有操作都正常,直到我添加了一行lua_tostring(L,-2),然后lua_next(L,-2)开始发出错误。在我的理解中,这一行是如何影响的,我只是从堆栈中获取值,而不是更多。我怎么才能修好它?
{
// Push an initial nil to init lua_next
lua_pushnil(inOutState);
// Parse the table at index
while (lua_next(inOutState, -2))
{
if (lua_isstring(inOutState
我正在尝试写一个lua开关,根据我目前所读到的,这似乎是通过使用一个表来实现的。所以我做了一个非常简单的表,但是当我尝试运行它的时候,我得到一个错误,说table index is null。
最终我想要的是基于不同的输入,这段代码应该调用不同的lua文件。但就目前而言,由于我是这门语言的新手,我想我应该满足于没有那个索引错误。
谢谢
#!/usr/bin/lua
-- hello world lua program
print ("Hello World!")
io.write('Hello, where would you like to go?\n'
我试图在c和lua中制作一个简单的calc应用程序。但出于某种原因,它正在克服基于输入的命令。我知道代码是无用的,不可行的,但我正在学习使用lua (luaJIT),c api,所以请容忍我。当我运行这段代码时,它会得到用户的输入(即添加),但之后什么也不做,并跳到代码的末尾。但是我把它放在一个无限循环中来阻止它,但是它仍然跳过if语句中的代码。有什么办法解决这个问题吗?任何帮助都是非常感谢的。谢谢!
C代码:
int main()
{
fflush(stdin);
int status;
int trace = 1;
int x = 0;
lua_Number lua_tonumber (
所以我试着用lua语言做一种语言,我把“输出”一词替换为“打印”和一些更多的单词,但是如果有人输出(“输出”),它也会替换它。我怎样才能检查它是否在字符串中?代码:
output('trying to make a new language in lua')
output('\n')
local file = io.open(arg[1],"r")
local code = file:read "*a"
local filename = arg[1]
local function execute()
code = code
(对不起我的英语坏了)
我试图在字符串中匹配一个or,如果它没有用单引号括起来,就用减号(-)替换它。例如:
local input1 = "'condition1' or 'condition2'"
input1:gsub(pattern, "-") --> Should return "'condition1' - 'condition2'"
local input2 = "'condition1 or condition2'" --
我试着用罗技的鼠标来发送字符串,像罗技提供的一个软件来做
我点击前进按钮,它将发送字符串,但我不能使用winform发送字符串到它来修改它
我发现罗技有
我尝试用OnEvent函数来控制鼠标点击发送字符串
但我以前从来没喝过。
下面是我的c#代码
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using LuaInterface;
namespace LuaScript
{
public partial class Form1 : Form
{
pu
我正试图用其他案文取代一些案文。很简单对吧?哈哈。
首先,我有一串文字:
local str = "This is some >>1234 text. This is some >>>/other/1234 text."
您将注意到文本中有趣的外观格式。我需要用HTML替换那些。但是有一个问题:我需要使用该格式中的数据访问数据库。我使用以下格式获取数据:
local pattern1 = ">>(%d+)"
local pattern2 = ">>>/(%w+)/(%d*)"
在这两种模
我是lua编程的新手。我正在寻找一个lua脚本,可以读取通过Suricata从互联网下载的文件,并检测文件是否发生了变化。任何帮助都将不胜感激。提前谢谢。 如下所示: function init(args)
return {http.response_body = tostring(true)}
end
local function read_file(path)
local file = open(path, "rb") -- r read mode and b binary mode
if not file then return nil end
我正在尝试修改现有的lua脚本,以清理Aegisub中的字幕数据。
我想添加删除包含符号"♪“的行的功能。
下面是我要修改的代码:
-- delete commented or empty lines
function noemptycom(subs,sel)
progress("Deleting commented/empty lines")
noecom_sel={}
for s=#sel,1,-1 do
line=subs[sel[s]]
if line.comment or line.text=="
我对Lua很陌生。
说我有一根"1234567890“字串。
我想迭代所有可能的3位数。(即123,234,345,456....)
for m in string.gmatch("1234567890","%d%d%d") do
print (m)
end
但这给出了输出123,456,789。
我应该使用什么样的模式?
其次,还有一个相关的问题,我如何指定一个3-digit数字?"%3d"似乎不起作用。"%d%d%d"是唯一的路吗?
注意:这不是标记Regular expression,因为Lua没有Reg
我有一个Lua解释器,每当我在代码中出现语法错误时,返回的错误消息就是attempted to call a string value,而不是有意义的错误消息。例如,如果我运行这个lua代码:
for a= 1,10
print(a)
end
它将返回错误'do' expected near 'print',而不是返回有意义的attempted to call a string value和行号。
我的C++代码如下:
void LuaInterpreter::run(std::string script) {
luaL_openlibs(m_ma
我正在学习Lua,我对python有一些了解,我想要像python一样替换字符串中的字符,但我没有幸运地找到确切的翻译函数。
我想在Lua中实现这个:
l = ["#01","#02", "#03"]
print(l)
for i in range(len(l)):
l[i]=l[i].replace("#","")
#print (i)
print (l)
所以我一直在想办法解决这个问题,我做了以下工作
main.lua
package.path = io.popen("cd"):read'*all' -- to set the path the same as main.lua (for exporting)
local u = require("utilities") -- this is the line that dosent work
utilities.lua
local u = {}
function u.GetService(s)
return require(tost
我使用LuaSocket和http.request调用一个远程PHP脚本,该脚本生成一个Lua表并将其输出到浏览器。
当我将http.request响应存储在一个变量中时,它是一个字符串,这使得表在我的Lua代码中不可用。
例如:
eventData = http.request("http://www.example.com/events.php")
print( eventData )
--print outputs this "string", that is really a Lua table that PHP generated
months={
是否有可能从导入的LUA模块完全反转代码?
例如,我们有
mymath.lua
作为一个模块
local mymath = {}
local a = 1
function mymath.add(a,b)
print(a+b)
end
function mymath.sub(a,b)
print(a-b)
end
function mymath.mul(a,b)
print(a*b)
end
function mymath.div(a,b)
print(a/b)
end
return mymath
我们有
testmodule.lua
如何在lua中将多行字符串变成单行字符串?
我试过这个:
function removeMultilines(str)
return str:gsub("\n")
end
但不起作用。
所以基本上,我想把str1变成str2
local str1 = [[Hey,
how are you today?
Whats your name?]]
local str2 = "Hey, how are you today? Whats your name?"
有人知道我能怎么接近吗?欢迎任何帮助,只需评论:D
我有这个C++代码,它需要调用Lua函数。当我得到函数返回值时,一切都很好(“甚至打印结果”),但是当涉及到存储变量时,该值将消失。
LS = luaL_newstate();
luaL_openlibs(LS);
lua_register(LS, "lua_HostFunction", Link::lua_HostFunction);
if (luaL_dofile(LS, "./src/solutions/16t20.lua") != LUA_OK) {
cout << "Error: File not found or inv