lua-users home
lua-l archive

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


Lloyd wrote:
Hi,
I am a lua newbie. This is my first program to print "Hello world" using C API. It gives me runtime error!. Where is the problem?

[snip]

int main()
{
    void *ud=NULL;

    lua_State* L=lua_newstate(my_lua_alloc,ud);
    if(L==NULL)
    {
        cout<<"Memory allocation error"<<endl;
        return 0;
    }

You need to initialize the Lua libraries here; otherwise, for example, the print() function won't be available.


      luaL_openlibs(ud);

    int r=lua_load(L,my_lua_reader,ud,"Test Chunk");

[rest snipped]