It is impossible to access Q-Id info with a Lua function. It can be done only by a API call like
https://www.wikidata.org/w/api.php?action=wbgetentities&ids=Q42&props=info
It returns:
{ "entities": { "Q42": { "pageid": 138, "ns": 0, "title": "Q42", "lastrevid": 503604471, "modified": "2017-06-20T10:01:26Z", "type": "item", "id": "Q42" } }, "success": 1 }
The most important is of course the modified parameter. I think a function should return the complete info block.