[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Cannot call lua function from C application
- From: "Yang Fan" <missdeer@...>
- Date: Tue, 1 Aug 2006 00:55:30 +0800
Hi all,
I'm new in Lua.I'm trying embedding the interpreter into my C++ application.I write a script file like this:
function main (data)
ConsoleOutput(data)
str = data
end
while i'm using C++ code to call this "main" function, but failed:(
if (luaL_loadfile(L, pszFileName))
{
trace1(("Cannot run lua file: %s", lua_tostring(L,-1)));
}
/* push functions and arguments */
lua_getglobal(L, "main"); /* function to be called */
lua_pushlstring(L, m_data.c_str(), m_data.size());
/* do the call (1 arguments, 0 result) */
if (lua_pcall(L, 0, 0, 0) != 0)
{
trace1(( "Error running function \"main\": %s", lua_tostring(L, -1)));
}
error msg showed:Error running function "main": attempt to call a string value
i really don't know what's wrong with my code, need your help! thanks!!
And sorry for my pool english:(