Skip to content

Support initialisation with AppOptions #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
dri-richard opened this issue Jan 16, 2023 · 2 comments · Fixed by #5
Closed

Support initialisation with AppOptions #4

dri-richard opened this issue Jan 16, 2023 · 2 comments · Fixed by #5

Comments

@dri-richard
Copy link
Contributor

firebase::App::Create() has an overload that takes an object of type AppOptions to permit Firebase to be initialized with non-default values.
We'd like to use it to permit selection of Firebase projects for different environments (dev, staging etc) from a boot screen.

I'm happy to take this on myself, but could do with some guidance on the Lua API, as AppOptions has 6 string members.

@britzl
Copy link
Contributor

britzl commented Jan 17, 2023

I'm happy to take this on myself, but could do with some guidance on the Lua API, as AppOptions has 6 string members.

We should change firebase.init() to take an optional Lua table with options, ie:

local options = {
  api_key = "a",
  app_id = "b",
  project_id = "c",
}
firebase.init(options)

The extension code will look something like this:

	AppOptions options;
	if (!lua_isnil(L, 1)) {
		luaL_checktype(L, 1, LUA_TTABLE);
		lua_pushvalue(L, 1);
		lua_pushnil(L);
		while (lua_next(L, -2)) {
			const char* attr = lua_tostring(L, -2);
			if (strcmp(attr, "api_key") == 0)
			{
				options.set_api_key(luaL_checkstring(L, -1));
			}
			else if (strcmp(attr, "app_id") == 0)
			{
				options.set_app_id(luaL_checkstring(L, -1));
			}
			else if (strcmp(attr, "project_id") == 0)
			{
				options.set_project_id(luaL_checkstring(L, -1));
			}
			lua_pop(L, 1);
		}
		lua_pop(L, 1);
	}

@dri-richard dri-richard mentioned this issue Jan 30, 2023
@britzl
Copy link
Contributor

britzl commented Jan 31, 2023

Closed via #5

@britzl britzl closed this as completed Jan 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants