static int win_ShellExecute(lua_State *L) { HWND hwnd = lua_isuserdata(L, 1) ? lua_touserdata(L, 1) : NULL; const wchar_t* lpOperation = opt_utf8_string(L, 2, NULL); const wchar_t* lpFile = check_utf8_string(L, 3, NULL); const wchar_t* lpParameters = opt_utf8_string(L, 4, NULL); const wchar_t* lpDirectory = opt_utf8_string(L, 5, NULL); INT nShowCmd = (INT)luaL_optinteger(L, 6, SW_SHOWNORMAL); HINSTANCE hinst = ShellExecuteW( hwnd, // handle to parent window lpOperation, // pointer to string that specifies operation to perform lpFile, // pointer to filename or folder name string lpParameters, // pointer to string that specifies executable-file parameters lpDirectory, // pointer to string that specifies default directory nShowCmd // whether file is shown when opened ); lua_pushinteger(L, (INT_PTR)hinst); return 1; }
static void add_tmpname(lua_State *L, const char *tmp) { struct tmpname_s **pp = 0; lua_pushlightuserdata(L, (void*)tmpnames_key); lua_rawget(L, LUA_REGISTRYINDEX); if (lua_isuserdata(L, -1)) { pp = (struct tmpname_s **)lua_touserdata(L, -1); lua_pop(L, 1); } else { lua_pop(L, 1); /* create sentinel */ lua_pushlightuserdata(L, (void*)tmpnames_key); pp = (struct tmpname_s **)lua_newuserdata(L, sizeof(void*)); pp[0] = 0; lua_createtable(L, 0, 1); lua_pushcfunction(L, gc_tmpname); lua_setfield(L,-2,"__gc"); lua_setmetatable(L, -2); lua_rawset(L, LUA_REGISTRYINDEX); } while (pp && *pp) { struct tmpname_s *p = *pp; if (!strcmp(p->tmp, tmp)) return; pp = &(p->next); } if (pp) { int len = strlen(tmp); struct tmpname_s *t = (struct tmpname_s*)malloc(len + sizeof(struct tmpname_s)); if (t) { t->next = 0; memcpy(t->tmp, tmp, len); t->tmp[len] = 0; *pp = t; } } }
/*---------------------------------------------------------------------------*/ int lua_tinker::meta_set(lua_State *L) { lua_getmetatable(L,1); lua_pushvalue(L,2); lua_rawget(L,-2); if(lua_isuserdata(L,-1)) { user2type<var_base*>::invoke(L,-1)->set(L); } else if(lua_isnil(L, -1)) { lua_pushvalue(L,2); lua_pushvalue(L,3); lua_rawset(L, -4); } lua_settop(L, 3); return 0; }
bool CLuaFn::PopLuaData(lua_State* pState, _ParamData* pParam, int nIndex) { if(pParam == NULL) { return false; } if(pParam->CompareType("string")) { if (lua_isstring(m_pState, nIndex) == 1) { const char* pData = (const char*)lua_tostring(m_pState, nIndex); pParam->SetData((void* )pData, (int)strlen(pData)); } return true; } else if(pParam->CompareType("int")) { if (lua_isnumber(m_pState, nIndex) == 1) { int nData = (int)lua_tonumber(m_pState, nIndex); pParam->SetData(&nData, sizeof(int)); } return true; } else if(pParam->CompareType("void")) { if (lua_isuserdata(m_pState, nIndex) == 1) { void* pData = (void* )lua_touserdata(m_pState, nIndex); pParam->SetData(&pData, sizeof(void*)); } return true; } else { pParam->SetData(tolua_tousertype(m_pState, nIndex, NULL), -1); return true; } }
/*** Run the event processing loop and dispatch callbacks. @function aura.eventloop_dispatch @param loop [loop] eventloop instance @param flags [number, optional] bitmask of the following flags aura.EVTLOOP_ONCE and aura.EVTLOOP_NONBLOCK */ static int l_eventloop_dispatch(lua_State *L) { struct laura_eventloop *lloop; int flags = 0; TRACE(); aura_check_args(L, 1); if (!lua_isuserdata(L, 1)) aura_typeerror(L, 1, "ludata"); lloop = lua_touserdata(L, 1); if (lua_gettop(L) == 2) flags = lua_tonumber(L, 2); aura_eventloop_dispatch(lloop->loop, flags); return 0; }
// 1 integer flags // 2 string collection // 3 documents // return string package static int op_insert(lua_State *L) { size_t sz = 0; const char * name = luaL_checklstring(L,2,&sz); int dsz = document_length(L); luaL_Buffer b; luaL_buffinit(L, &b); struct buffer buf; buffer_create(&buf); // make package header, don't raise L error int len = reserve_length(&buf); write_int32(&buf, 0); write_int32(&buf, 0); write_int32(&buf, OP_INSERT); write_int32(&buf, lua_tointeger(L,1)); write_string(&buf, name, sz); int total = buf.size + dsz; write_length(&buf, total, len); luaL_addlstring(&b, (const char *)buf.ptr, buf.size); buffer_destroy(&buf); if (lua_isuserdata(L,3)) { document doc = lua_touserdata(L,3); luaL_addlstring(&b, (const char *)doc, get_length(doc)); } else { int s = lua_rawlen(L, 3); int i; for (i=1;i<=s;i++) { lua_rawgeti(L,3,i); document doc = lua_touserdata(L,3); lua_pop(L,1); // must call lua_pop before luaL_addlstring, because addlstring may change stack top luaL_addlstring(&b, (const char *)doc, get_length(doc)); } } luaL_pushresult(&b); return 1; }
std::string Exchanger<std::string>::get(lua_State *luaState, int index) { if (lua_isuserdata(luaState, index) == 0) { std::size_t length; const char * const string = lua_tolstring(luaState, index, &length); if (string != nullptr) { // the returned std:string can contain null characters. The length of the string is length return std::string(string, length); } else { throw ArgumentException::createTypeErrorException(luaState, index, lua_typename(luaState, LUA_TSTRING)); } } else { const std::string *userData = type_manager::getConvertibleType<std::string>(luaState, index); if (userData != nullptr) { return *userData; } else { throw ArgumentException::createTypeErrorException(luaState, index, lua_typename(luaState, LUA_TSTRING)); } } }
static void SetSoundConfigRace(lua_State *l, int j, SoundConfig soundConfigs[]) { if (!lua_istable(l, j + 1) || lua_rawlen(l, j + 1) != 2) { LuaError(l, "incorrect argument"); } const char *raceName = LuaToString(l, j + 1, 1); const int raceIndex = PlayerRaces.GetRaceIndexByName(raceName); if (raceIndex == -1) { LuaError(l, "Unknown race: %s" _C_ raceName); } lua_rawgeti(l, j + 1, 2); LuaUserData *data = NULL; if (!lua_isuserdata(l, -1) || (data = (LuaUserData *)lua_touserdata(l, -1))->Type != LuaSoundType) { LuaError(l, "Sound id expected"); } lua_pop(l, 1); soundConfigs[raceIndex].Sound = (CSound *)data->Data; }
int KTrade::has_i_l(lua_State* L) { if(!lua_isuserdata(L, 1) || lua_islightuserdata(L, 1)) { luaL_argerror(L, 1, "KTrade object expected."); return 0; } int n = lua_gettop(L); KTrade* obj = LMREG::read<KTrade*>(L, 1); ItemMap::iterator it = obj->m_ilist.end(); for(int i=2; i<=n; i++) { int typeID = lua_tointeger(L, i); if(obj->m_ilist.find(typeID) != it) return true; } return false; }
// // LUA_AddPropertyScene scene (object), property (string), value (string) // static int LUA_AddPropertyScene(lua_State *lua) { if (lua_gettop(lua) < 3) { CzScriptEngineLua::DisplayError(lua, "scene.add() not enough parameters, expected scene (object), property (string), value (string, number, boolean or vec)"); lua_pushboolean(lua, false); return 1; } // Get the target object IzXomlResource* object = NULL; if (lua_isuserdata(lua, 1)) object = (IzXomlResource*)lua_touserdata(lua, 1); if (object == NULL || object->getClassTypeHash() != CzHashes::Scene_Hash) { CzScriptEngineLua::DisplayError(lua, "scene.add() Invalid target object for Param0"); lua_pushboolean(lua, false); return 1; } CzString prop_name, value; if (lua_isstring(lua, 2)) prop_name = lua_tostring(lua, 2); else { CzScriptEngineLua::DisplayError(lua, "scene.add() property must be a property name (Param1) - object - ", object->getName().c_str()); lua_pushboolean(lua, false); return 1; } CzXomlProperty prop; if (!LUA_ValueToProperty(lua, 3, prop)) { CzScriptEngineLua::DisplayError(lua, "scene.add() value must be a string, number, boolean or vec - object - ", object->getName().c_str()); CzDebug::Log(CZ_DEBUG_CHANNEL_INFO, "- property - ", prop_name.c_str()); lua_pushboolean(lua, false); return 1; } lua_pushboolean(lua, ((CzScene*)object)->setProperty(prop_name.getHash(), prop, true)); return 1; }
void Lua_V2::SetActorCollisionMode() { lua_Object actorObj = lua_getparam(1); lua_Object modeObj = lua_getparam(2); if (!lua_isuserdata(actorObj) || lua_tag(actorObj) != MKTAG('A','C','T','R')) return; Actor *actor = getactor(actorObj); assert(actor); int mode = (int)lua_getnumber(modeObj); // From _actors.lua // COLLISION_OFF = 0 // COLLISION_BOX = 1 // COLLISION_SPHERE = 2 // FIXME: set collision mode //actor->func(mode); warning("Lua_V2::SetActorCollisionMode: implement opcode. Mode %d", mode); }
int lua_sendfile ( lua_State *L ) { if ( !lua_isuserdata ( L, 1 ) ) { luaL_error ( L, "miss epd!" ); return 0; } epdata_t *epd = lua_touserdata ( L, 1 ); if ( !lua_isstring ( L, 2 ) ) { lua_pushnil ( L ); lua_pushstring ( L, "Need a file path!" ); return 2; } network_sendfile ( epd, lua_tostring ( L, 2 ) ); return 0; }
/* Take ownership */ int tolua_bnd_takeownership (lua_State* L) { lua_CFunction func = 0; if (lua_isuserdata(L,1)) { if (lua_getmetatable(L,1)) /* if metatable? */ { void* u; lua_pushstring(L,".collector"); lua_rawget(L,-2); func = lua_iscfunction(L,-1) ? lua_tocfunction(L,-1) : NULL; lua_pop(L,2); u = *((void**)lua_touserdata(L,1)); tolua_clone(L,u,func); } } lua_pushboolean(L,func!=0); return 1; }
/* {{{ proto opendata openssl_open(string data, string ekey, mixed privkey, [, cipher enc|string md_alg=RC4]) Opens data */ LUA_API LUA_FUNCTION(openssl_open) { size_t data_len, ekey_len; const char * data = luaL_checklstring(L, 1, &data_len); const char * ekey = luaL_checklstring(L, 2, &ekey_len); EVP_PKEY *pkey = CHECK_OBJECT(3,EVP_PKEY, "openssl.evp_pkey"); int top = lua_gettop(L); int len1, len2 = 0; unsigned char *buf; EVP_CIPHER_CTX ctx; const EVP_CIPHER *cipher = NULL; if(top>3) { if(lua_isstring(L,4)) cipher = EVP_get_cipherbyname(lua_tostring(L,4)); else if(lua_isuserdata(L,4)) cipher = CHECK_OBJECT(4,EVP_CIPHER,"openssl.evp_cipher"); else luaL_error(L, "#4 argument must be nil, string, or openssl.evp_cipher object"); } if(!cipher) cipher = EVP_rc4(); len1 = data_len + 1; buf = malloc(len1); if (EVP_OpenInit(&ctx, cipher, (unsigned char *)ekey, ekey_len, NULL, pkey) && EVP_OpenUpdate(&ctx, buf, &len1, (unsigned char *)data, data_len)) { len2 = data_len - len1; if (!EVP_OpenFinal(&ctx, buf + len1, &len2) || (len1 + len2 == 0)) { free(buf); } } else { free(buf); } buf[len1 + len2] = '\0'; lua_pushlstring(L, (const char*)buf, len1 + len2); free(buf); return 1; }
int operatorCallback(lua_State* L) { // Check args int argc = lua_gettop(L); if (argc != 2) return luaL_error(L, "Invalid args count (got %d, expected at least the object instance and one other argument)", argc); if (!lua_isuserdata(L, 1)) return luaL_error(L, "First arg must be a userdata (got %s)", lua_typename(L, lua_type(L, 1))); // Get args camp::UserObject* userdata = static_cast<camp::UserObject*>(lua_touserdata(L, 1)); camp::Value arg = camp::lua::valueFromLua(L, 2); try { // Retrieve the function to be called const camp::Function& function = userdata->getClass().getOperator(Op, arg.typeInfo()); // Clear the stack lua_settop(L, 0); // Call the function. camp::Value result = function.call(*userdata, camp::Args(arg)); // Push the result if needed if (result.type() == camp::noType) { return 0; } else { camp::lua::valueToLua(L, result); return 1; } } catch (const camp::Error& err) { return luaL_error(L, err.what()); } return 0; }
static int do_cmd(lua_State *L, buffer *b, int narg, enum cmd c) { int pos; switch (c) { case cmd_append: pos = b->len; break; case cmd_insert: case cmd_set: pos = real_offset(luaL_checkint(L, narg++), b->len); break; default: pos = 0; break; } if (lb_isbufferorstring(L, narg)) { size_t len; const char *str = lb_tolstring(L, narg, &len); size_t i = real_range(L, narg+1, &len); if (prepare_cmd(L, b, c, pos, len)) memcpy(&b->str[pos], &str[i], len); } else if (lua_type(L, narg) == LUA_TNUMBER) { size_t fill_len = lua_tointeger(L, narg); size_t len = 0; const char *str = NULL; if (!lua_isnoneornil(L, narg+1)) { if ((str = lb_tolstring(L, narg+1, &len)) != NULL) str += real_range(L, narg+2, &len); else if ((str = udtolstring(L, narg+1, &len)) == NULL) luaL_typerror(L, narg+1, "string, buffer or userdata"); } if (prepare_cmd(L, b, c, pos, fill_len)) fill_str(b, pos, fill_len, str, len); } else if (lua_isuserdata(L, narg)) { size_t len = 0; const char *str = udtolstring(L, narg, &len); if (prepare_cmd(L, b, c, pos, len)) memcpy(&b->str[pos], str, len); } else if (!lua_isnoneornil(L, narg)) luaL_typerror(L, narg, "string, buffer, number or userdata"); lua_settop(L, narg-1); return 1; }
/*** * @method cryptobox_hash:update(data) * Updates hash with the specified data (hash should not be finalized using `hex` or `bin` methods) * @param {string} data data to hash */ static gint lua_cryptobox_hash_update (lua_State *L) { rspamd_cryptobox_hash_state_t *h = lua_check_cryptobox_hash (L, 1); const gchar *data; struct rspamd_lua_text *t; gsize len; if (lua_isuserdata (L, 2)) { t = lua_check_text (L, 2); if (!t) { return luaL_error (L, "invalid arguments"); } data = t->start; len = t->len; } else { data = luaL_checklstring (L, 2, &len); } if (lua_isnumber (L, 3)) { gsize nlen = lua_tonumber (L, 3); if (nlen > len) { return luaL_error (L, "invalid length: %d while %d is available", (int)nlen, (int)len); } len = nlen; } if (h && data) { rspamd_cryptobox_hash_update (h, data, len); } else { return luaL_error (L, "invalid arguments"); } return 0; }
static int lua_request_connect(lua_State *L) { if (! ( lua_isuserdata(L, -3) && lua_isstring (L, -2) && lua_type (L, -1) == LUA_TFUNCTION )) { printf("Invalid arguments"); return 0; } /* Get the values from the stack */ const request_t *r = (request_t*) lua_touserdata(L, -3); const char *signal = lua_tostring (L, -2); /* Remove the function from the stack and add it to the registry */ const int callback_ref = luaL_ref(L, LUA_REGISTRYINDEX); /* Remove the other args, they are no longer needed */ lua_pop(L, 2); /* Create the binder */ lua_request_t *lr = (lua_request_t *) r->user_data; connection_t *conn = (connection_t *) malloc(sizeof(connection_t)); conn->next = NULL; conn->reference = callback_ref; conn->signal_name = (char*) malloc((strlen(signal) +1) * sizeof(char)); /* Copy the signal name to avoid user after free */ strcpy(conn->signal_name, signal); /* Updated the connection linked list */ if (!lr->first_connection) lr->first_connection = conn; else lr->last_connection->next = (struct connection_t*) conn; lr->last_connection = conn; return 0; }
/*** * @function rspamd_cryptobox.sign_memory(kp, data) * Sign data using specified keypair * @param {keypair} kp keypair to sign * @param {string} data * @return {cryptobox_signature} signature object */ static gint lua_cryptobox_sign_memory (lua_State *L) { struct rspamd_cryptobox_keypair *kp; const gchar *data; struct rspamd_lua_text *t; gsize len = 0; rspamd_fstring_t *sig, **psig; kp = lua_check_cryptobox_keypair (L, 1); if (lua_isuserdata (L, 2)) { t = lua_check_text (L, 2); if (!t) { return luaL_error (L, "invalid arguments"); } data = t->start; len = t->len; } else { data = luaL_checklstring (L, 2, &len); } if (!kp || !data) { return luaL_error (L, "invalid arguments"); } sig = rspamd_fstring_sized_new (rspamd_cryptobox_signature_bytes ( rspamd_keypair_alg (kp))); rspamd_cryptobox_sign (sig->str, &sig->len, data, len, rspamd_keypair_component (kp, RSPAMD_KEYPAIR_COMPONENT_SK, NULL), rspamd_keypair_alg (kp)); psig = lua_newuserdata (L, sizeof (void *)); *psig = sig; rspamd_lua_setclass (L, "rspamd{cryptobox_signature}", -1); return 1; }
/* zlib.deflate( sink: function | { write: function [, close: function, flush: function] }, compression level, [Z_DEFAILT_COMPRESSION] method, [Z_DEFLATED] windowBits, [15] memLevel, [8] strategy, [Z_DEFAULT_STRATEGY] dictionary: [""] ) */ static int lzlib_deflate(lua_State *L) { int level, method, windowBits, memLevel, strategy; lz_stream *s; const char *dictionary; size_t dictionary_len; if (lua_istable(L, 1) || lua_isuserdata(L, 1)) { /* is there a :write function? */ lua_getfield(L, 1, "write"); if (!lua_isfunction(L, -1)) { luaL_argerror(L, 1, "output parameter does not provide :write function"); } lua_pop(L, 1); } else if (!lua_isfunction(L, 1)) { luaL_argerror(L, 1, "output parameter must be a function, table or userdata value"); } level = luaL_optint(L, 2, Z_DEFAULT_COMPRESSION); method = luaL_optint(L, 3, Z_DEFLATED); windowBits = luaL_optint(L, 4, 15); memLevel = luaL_optint(L, 5, 8); strategy = luaL_optint(L, 6, Z_DEFAULT_STRATEGY); dictionary = luaL_optlstring(L, 7, NULL, &dictionary_len); s = lzstream_new(L, 1); if (deflateInit2(&s->zstream, level, method, windowBits, memLevel, strategy) != Z_OK) { lua_pushliteral(L, "call to deflateInit2 failed"); lua_error(L); } if (dictionary) { if (deflateSetDictionary(&s->zstream, (const Bytef *) dictionary, dictionary_len) != Z_OK) { lua_pushliteral(L, "call to deflateSetDictionnary failed"); lua_error(L); } } s->state = LZ_DEFLATE; return 1; }
// // LUA_isTypeOf(type-name) // static int LUA_isTypeOf(lua_State *lua) { int count = lua_gettop(lua); if (lua_gettop(lua) < 1) { CzScriptEngineLua::DisplayError(lua, "sys.isTypeOf() not enough parameters, expected type-name"); lua_pushboolean(lua, false); return 1; } // Get the resource IzXomlResource* resource = NULL; if (lua_isuserdata(lua, 1)) resource = (CzScene*)lua_touserdata(lua, 1); else { CzScriptEngineLua::DisplayError(lua, "sys.isTypeOf() Invalid parameter, expected object for Param0"); lua_pushboolean(lua, false); return 1; } // Get the type of actor to create const char* type = NULL; if (lua_isstring(lua, 2)) type = lua_tostring(lua, 2); else { CzScriptEngineLua::DisplayError(lua, "sys.isTypeOf() Invalid parameter, expected type-name for Param1"); lua_pushboolean(lua, false); return 1; } unsigned int type_hash = CZ_HASH(type); if (resource->getClassTypeHash() == type_hash) lua_pushboolean(lua, true); else lua_pushboolean(lua, false); return 1; }
// // LUA_GetPropertyScene scene (object), property (string) // static int LUA_GetPropertyScene(lua_State *lua) { if (lua_gettop(lua) < 2) { CzScriptEngineLua::DisplayError(lua, "scene.get() not enough parameters, expected scene (object), property (string)"); lua_pushnil(lua); return 1; } // Get the target object IzXomlResource* object = NULL; if (lua_isuserdata(lua, 1)) object = (IzXomlResource*)lua_touserdata(lua, 1); if (object == NULL || object->getClassTypeHash() != CzHashes::Scene_Hash) { CzScriptEngineLua::DisplayError(lua, "scene.get() Invalid target object for Param0"); lua_pushnil(lua); return 1; } CzString prop_name, value; if (lua_isstring(lua, 2)) prop_name = lua_tostring(lua, 2); else { CzScriptEngineLua::DisplayError(lua, "scene.get() property must be a property name (Param1) - object - ", object->getName().c_str()); lua_pushnil(lua); return 1; } CzXomlProperty prop; if (!((CzScene*)object)->getProperty(prop_name.getHash(), prop)) { CzScriptEngineLua::DisplayError(lua, "scene.get() scene property does not exist - ", prop_name.c_str()); lua_pushnil(lua); return 1; } LUA_ReturnProperty(lua, prop); return 1; }
static int luaBufferData(lua_State *pState) { if(!lua_isuserdata(pState, -1)){ lua_pushstring(pState, "invalid argument:1"); lua_error(pState); return 1; } Buffer *pBuffer = (Buffer*)lua_touserdata(pState, -1); if(!pBuffer){ lua_pushstring(pState, "invalid buffer"); lua_error(pState); return 1; } lua_pop(pState, 1); lua_pushlstring(pState, pBuffer->data(), pBuffer->size()); return 1; }
static int lsend(lua_State *L) { struct skynet_context * ctx = lua_touserdata(L, lua_upvalueindex(1)); int id = luaL_checkinteger(L, 1); void *buffer; int sz; if (lua_isuserdata(L,2)) { buffer = lua_touserdata(L,2); sz = luaL_checkinteger(L,3); } else { size_t len = 0; const char * str = luaL_checklstring(L, 2, &len); buffer = malloc(len); memcpy(buffer, str, len); sz = (int)len; } int err = skynet_socket_send(ctx, id, buffer, sz); lua_pushboolean(L, !err); return 1; }
// indexing a handle returns a helper int client_newindex( lua_State *L ) { const char *s; check_num_args( L, 3 ); MYASSERT( lua_isuserdata( L, 1 ) && ismetatable_type( L, 1, "rpc.client" ) ); if( lua_type( L, 2 ) != LUA_TSTRING ) return luaL_error( L, "can't index handle with a non-string" ); s = lua_tostring( L, 2 ); if ( strlen( s ) > NUM_FUNCNAME_CHARS - 1 ) return luaL_error( L, error_string( ERR_LONGFNAME ) ); helper_create( L, ( Transport* )lua_touserdata( L, 1 ), "" ); lua_replace(L, 1); helper_newindex( L ); return 0; }
static int RenderInstance_setconstantbuffer(lua_State* L) { lua_render_instance* inst_hdlr = (lua_render_instance*)lua_touserdata(L, 1); kl_render_instance_t* inst = inst_hdlr->inst; luaL_argcheck(L, lua_istable(L, 2), 2, "expected table created by ConstantBuffer.new"); lua_getfield(L, 2, "_constantbuffer"); if(lua_isnoneornil(L, -1) || !lua_isuserdata(L, -1)) { lua_pop(L, 1); luaL_argcheck(L, 0, 2, "expected table created by ConstantBuffer.new"); } else { inst->constant_buffer = luaL_checkudata(L, -1, CONSTANT_BUFFER_LUA_LIB); lua_pop(L, 1); } return 0; }
void Lua_V2::StopChore() { lua_Object choreObj = lua_getparam(1); lua_Object fadeTimeObj = lua_getparam(2); if (!lua_isuserdata(choreObj) || lua_tag(choreObj) != MKTAG('C','H','O','R')) return; int chore = lua_getuserdata(choreObj); float fadeTime = 0.0f; if (!lua_isnil(fadeTimeObj)) { if (lua_isnumber(fadeTimeObj)) fadeTime = lua_getnumber(fadeTimeObj); } Chore *c = EMIChore::getPool().getObject(chore); if (c) { c->stop((int)(fadeTime * 1000)); } }
void* GetField_Userdata( lua_State* L, int index, const std::string& key ) { int tableIndex = ToPositiveIndex(L, index); assert(lua_istable(L, tableIndex)); // 获取结果 lua_pushstring(L, key.c_str()); lua_gettable(L, tableIndex); void* result = NULL; if (lua_isuserdata(L, -1)) result = lua_touserdata(L, -1); // 结果出栈,还原栈 lua_pop(L, 1); return result; }
static int l_eventloop_add(lua_State *L) { struct laura_node *lnode; struct laura_eventloop *lloop; TRACE(); aura_check_args(L, 2); if (!lua_isuserdata(L, 1)) aura_typeerror(L, 1, "ludata (eventloop)"); lnode = lua_fetch_node(L, 2); lloop = lua_touserdata(L, 1); if (!lloop || !lnode) return luaL_error(L, "Failed to retrive arguments"); aura_eventloop_add(lloop->loop, lnode->node); return 0; }
static int l_set_node_container(lua_State *L) { struct laura_node *lnode; TRACE(); aura_check_args(L, 2); if (!lua_isuserdata(L, 1)) aura_typeerror(L, 1, "udata"); if (!lua_istable(L, 2)) aura_typeerror(L, 2, "table"); lnode = lua_touserdata(L, 1); lnode->node_container = luaL_ref(L, LUA_REGISTRYINDEX); lnode->refs |= REF_NODE_CONTAINER; aura_unhandled_evt_cb(lnode->node, event_cb, lnode); return 0; }