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)