StendhalScripting/Lua: Difference between revisions
Content deleted Content added
imported>AntumDeluge |
imported>AntumDeluge →Misc: typecasting |
||
Line 495:
print("Test server disabled")
end
</pre>
== Misc ==
=== Typecasting ===
Lua does not support typecasting (as far as I know), but if the class you want to cast to has a copy constructor, achieving the same functionality is quite simple.
<pre>
-- "entities:getItem" returns an instance of Item
local bestiary = entities:getItem("bestiary")
-- in order to use the bestiary's "setOwner" method, we must convert it to an "OwnedItem" instance by calling its copy constructor
bestiary = luajava.newInstance("games.stendhal.server.entity.item.OwnedItem", bestiary)
bestiary:setOwner("Ted")
</pre>
| |||