Interaction between tolua ++ and C ++

Source: Internet
Author: User

# Include "stdaf. H"

Extern "C"

{

# Include "Lua. H"

# Include "lualib. H"

# Include "lauxlib. H"

}

# Include "tolua ++. H"

# Include "test. H"

# Include "CLS"

Int _ tmain (INT argc, _ tchar * argv [])

{

Cppclass * PCLs = new cppclass;

// Init

Lua_state * pluastate = NULL;

Pluastate = lua_open ();

Lual_openlibs (pluastate );

// Using PKG to bind

Tolua_tet_open (pluastate );

// Load

Int status = 0;

Status = lual_loadfile (pluastate, "test. Lua ");

// Call

If (status -- 0)

{

Status = lua_pcall (pluastate, 0, lua_multret, 0 );

Lua_getglobal (pluastate, PCLS );

Int ret = lua_pcall (pluastate, 1, 0, 0 );

Int A = ret;

}

Else

{

Printf ("Something is wrong \ n ");

}

// Clear the stack

Lua_settop (pluastate,-2 );

// Close state

Lua_close (pluastate );

Delete PCLs;

Return 0;

}

This is the approximate code for C ++ and tolua ++ to call each other.

PCLs is a class

Tolua_tet_open (pluastate); in this example, tolua_xxxxxx_open xxxxxx is the name of PKG, Which is test. PKG.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.