Skip to content

Commit

Permalink
Add set_action to Decal scripting
Browse files Browse the repository at this point in the history
Fixes #2557
  • Loading branch information
tobbi committed Jul 23, 2023
1 parent 7e8f0ba commit cf5313c
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/scripting/decal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ Decal::fade_out(float time)
object.fade_out(time);
}

void
Decal::set_action(const std::string& action)
{
SCRIPT_GUARD_VOID;
object.set_action(action);
}

} // namespace scripting

/* EOF */
5 changes: 5 additions & 0 deletions src/scripting/decal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ class Decal final
* @param float $time
*/
void fade_out(float time);
/**
* Sets the action for this decal
* @param float $time
*/
void set_action(const std::string& action);
};

} // namespace scripting
Expand Down
37 changes: 37 additions & 0 deletions src/scripting/wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4920,6 +4920,36 @@ static SQInteger Decal_fade_out_wrapper(HSQUIRRELVM vm)

}

static SQInteger Decal_set_action_wrapper(HSQUIRRELVM vm)
{
SQUserPointer data;
if(SQ_FAILED(sq_getinstanceup(vm, 1, &data, nullptr, SQTrue)) || !data) {
sq_throwerror(vm, _SC("'set_action' called without instance"));
return SQ_ERROR;
}
scripting::Decal* _this = reinterpret_cast<scripting::Decal*> (data);

const SQChar* arg0;
if(SQ_FAILED(sq_getstring(vm, 2, &arg0))) {
sq_throwerror(vm, _SC("Argument 1 not a string"));
return SQ_ERROR;
}

try {
_this->set_action(arg0);

return 0;

} catch(std::exception& e) {
sq_throwerror(vm, e.what());
return SQ_ERROR;
} catch(...) {
sq_throwerror(vm, _SC("Unexpected exception while executing function 'set_action'"));
return SQ_ERROR;
}

}

static SQInteger Dispenser_release_hook(SQUserPointer ptr, SQInteger )
{
scripting::Dispenser* _this = reinterpret_cast<scripting::Dispenser*> (ptr);
Expand Down Expand Up @@ -14951,6 +14981,13 @@ void register_supertux_wrapper(HSQUIRRELVM v)
throw SquirrelError(v, "Couldn't register function 'fade_out'");
}

sq_pushstring(v, "set_action", -1);
sq_newclosure(v, &Decal_set_action_wrapper, 0);
sq_setparamscheck(v, SQ_MATCHTYPEMASKSTRING, ".s");
if(SQ_FAILED(sq_createslot(v, -3))) {
throw SquirrelError(v, "Couldn't register function 'set_action'");
}

if(SQ_FAILED(sq_createslot(v, -3))) {
throw SquirrelError(v, "Couldn't register class 'Decal'");
}
Expand Down

0 comments on commit cf5313c

Please sign in to comment.