Lua and c

Source: Internet
Author: User

I recently used lua to write game server logic.
Writing server logic with lua is much simpler! You know!

The first problem is about the return value of lua's C call.
// Test the returned table
/**
The following code is equivalent to lua:
Function return_table ()
Local t = {}
T. result = true
T. data = "hello"
Return t
End
*/
Int tableReturnTable (lua_State * L)
{
Lua_newtable (L );
Int table_index = lua_gettop (L );

Lua_pushboolean (L, true );
Lua_setfield (L, table_index, "result ");

Lua_pushstring (L, "hello", 5 );
Lua_setfield (L, table_index, "data ");

Return 1;
}
Problem 2 multi-parameter return
// Multiple responses for testing
/**
The following code is equivalent to lua:
Function mult_return ()
Return "hello", 100, true
End
*/
Int mult_return (lua_Status * L)
{
Lua_pushstring (L, "hello ");
Lua_pushnumber (L, 100 );
Lua_pushboolean (L, true );
Return 3;
}
Third, delete the elements in the table.
Local t = {}
T. hello = "hello"
T [1] = 100
The deletion method is as follows:
T. hello = nil
T [1] = nil
Clear table
Table. foreach (t, function (k, v) t [k] = nil end)

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.