lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


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:(