我试图在Lua中加载以下C库:
#include <stdio.h>
#include <stdlib.h>
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
void stackDump(lua_State* lua)
{
int i, t;
int top = lua_gettop(lua);
printf("Stack dump: ");
for (i = 1; i <= top; i++)
{
这是密码。目的是打印信息。在PrintC中,我想让e...but作为cdata到达。我怎么才能打开它或者绕过它呢?
extern "C"
{
static int PrintC ( lua_State *L )
{
// does not work cdata
//executor* e = ( executor* ) luaL_checkudata(L, 1, "cdata"); does n
//luaL_checkudata(L, 1, "void *");
我正在和Lua玩下面的链接:,并对一个点感到困惑。
Lua 5.2.4 Copyright (C) 1994-2015 Lua.org, PUC-Rio
> x=10
> local i=1
> while i<=x do
>> local x = i*2
>> print(x)
>> i=i+1
>> end
stdin:1: attempt to compare nil with number
stack traceback:
stdin:1: in main chunk
[C]: in ?
我
我是Lua的新手,使用了一些教程,尝试了一些基本的东西,比如编写通用算法等。
但是我在我的mac os机器上使用lua解释器时遇到了一些问题。
例如,我们有一个名为'sample.lua‘的文件,其中包含以下代码行:
function fib(n) return n<2 and n or fib(n-1)+fib(n-2) end
如何从终端运行该函数?如果我不使用任何函数,我只需要使用'lua script.lua‘来调用脚本-工作!
下一个问题是关于非编译的lua-source和编译的lua-source之间的基本理解。为什么lua代码不需要编译就可以运行,就像我之前
我正在寻找一种能够在我的c代码中读取lua的主要函数的方法。
我也在寻找一种将C函数传递给lua的方法
在我的示例代码中,LoadTBL将是来自C代码的函数
TBL =
{
{ Init, 0, 15, 00 },
{ End, 1, 16, 00 }
}
function main()
for key, value in pairs(TBL) do
result, msg = LoadTBL(value[1], value[2], value[3]);
if( not result ) then return f
我有一个用来读取Lua的类,我想让它可以一次加载多个脚本,而不会发生冲突,也就是说,当第一个脚本执行时,Lua变量的值被保存在第一个脚本中。 我希望程序能输出它- print = 123
print = Hi 0
Result = 3
print = Hi 1
Result = 3
print = Hi 2
Result = 3
print = Hi 3
Result = 3
print = Hi 4
Result = 3
print = Hi 5
Result = 3
print = Hi 6
Result = 3
print = Hi 7
Result = 3
print = 123
我想知道在C++代码中与lua /O交互的最佳方式。 lua脚本: while true do
local input = io.read("*line")
if input == "hello" then
print("world")
else
print("hmmm...")
end
end C++代码: lua_State* L = luaL_newstate();
luaL_openlibs(L);
int r = luaL_dofile(L, "f
我使用幻影类型来模拟堆栈的状态,作为OCaml的包装模块(Lua通过堆栈与C/OCaml通信)。小代码示例:
type 's t
type empty
type 's table
type top
val newstate : unit -> empty t (* stack empty *)
val getglobal : empty t -> top table t (* stack: -1 => table *)
某些堆栈操作在表和数组表上都是可能的(在Lua中没有真正的数组);有些则不是。
type 's table
我正在使用Lua for Windows。
我正在尝试来自wxLua网站的示例脚本;但是,当我运行该脚本时,它在第一行(即require 'wx' )上失败:
lua: cannot open wx: No such file or directory
但是,在REPL/解释器中执行require 'wx'时,它工作正常。
我做了另一个脚本来输出print(package.cpath)和print(package.path),在我看来,它们和REPL中的脚本是一样的。
为什么,在运行脚本时,它无法找到'wx'?
在本例中,我同时运行脚本和来自同一
在我的Lua脚本中,我有多个使用相同“结构”的库。例如,我有包含a.lua和require('c')的内容。b.lua和c.lua都有一个信息函数。b.lua让它打印"b“,c.lua让它打印"c”。在a.lua中,我希望使用来自B.lua或C.lua的info()启动一个协同线。
这是我的b.lua:
b = {}
function b.info()
coroutine.yield()
print("b")
print("b2")
end
C.lua有一个类似的结构,但大多数B是用C代替的。当尝试用local co
我正在尝试设置,以便可以使用来使用.NET框架中的一些类。我可以通过Lua命令行运行它,但是当我尝试在init.lua启动脚本中使用require "CLRPackage"时,它似乎找不到所需的文件。启动Wireshark时出现以下异常:
Lua: Error during loading:
C:\Program Files\Wireshark\luascript.lua:25: module 'CLRPackage' not found:
no field package.preload['CLRPackage']
no fi
为了用C语言定义Lua可调用的方法,它必须匹配给定的签名,并使用Lua API来检索参数和返回结果。我正在编写Lua的C#包装器,我感兴趣的是能够调用任意的C#方法,而不需要它们遵循这些约定。当包装像D这样的东西时,可以使用模板系统为任何给定的方法动态创建粘合代码。我在想,这在C#中也是可能的,但通过使用动态代码生成。
C API看起来像这样,生成的代码将通过我的库的较低级别的部分来操作它,该部分P/调用Lua C库。
static int foo (lua_State *L)
{
int n = lua_gettop(L); /* number of arguments */
我有一个Entity类,它包含一些属性(数据片段)。这些属性存储在名称=>值的映射中。
class Entity
{
public:
// Sets the attribute with the specified name.
void attribute(const std::string& name, const GenericType& value) {
m_attributes[name] = value;
}
// Returns the attribute with the specified name.