lua 根据字符串调用函数

local GMDirective =
{
}

function SetRoleLV(nRoleID)
print("test",nRoleID)
end

table.insert(GMDirective,SetRoleLV)

for k,v in pairs(GMDirective) do
v(100)
end

 

function SetRoleLV(nRoleID)
	print("test",nRoleID)
end
function GetItem(nRoleID,nItemID)
	print(nRoleID,nItemID)
end
local GMDirective =
{
	["SetRoleLV"]={SetRoleLV,1},
	["GetItem"]={GetItem,2}
}
local MsgTable = {1,2,3,4,5}
for k,v in pairs(GMDirective) do
	GMDirective[k][1](MsgTable[1],MsgTable[2])
end

  

	local fun = loadstring(GMDirective[FucName])
	if type(fun) == "function" then
		fun(pPlayer,MSGTable)
	end

  

posted @ 2013-02-16 18:36  byfei  阅读(1616)  评论(0)    收藏  举报