Page 1 of 1

ASSERT_DLUA

PostPosted: Thursday, 11th December 2014, 16:29
by Slap and stab
So, I was trying to get some lua magic online, but smashed in the brick wall ASSERT_DLUA. This macro kills my scripts, and I don't understand why
  Code:
// Some dLua convenience functions.
IDEF(base_type)
{
    ASSERT_DLUA;
    lua_pushstring(ls, base_type_string(*item).c_str());
    return 1;
}
So... am I not allowed to use functions like base_type, identified, is_cursed and such in my scripts? These look harmless to me.
I try to use them like this:
  Code:
if not item.is_cursed() then ...
and get
  Code:
Operation forbidden in end-user script
I tried to place the lua file in different folders in dat/* and include it via init.txt:
  Code:
lua_file = lua/party/master.lua

Re: ASSERT_DLUA

PostPosted: Thursday, 11th December 2014, 17:02
by Galefury
There's two classes of lua functions in crawl, dlua and clua. Dlua is for the game to use, for example for vaults. Clua is for user scripts. Dlua functions might manipulate the game state or provide information that is usually not available to the user. Clua functions can only do things the user could just as well do himself.

I don't know why the functions you are trying to use are dlua. If you are sure there aren't any information leaks you could ask why they are dlua in ##crawl-dev and ask for them to be moved to clua.

Including the script from somewhere else is not going to help by the way.

Re: ASSERT_DLUA

PostPosted: Thursday, 11th December 2014, 17:55
by neil
Insead of is_cursed() you want cursed(). is_cursed() is dlua-only because it tells you about unidentified curses.

I'm not sure why base_type() is dlua-only, but clua has a similar .class(). It takes an optional boolean to indicate terse mode. In terse mode, the strings are *almost* what base_type returns, except "staff" becomes "magical staff" and "miscellaneous" becomes "misc". No clue why. Without terse mode, the strings are what appear in menus ("Comestibles", "Magical Staves", etc.)

sub_type() has the same problem as is_cursed() (it can give unidentified information about potions/scrolls/etc). The clua equivalent is .subtype(), but that doesn't actually work with most kinds of items. That could stand to be improved.