int main()
{
	Lua lua;
	auto global = lua.GetGlobalEnvironment();
	
	auto newCar = lua.CreateFunction<LuaTable()>(
		[&]() -> LuaTable 
		{
			LuaTable table = lua.CreateTable();
			table.Set("type", "renault");
			return table;
		}
	);

	global.Set("newCar", newCar);

	// Run the script that chooses a function to return
	lua.RunScript(
		"x = newCar()['type']"
	);

	auto type = global.Get<std::string>("x");
	
	return type.compare("renault");
}
int main()
{

	Lua lua;

    LuaTable tbl = lua.CreateTable();
    tbl.Set("name", "Chuck Norris");
    tbl.Set("age", 1337);
    tbl.Set("0", "divide by");
    tbl.Set(1337, "leet");
    
    int keys = 3;
    
    tbl.ForAllStringKeys([&](std::string key, LuaType::Value value)
    {
        keys--;
    });

	return keys;
}
Example #3
0
	static int GetColumnInfo( T* p, lua_State *L )
	{
		PlayerNumber pn = Enum::Check<PlayerNumber>(L, 1);
		int iCol = IArg(2) - 1;
		if( iCol < 0 || iCol >= p->m_iColsPerPlayer )
		{
			LOG->Warn( "Style:GetColumnDrawOrder(): column %i out of range( 1 to %i )", iCol+1, p->m_iColsPerPlayer );
			return 0;
		}

		LuaTable ret;
		lua_pushnumber( L, p->m_ColumnInfo[pn][iCol].track+1 );
		ret.Set( L, "Track" );
		lua_pushnumber( L, p->m_ColumnInfo[pn][iCol].fXOffset );
		ret.Set( L,  "XOffset" );
		lua_pushstring( L, p->ColToButtonName(iCol) );
		ret.Set( L, "Name" );
		
		ret.PushSelf(L); 
		return 1;
	}