English 中文(简体)
C++ 的 CallLua 函数, 缺少参数
原标题:Call Lua function from C++, missing argument

I have strange problem, with calling Lua function from C++. I have in Lua:

Player = 
{
    Number = 0.43,
    Text = "SomeText",
}

function Player:Func(a, b)  
    return (a * b);
end

Before lua_pcall my stack looks:
table
function
3
4

I call this function with:

lua_pcall(L, 2, 1, 0)

我从Lua那里得到错误:

尝试对当地b(无价值)进行算术

当我改变卢阿的脚本

return (a * b);

return a;

There is no error, but from lua_至number(L, -1); I get value 4 (my second argument in C:/), so it looks that my second argument in C is first in Lua. Do you know what I made wrong in my code ?
How I construct stack:

lua_getglobal (L, "Player");
lua_pushstring(L, "Func");
lua_gettable(L, -2);
lua_pushnumber(L, 3.0);
lua_pushnumber(L, 4.0);
最佳回答

Bens评论是关键 - 阅读“Lua的方案编制”第150页中面向目标的方案拟订部分。

http://www.lua.org/pil/16.html>http://www.lua.org/pil/16.html

The effect of the colon is to add an extra hidden parameter in a method definition and to add an extra argument in a method call.

所以您需要将“ 账户” 对象作为第一个参数, 或者( 在此情况下更容易) 将 < code> 函数玩家: func( a, b) 改为 < code > 函数玩家 。 func( a, b)

问题回答

暂无回答




相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签