Use VC to load Lua. lib and configure the Lua script ....

Source: Internet
Author: User

Generally, Lua. Lib is not used. How does it come from? It is actually very simple.

We all know that Lua is cross-platform and open-source. So we can see a lot of internal code, so as to provide convenience for Lib.

 

 

Let's explain the answer. Lua. lib can be automatically generated.

Below are detailed steps:

1. The VC project, Win32 static library, is named Lua.

2. Load all *. C and *. h In the SRC file under the Lua root path.

3. debug and release compile with you.

4. You can use Lua. Lib anywhere, of course, in windows.

 

 

/* VC example

* $ Chenxiong
$2009.11.12
*/

Extern "C "{
# Include "Lua. H"
# Include "lualib. H"
# Include "lauxlib. H"
}

# Pragma comment (Lib, "Lua. lib ")

# Include <stdio. h>
# Include <string>
# Include <conio. h>
Using namespace STD;

// "Luatest. Lua"
Int main (void)
{
Lua_state * l = lua_open ();/* initialize opens Lua to obtain the Lua state base */
Lual_openlibs (l); // load all the Lua standard Libraries

Lual_dofile (L, "luatest. Lua"); // execute luatest. Lua and add the assort function to the luatest. Lua stack.
Lua_getglobal (L, "assort"); // use the function name to extract the function address and press it into the stack.
Lua_pushstring (L, "Heihei"); // press the first parameter to the stack.
Lua_pcall (L, 0); // call the assort Function

Int I = (INT) lua_tonumber (L,-1 );
Lua_pop (L, 1 );
Printf ("is % d/N", I );
Lua_close (L );
Return 0;

}

 

 

 

-- [[Luatest. Lua... test function
2009.11.12]

I =-1
Bill = "Hello World"
Function assort (Bill)
D = string. Len (Bill)
If D> = 5 then
I = 1
Else
I = 0
End
Return I
End

Print (assort (Bill ))

 

 

 

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.