Beispiel #1
0
/* get function: mpp */
static int tolua_get_tarray_M_mpp(lua_State* tolua_S)
{
 int tolua_index;
#ifndef TOLUA_RELEASE
 {
 tolua_Error tolua_err;
 if (!tolua_isnumber(tolua_S,2,0,&tolua_err))
 tolua_error(tolua_S,"#vinvalid type in array indexing.",&tolua_err);
 }
#endif
 tolua_index = (int)tolua_tonumber(tolua_S,2,0)-1;
#ifndef TOLUA_RELEASE
 if (tolua_index<0 || tolua_index>=10)
 tolua_error(tolua_S,"array indexing out of range.",NULL);
#endif
 tolua_pushusertype(tolua_S,(void*)mpp[tolua_index],"Point");
 return 1;
}
Beispiel #2
0
static int tolua_ship_create(lua_State * L)
{
    region *r = (region *)tolua_tousertype(L, 1, 0);
    const char *sname = tolua_tostring(L, 2, 0);
    if (sname) {
        const ship_type *stype = st_find(sname);
        if (stype) {
            ship *sh = new_ship(stype, r, default_locale);
            sh->size = stype->construction ? stype->construction->maxsize : 1;
            tolua_pushusertype(L, (void *)sh, TOLUA_CAST "ship");
            return 1;
        }
        else {
            log_error("Unknown ship type '%s'\n", sname);
        }
    }
    return 0;
}
static int tolua_building_create(lua_State * L)
{
    region *r = (region *)tolua_tousertype(L, 1, 0);
    const char *bname = tolua_tostring(L, 2, 0);
    if (!r) {
        log_error("building.create expects a region as argument 1");
    } else if (!bname) {
        log_error("building.create expects a name as argument 2");
    } else {
        const building_type *btype = bt_find(bname);
        if (btype) {
            building *b = new_building(btype, r, default_locale);
            tolua_pushusertype(L, (void *)b, TOLUA_CAST "building");
            return 1;
        }
    }
    return 0;
}
Beispiel #4
0
/** Assign usertype to global variable.
 * @param name name of global variable to assign the value to
 * @param data usertype data
 * @param type_name type name of the data
 * @param name_space C++ namespace of type, prepended to type_name
 */
void
LuaContext::set_usertype(const char *name, void *data,
			  const char *type_name, const char *name_space)
{
  MutexLocker lock(__lua_mutex);

  std::string type_n = type_name;
  if ( name_space ) {
    type_n = std::string(name_space) + "::" + type_name;
  }

  assert_unique_name(name, "usertype");

  __usertypes[name] = std::make_pair(data, type_n);

  tolua_pushusertype(__L, data, type_n.c_str());
  lua_setglobal(__L, name);
}
Beispiel #5
0
JiveTile *jive_style_tile(lua_State *L, int index, const char *key, JiveTile *def) {
	JiveTile *value;

	JIVEL_STACK_CHECK_BEGIN(L);

	lua_pushcfunction(L, jiveL_style_value);
	lua_pushvalue(L, index);
	lua_pushstring(L, key);
	tolua_pushusertype(L, def, "Tile");
	lua_call(L, 3, 1);

	value = tolua_tousertype(L, -1, 0);
	lua_pop(L, 1);

	JIVEL_STACK_CHECK_END(L);

	return value;
}
int player_trade_get_session_id(lua_State* L)
{
#ifdef _DEBUG
	tolua_Error err;
	if(	!tolua_isusertype(L,1,"CPlayerTrade",0,&err) ||
		!tolua_isusertype(L,2,"CGameClient",0,&err)||
		!tolua_isnumber(L,3,0,&err)||
		!tolua_isnoobj(L,4,&err) )
	{
		tolua_error(L,"#ferror in function 'player_trade_get_session_id'.",&err);
		return 0;
	}
#endif
	CPlayerTrade* selfTrade = (CPlayerTrade*)tolua_tousertype(L,1,0);
	const CGUID& guid = selfTrade->GetSessionID();
	tolua_pushusertype(L,(void*)&guid,"CGUID");
	return 1;
}
Beispiel #7
0
void LuaScripting::ExecuteHook(Entity *_entity, const char *_hook, int _value)
{
    tolua_pushusertype(m_luaState, (void*)_entity, "Entity");
    lua_setglobal(m_luaState, "entity");
    lua_pop(m_luaState, 1);
    if (RunScript(_entity->GetName())) {
        lua_getglobal(m_luaState, _hook);
        if (lua_isfunction(m_luaState, -1)) {
            lua_pushnumber(m_luaState, _value);
            if (!strcmp(_hook, "onMouseOver") || !strcmp(_hook, "onMouseLeave")) {
                lua_call(m_luaState, 0, 0);
            } else {
                lua_call(m_luaState, 1, 0);
            }
        }
    }
    ResetEntityFileGlobals();
}
int lua_glue_auto_GlDisplayService_constructor(lua_State* L)
{
    bool ok = true;

    glfw::GlfwContext* context;

    ok &= luaval_to_object<glfw::GlfwContext>(L, 1, "glfw.GlfwContext", &context, "display.GlDisplayService:GlDisplayService");

    if (!ok)
    {
        tolua_error(L, "invalid arguments in function 'lua_glue_auto_GlDisplayService_constructor'", nullptr);
        return 0;
    }
    display::GlDisplayService* cobj = new display::GlDisplayService(*context);
    tolua_pushusertype(L, (void*)cobj, "display.GlDisplayService");
    tolua_register_gc(L, lua_gettop(L));
    return 1;
}
Beispiel #9
0
      inline virtual void
      __export(T const& container, const char* data_type, const char* out_table)
      {
        lua_State *lua = ScriptEngine::getSingleton().getLuaState();

        lua_newtable(lua); // declare the empty table out_table

        typename T::const_iterator cursor;
        int count = 0;
        for (cursor = container.begin(); cursor != container.end(); ++cursor)
        {
          lua_pushinteger(lua, (++count));
          tolua_pushusertype(lua, (void*)(*cursor), data_type);
          lua_settable(lua, -3);
        }

        lua_setglobal(lua, out_table);
      }
Beispiel #10
0
/* Type casting
 */
static int tolua_bnd_cast (lua_State* L)
{
  void* v = tolua_tousertype(L,1,NULL);
  const char* s = tolua_tostring(L,2,NULL);
  if (!v)
    lua_pushnil(L);
  else if (v && s) {
    tolua_getmetatable(L,s);             /* stack: ubox[u] super super[mt] flag mt */
    if (lua_isnil(L,-1)) {
      tolua_error(L,"Unknown 'type' for 'tolua.cast' function",NULL);
    }
    tolua_pushusertype(L,v,s);
  }
  else {
    tolua_error(L,"Invalid arguments for 'tolua.cast' function",NULL);
  }
  return 1;
}
//////////////////////////////////////////////////////////////////////////
//MessageHandler
//////////////////////////////////////////////////////////////////////////
static int tolua_MessageHandler_sShareInstance(lua_State *tolua_S)
{
#ifndef TOLUA_ISEER_RELEASE
	tolua_Error tolua_err;
	if(
		!tolua_isusertable(tolua_S,1,"MessageHandler",0,&tolua_err) ||
		!tolua_isnoobj(tolua_S,2,&tolua_err)
		)
	{
		tolua_error(tolua_S,"#ferror in function 'MessageHandler::sShareInstance'",&tolua_err);
		return 0;
	}
#endif
	MessageHandler *tolua_ret = MessageHandler::sShareInstance();
	tolua_pushusertype(tolua_S,(void*)tolua_ret,"MessageHandler");

	return 1;
}
//------------------------------------------------------------------------------
void QContactListener::PreSolve(b2Contact* pContact, const b2Manifold* oldManifold)
{
    QNode* pNodeA = (QNode*)pContact->GetFixtureA()->GetBody()->GetUserData();
    QNode* pNodeB = (QNode*)pContact->GetFixtureB()->GetBody()->GetUserData();

    int ls = lua_gettop(g_L);

    LUA_EVENT_PREPARE("collisionPreSolve"); // On stack: event
    LUA_EVENT_SET_STRING("phase", "began");
    LUA_EVENT_SET_TOLUA_PTR("nodeA", (void*)pNodeA, pNodeA->_getToLuaClassName());
    LUA_EVENT_SET_TOLUA_PTR("nodeB", (void*)pNodeB, pNodeB->_getToLuaClassName());
    LUA_EVENT_SET_TOLUA_PTR("target", (void*)pNodeA, pNodeA->_getToLuaClassName());
    ls = lua_gettop(g_L);

    QContact con(pContact);
    ls = lua_gettop(g_L);
    LUA_EVENT_SET_TOLUA_PTR("contact", (void*)&con, "quick::QPhysics::Contact");

    ls = lua_gettop(g_L);

    // World point of collision... is this correct?
    b2WorldManifold wm;
    pContact->GetWorldManifold(&wm);
    float dx = g_Sim->scaleP2D(wm.points[0].x);
    float dy = g_Sim->scaleP2D(wm.points[0].y);
    LUA_EVENT_SET_NUMBER("x", dx);
    LUA_EVENT_SET_NUMBER("y", dy);

    ls = lua_gettop(g_L);

    lua_getfield(g_L, LUA_GLOBALSINDEX, "handleNodeEvent");
	lua_pushvalue(g_L, -2); // On stack: handleNodeEvent(event)
    tolua_pushusertype(g_L, (void*)pNodeA, pNodeA->_getToLuaClassName()); // On stack: handleNodeEvent(event, node)

    ls = lua_gettop(g_L);
    int s = lua_pcall(g_L, 2, 1, 0);
    ls = lua_gettop(g_L);
    LUA_REPORT_ERRORS(g_L, s);
    
    lua_pop(g_L, 2);
    ls = lua_gettop(g_L);

    bool b = true;
}
Beispiel #13
0
  void instance::pass_evt_to_lua(const Event& evt)
  {
    // pass to lua

    lua_getfield(lua_, LUA_GLOBALSINDEX, "processEvt");
    if(!lua_isfunction(lua_, 1))
    {
      log_->errorStream() << "could not find Lua event processor!"
        << " event: " << Event::_uid_to_string(evt.UID) << "#" << (int)evt.UID;
      lua_pop(lua_,1);
      return;
    }

    tolua_pushusertype(lua_,(void*)&evt,"Pixy::Event");
    lua_call(lua_, 1, 1);
    int result = lua_toboolean(lua_, lua_gettop(lua_));
    lua_remove(lua_, lua_gettop(lua_));

  }
Beispiel #14
0
int jiveL_style_font(lua_State *L) {
	
	/* stack is:
	 * 1: widget
	 * 2: key
	 * 3: default
	 */

	jiveL_style_value(L);

	if (lua_isnil(L, -1)) {
		lua_pop(L, 1);

		/* default font */
		tolua_pushusertype(L, jive_font_load("fonts/FreeSans.ttf", 15), "Font");
	}

	return 1;
}
Beispiel #15
0
static int lua_ftk_bitmap_create(lua_State* L)
{
	tolua_Error err = {0};
	FtkBitmap* retv;
	int w;
	int h;
	FtkColor clear_color;
	int param_ok = tolua_isnumber(L, 1, 0, &err) && tolua_isnumber(L, 2, 0, &err) && tolua_isusertype(L, 3, "FtkColor", 0, &err);

	return_val_if_fail(param_ok, 0);

	w = tolua_tonumber(L, 1, 0);
	h = tolua_tonumber(L, 2, 0);
	clear_color = *(FtkColor*)tolua_tousertype(L, 3, 0);
	retv = ftk_bitmap_create(w, h, clear_color);
	tolua_pushusertype(L, (FtkBitmap*)retv, "FtkBitmap");

	return 1;
}
/** Binds cNetwork::CreateUDPEndpoint */
static int tolua_cNetwork_CreateUDPEndpoint(lua_State * L)
{
	// Function signature:
	// cNetwork:CreateUDPEndpoint(Port, Callbacks) -> cUDPEndpoint

	cLuaState S(L);
	if (
		!S.CheckParamStaticSelf("cNetwork") ||
		!S.CheckParamNumber(2) ||
		!S.CheckParamTable(3) ||
		!S.CheckParamEnd(4)
	)
	{
		return 0;
	}

	// Read the params:
	int port;
	cLuaState::cTableRefPtr callbacks;
	if (!S.GetStackValues(2, port, callbacks))
	{
		return S.ApiParamError("Cannot read parameters");
	}

	// Check validity:
	if ((port < 0) || (port > 65535))
	{
		return S.ApiParamError("Port number out of range (%d, range 0 - 65535)", port);
	}
	ASSERT(callbacks != nullptr);  // Invalid callbacks would have resulted in GetStackValues() returning false

	// Create the LuaUDPEndpoint glue class:
	auto endpoint = std::make_shared<cLuaUDPEndpoint>(std::move(callbacks));
	endpoint->Open(static_cast<UInt16>(port), endpoint);

	// Register the endpoint to be garbage-collected by Lua:
	tolua_pushusertype(L, endpoint.get(), "cUDPEndpoint");
	tolua_register_gc(L, lua_gettop(L));

	// Return the endpoint object:
	S.Push(endpoint.get());
	return 1;
}
int lua_register_sls_world_getSloth(lua_State* tolua_S)
{
  int argc = 0;
  sls::World* cobj = nullptr;

  cobj = (sls::World*)tolua_tousertype(tolua_S,1,0);
  if (!cobj) return 0;

  argc = lua_gettop(tolua_S) - 1;
  if (argc == 1) {
    tolua_Error tolua_err;
    if (tolua_isnumber(tolua_S,2,0,&tolua_err)) {
      int val = tolua_tonumber(tolua_S, 2, 0);
      sls::Sloth* ret = &(cobj->getSloth(val));
      tolua_pushusertype(tolua_S,(void*)ret,"sls.Sloth");
      return 1;
    }
  }
  return 0;
}
//----------------------------------------------------------------------------------------
bool BaseLevelBuilder::excuteScript()
{
	char buffer[64];
	int levelId = m_level->getID();	
	sprintf(buffer, "Script\\Level\\%d.lua", levelId);
	
	CCLuaEngine* luaEngine = (CCLuaEngine*)CCScriptEngineManager::sharedManager()->getScriptEngine();
	if (luaEngine)
	{
		lua_State *lua_S = luaEngine->getLuaState();
		tolua_pushusertype(lua_S,(void*)this,"BaseLevelBuilder");	
		lua_setglobal(lua_S,"baseLevelBuilderObject");
	}

	//execute the script
	std::string path = CCFileUtils::sharedFileUtils()->fullPathFromRelativePath(buffer);
	CCScriptEngineManager::sharedManager()->getScriptEngine()->executeScriptFile(path.c_str());
	
	return true;
}
Beispiel #19
0
/* function: lua_get_quest */
static int toluaI_quest_quest00(lua_State* tolua_S)
{
 if (
 !tolua_istype(tolua_S,1,LUA_TNUMBER,0) ||
 !tolua_isnoobj(tolua_S,2)
 )
 goto tolua_lerror;
 else
 {
  s32b q_idx = ((s32b)  tolua_getnumber(tolua_S,1,0));
 {
  quest_type* toluaI_ret = (quest_type*)  lua_get_quest(q_idx);
 tolua_pushusertype(tolua_S,(void*)toluaI_ret,tolua_tag(tolua_S,"quest_type"));
 }
 }
 return 1;
tolua_lerror:
 tolua_error(tolua_S,"#ferror in function 'quest'.");
 return 0;
}
static int tolua_DecalScript_ADDDECALSPRITEMESSAGE_new00(lua_State* tolua_S)
{
    tolua_Error tolua_err;
    if (
        !tolua_isusertable(tolua_S,1,"ADDDECALSPRITEMESSAGE",0,&tolua_err) ||
        !tolua_isnoobj(tolua_S,2,&tolua_err)
    )
        goto tolua_lerror;
    else
    {
        {
            ADDDECALSPRITEMESSAGE* tolua_ret = (ADDDECALSPRITEMESSAGE*)  new ADDDECALSPRITEMESSAGE();
            tolua_pushusertype(tolua_S,(void*)tolua_ret,"ADDDECALSPRITEMESSAGE");
        }
    }
    return 1;
tolua_lerror:
    tolua_error(tolua_S,"#ferror in function 'new'.",&tolua_err);
    return 0;
}
static int tolua_AIObjectScript_COMMANDSEQUENCEPARAMS_new00(lua_State* tolua_S)
{
 tolua_Error tolua_err;
 if (
 !tolua_isusertable(tolua_S,1,"COMMANDSEQUENCEPARAMS",0,&tolua_err) ||
 !tolua_isnoobj(tolua_S,2,&tolua_err)
 )
 goto tolua_lerror;
 else
 {
 {
  COMMANDSEQUENCEPARAMS* tolua_ret = (COMMANDSEQUENCEPARAMS*)  new COMMANDSEQUENCEPARAMS();
 tolua_pushusertype(tolua_S,(void*)tolua_ret,"COMMANDSEQUENCEPARAMS");
 }
 }
 return 1;
tolua_lerror:
 tolua_error(tolua_S,"#ferror in function 'new'.",&tolua_err);
 return 0;
}
static int tolua_FadeUtility_FADEUTILITYPARAMS_new00(lua_State* tolua_S)
{
 tolua_Error tolua_err;
 if (
 !tolua_isusertable(tolua_S,1,"FADEUTILITYPARAMS",0,&tolua_err) ||
 !tolua_isnoobj(tolua_S,2,&tolua_err)
 )
 goto tolua_lerror;
 else
 {
 {
  FADEUTILITYPARAMS* tolua_ret = (FADEUTILITYPARAMS*)  new FADEUTILITYPARAMS();
 tolua_pushusertype(tolua_S,(void*)tolua_ret,"FADEUTILITYPARAMS");
 }
 }
 return 1;
tolua_lerror:
 tolua_error(tolua_S,"#ferror in function 'new'.",&tolua_err);
 return 0;
}
Beispiel #23
0
/* function: music_load_music */
static int toluaI_sound_sound___load_music00(lua_State* tolua_S)
{
 if (
 !tolua_istype(tolua_S,1,LUA_TSTRING,0) ||
 !tolua_isnoobj(tolua_S,2)
 )
 goto tolua_lerror;
 else
 {
  cptr file = ((cptr)  tolua_getstring(tolua_S,1,0));
 {
  Mix_Music* toluaI_ret = (Mix_Music*)  music_load_music(file);
 tolua_pushusertype(tolua_S,(void*)toluaI_ret,tolua_tag(tolua_S,"Mix_Music"));
 }
 }
 return 1;
tolua_lerror:
 tolua_error(tolua_S,"#ferror in function '__load_music'.");
 return 0;
}
static int tolua_MessageHandler_GetCurWildMsgPackage(lua_State *tolua_S)
{
#ifndef TOLUA_TXGUI_RELEASE
	tolua_Error tolua_err;
	if(
		!tolua_isusertype(tolua_S,1,"MessageHandler",0,&tolua_err) ||
		!tolua_isnoobj(tolua_S,2,&tolua_err)
		)
	{
		tolua_error(tolua_S,"#ferror in function 'MessageHandler::getCurWildMsgPackage'",&tolua_err);
		return 0;
	}
#endif

	MessageHandler* self = (MessageHandler*)tolua_tousertype(tolua_S,1,0);	
	WILD_MSG_PACKAGE* tolua_ret = (WILD_MSG_PACKAGE*) self->getWildMsgPackage();
	tolua_pushusertype(tolua_S,(void*)tolua_ret,"WILD_MSG_PACKAGE");

	return 1;
}
Beispiel #25
0
static int tolua_GUID_CGUID_new01(lua_State* tolua_S)
{
 tolua_Error tolua_err;
 if (
     !tolua_isusertable(tolua_S,1,"CGUID",0,&tolua_err) ||
     !tolua_isstring(tolua_S,2,0,&tolua_err) ||
     !tolua_isnoobj(tolua_S,3,&tolua_err)
 )
  goto tolua_lerror;
 else
 {
  const char* str = ((const char*)  tolua_tostring(tolua_S,2,0));
  {
   CGUID* tolua_ret = (CGUID*)  Mtolua_new((CGUID)(str));
    tolua_pushusertype(tolua_S,(void*)tolua_ret,"CGUID");
  }
 }
 return 1;
tolua_lerror:
 return tolua_GUID_CGUID_new00(tolua_S);
}
//====================================================================================================================================
//得到ID
int baseobject_getid(lua_State* L)
{
#ifdef _DEBUG
 	tolua_Error err;
 	if(!tolua_isusertype(L,1,"CBaseObject",0,&err)||
 		!tolua_isstring(L,2,0,&err)||
 		!tolua_isnoobj(L,3,&err))
 	{
 		tolua_error(L,"#ferror in function 'baseobject_getid'.",&err);
 		return 0;
 	}
#endif
	CBaseObject *self = (CBaseObject*)tolua_tousertype(L,1,0);									//10.10注释
	if( self != NULL )
	{
		const CGUID& guid = self->GetExID();
		tolua_pushusertype(L,(void*)&guid,"CGUID");
		return 1;
	}
	return 0;
}
Beispiel #27
0
bool cPlugin_NewLua::OnWeatherChanged(cWorld & a_World)
{
	cCSLock Lock(m_CriticalSection);
	const char * FnName = GetHookFnName(cPluginManager::HOOK_WEATHER_CHANGED);
	ASSERT(FnName != NULL);
	if (!PushFunction(FnName))
	{
		return false;
	}

	tolua_pushusertype(m_LuaState, &a_World, "cWorld");

	if (!CallFunction(1, 1, FnName))
	{
		return false;
	}

	bool bRetVal = (tolua_toboolean(m_LuaState, -1, 0) > 0);
	lua_pop(m_LuaState, 1);
	return bRetVal;
}
Beispiel #28
0
bool cPlugin_NewLua::OnPlayerTossingItem(cPlayer & a_Player)
{
	cCSLock Lock(m_CriticalSection);
	const char * FnName = GetHookFnName(cPluginManager::HOOK_PLAYER_TOSSING_ITEM);
	ASSERT(FnName != NULL);
	if (!PushFunction(FnName))
	{
		return false;
	}

	tolua_pushusertype(m_LuaState, &a_Player, "cPlayer");

	if (!CallFunction(1, 1, FnName))
	{
		return false;
	}

	bool bRetVal = (tolua_toboolean(m_LuaState, -1, 0) > 0);
	lua_pop(m_LuaState, 1);
	return bRetVal;
}
Beispiel #29
0
/* get function: pp of class  Array */
static int tolua_get_tarray_Array_pp(lua_State* tolua_S)
{
 int tolua_index;
  Array* self;
 lua_pushstring(tolua_S,".self");
 lua_rawget(tolua_S,1);
 self = (Array*)  lua_touserdata(tolua_S,-1);
#ifndef TOLUA_RELEASE
 {
 tolua_Error tolua_err;
 if (!tolua_isnumber(tolua_S,2,0,&tolua_err))
 tolua_error(tolua_S,"#vinvalid type in array indexing.",&tolua_err);
 }
#endif
 tolua_index = (int)tolua_tonumber(tolua_S,2,0)-1;
#ifndef TOLUA_RELEASE
 if (tolua_index<0 || tolua_index>=10)
 tolua_error(tolua_S,"array indexing out of range.",NULL);
#endif
 tolua_pushusertype(tolua_S,(void*)self->pp[tolua_index],"Point");
 return 1;
}
Beispiel #30
0
bool cPlugin_NewLua::OnHandshake(cClientHandle * a_Client, const AString & a_Username)
{
	cCSLock Lock(m_CriticalSection);
	const char * FnName = GetHookFnName(cPluginManager::HOOK_HANDSHAKE);
	ASSERT(FnName != NULL);
	if (!PushFunction(FnName))
	{
		return false;
	}

	tolua_pushusertype(m_LuaState, a_Client, "cClientHandle");
	tolua_pushstring  (m_LuaState, a_Username.c_str());

	if (!CallFunction(2, 1, FnName))
	{
		return false;
	}

	bool bRetVal = (tolua_toboolean(m_LuaState, -1, 0) > 0);
	lua_pop(m_LuaState, 1);
	return bRetVal;
}