Skip to content

Commit f47134f

Browse files
committed
Updated docs
1 parent 4986991 commit f47134f

File tree

2 files changed

+48
-32
lines changed

2 files changed

+48
-32
lines changed

docs/index.md

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,25 @@ Follow the [main setup guide for integration of Firebase in Defold](https://www.
2727
```lua
2828
function init(self)
2929
-- use firebase only if it is supported on the current platform
30-
if firebase then
31-
firebase.init()
30+
if not firebase then
31+
return
32+
end
33+
34+
-- initialise firebase and check that it was successful
35+
local ok, err = firebase.init()
36+
if not ok then
37+
print(err)
38+
return
39+
end
40+
41+
-- initialise analytics
42+
firebase.analytics.init(function(self, ok, err)
43+
if not ok then
44+
print(err)
45+
return
46+
end
47+
48+
-- log data
3249
firebase.analytics.set_screen("myscreen", "collection")
3350
firebase.analytics.log_string("character", "storm trooper")
3451
firebase.analytics.log_int("kills", 152)
@@ -39,7 +56,7 @@ function init(self)
3956
string = "some_string"
4057
}
4158
firebase.analytics.log_table("stats", t)
42-
end
59+
end)
4360
end
4461
```
4562

firebase_analytics/src/firebase_analytics.cpp

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -41,41 +41,40 @@ static int FirebaseAnalytics_Analytics_InstanceId(lua_State* L) {
4141
DM_LUA_STACK_CHECK(L, 0);
4242
g_FirebaseAnalytics_InstanceIdCallback = dmScript::CreateCallback(L, 1);
4343

44-
Future<std::string> future = analytics::GetAnalyticsInstanceId();
45-
future.OnCompletion([](const Future< std::string >& completed_future) {
46-
if (!dmScript::IsCallbackValid(g_FirebaseAnalytics_InstanceIdCallback))
47-
{
48-
dmLogWarning("Analytics InstanceId callback is not valid");
49-
return;
50-
}
44+
analytics::GetAnalyticsInstanceId()
45+
.OnCompletion([](const Future< std::string >& completed_future) {
46+
if (!dmScript::IsCallbackValid(g_FirebaseAnalytics_InstanceIdCallback))
47+
{
48+
dmLogWarning("Analytics InstanceId callback is not valid");
49+
return;
50+
}
5151

52-
if (dmScript::SetupCallback(g_FirebaseAnalytics_InstanceIdCallback))
53-
{
54-
lua_State* L = dmScript::GetCallbackLuaContext(g_FirebaseAnalytics_InstanceIdCallback);
52+
if (dmScript::SetupCallback(g_FirebaseAnalytics_InstanceIdCallback))
53+
{
54+
lua_State* L = dmScript::GetCallbackLuaContext(g_FirebaseAnalytics_InstanceIdCallback);
5555

56-
if (completed_future.error() == 0) {
57-
lua_pushstring(L, completed_future.result()->c_str());
58-
int ret = lua_pcall(L, 2, 0, 0);
59-
if (ret != 0) {
60-
lua_pop(L, 1);
61-
}
56+
if (completed_future.error() == 0) {
57+
lua_pushstring(L, completed_future.result()->c_str());
58+
int ret = lua_pcall(L, 2, 0, 0);
59+
if (ret != 0) {
60+
lua_pop(L, 1);
6261
}
63-
else {
64-
dmLogError("%d: %s", completed_future.error(), completed_future.error_message());
65-
lua_pushnil(L);
66-
lua_pushstring(L, completed_future.error_message());
67-
int ret = lua_pcall(L, 3, 0, 0);
68-
if (ret != 0) {
69-
lua_pop(L, 2);
70-
}
62+
}
63+
else {
64+
dmLogError("%d: %s", completed_future.error(), completed_future.error_message());
65+
lua_pushnil(L);
66+
lua_pushstring(L, completed_future.error_message());
67+
int ret = lua_pcall(L, 3, 0, 0);
68+
if (ret != 0) {
69+
lua_pop(L, 2);
7170
}
72-
dmScript::TeardownCallback(g_FirebaseAnalytics_InstanceIdCallback);
7371
}
72+
dmScript::TeardownCallback(g_FirebaseAnalytics_InstanceIdCallback);
73+
}
7474

75-
dmScript::DestroyCallback(g_FirebaseAnalytics_InstanceIdCallback);
76-
g_FirebaseAnalytics_InstanceIdCallback = 0;
77-
78-
});
75+
dmScript::DestroyCallback(g_FirebaseAnalytics_InstanceIdCallback);
76+
g_FirebaseAnalytics_InstanceIdCallback = 0;
77+
});
7978
return 0;
8079
}
8180

0 commit comments

Comments
 (0)