Skip to content

Conversation

blendjam
Copy link

This currently supports android devices only. Any help from moderators is welcomed.

@britzl
Copy link
Contributor

britzl commented Mar 26, 2025

Looks good.

This currently supports android devices only

iOS documentation: https://developers.google.com/admob/ios/rewarded#validate-ssv

@blendjam
Copy link
Author

Adding support for userId is breaking as load_rewarded expects userId to be passed as argument.

@blendjam blendjam changed the title Added optional custom data support for rewarded AD Added optional userId and customData support for rewarded AD Mar 26, 2025
@britzl
Copy link
Contributor

britzl commented Mar 31, 2025

Adding support for userId is breaking as load_rewarded expects userId to be passed as argument.

You're right. It would be better to either have userId and customData as optional extra arguments or provide them in an options table:

local options = {
    user_id = "user_id",
    custom_data = "my custom data",
}
admob.show_rewarded("unit_id", options)

The below change should be enough to treat the values as optional:

static int Lua_LoadRewarded(lua_State* L)
{
    DM_LUA_STACK_CHECK(L, 0);
    if (lua_type(L, 1) != LUA_TSTRING) {
        return DM_LUA_ERROR("Expected string, got %s. Wrong type for Rewarded UnitId variable '%s'.", luaL_typename(L, 1), lua_tostring(L, 1));
    }
    const char* unitId_lua = luaL_checkstring(L, 1);

    char* userId_lua = 0;
    if (lua_gettop(L) > 1)
    {
        userId_lua =  luaL_checkstring(L, 2);
    }

    char* customData_lua = 0;
    if (lua_gettop(L) > 2)
    {
        customData_lua = luaL_checkstring(L, 3);
    }

    LoadRewarded(unitId_lua, userId_lua, customData_lua);
    return 0;
}

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 this pull request may close these issues.

2 participants