本文整理汇总了C++中SpaceStation::AddBBAdvert方法的典型用法代码示例。如果您正苦于以下问题:C++ SpaceStation::AddBBAdvert方法的具体用法?C++ SpaceStation::AddBBAdvert怎么用?C++ SpaceStation::AddBBAdvert使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SpaceStation
的用法示例。
在下文中一共展示了SpaceStation::AddBBAdvert方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: l_spacestation_add_advert
/*
* Method: AddAdvert
*
* Add an advertisement to the station's bulletin board
*
* > ref = station:AddAdvert(description, chatfunc, deletefunc)
*
* Parameters:
*
* description - text to display in the bulletin board
*
* chatfunc - function to call when the ad is activated. The function is
* passed three parameters: a <ChatForm> object for the ad
* conversation display, the ad reference returned by <AddAdvert>
* when the ad was created, and an integer value corresponding to
* the action that caused the activation. When the ad is initially
* selected from the bulletin board, this value is 0. Additional
* actions (and thus values) are defined by the script via
* <ChatForm.AddAction>.
*
* deletefunc - optional. function to call when the ad is removed from the
* bulletin board. This happens when <RemoveAdvert> is called,
* when the ad is cleaned up after
* <ChatForm.RemoveAdvertOnClose> is called, and when the
* <SpaceStation> itself is destroyed (eg the player leaves the
* system).
*
* Return:
*
* ref - an integer value for referring to the ad in the future. This value
* will be passed to the ad's chat function and should be passed to
* <RemoveAdvert> to remove the ad from the bulletin board.
*
* Example:
*
* > local ref = station:AddAdvert(
* > "FAST SHIP to deliver a package to the Epsilon Eridani system.",
* > function (ref, opt) ... end,
* > function (ref) ... end
* > )
*
* Availability:
*
* alpha 10
*
* Status:
*
* stable
*/
static int l_spacestation_add_advert(lua_State *l)
{
LUA_DEBUG_START(l);
SpaceStation *s = LuaSpaceStation::GetFromLua(1);
std::string description = luaL_checkstring(l, 2);
if (!lua_isfunction(l, 3))
luaL_typerror(l, 3, lua_typename(l, LUA_TFUNCTION));
bool have_delete = false;
if (lua_gettop(l) >= 4) {
if (!lua_isnil(l, 4) && !lua_isfunction(l, 4))
luaL_typerror(l, 4, lua_typename(l, LUA_TFUNCTION));
have_delete = true;
}
int ref = s->AddBBAdvert(description, _create_chat_form);
lua_getfield(l, LUA_REGISTRYINDEX, "PiAdverts");
if (lua_isnil(l, -1)) {
lua_pop(l, 1);
lua_newtable(l);
lua_pushvalue(l, -1);
lua_setfield(l, LUA_REGISTRYINDEX, "PiAdverts");
}
lua_pushinteger(l, ref);
lua_newtable(l);
lua_pushstring(l, "onChat");
lua_pushvalue(l, 3);
lua_settable(l, -3);
if (have_delete) {
lua_pushstring(l, "onDelete");
lua_pushvalue(l, 4);
lua_settable(l, -3);
}
lua_settable(l, -3);
lua_pop(l, 1);
LUA_DEBUG_END(l,0);
_register_for_station_delete(s);
lua_pushinteger(l, ref);
return 1;
}