MCPcopy Index your code
hub / github.com/aiscriptdev/aiscript / define_method

Method define_method

aiscript-vm/src/vm/state.rs:1229–1254  ·  view source on GitHub ↗
(&mut self, name: InternedString<'gc>, is_static: bool)

Source from the content-addressed store, hash-verified

1227 }
1228
1229 fn define_method(&mut self, name: InternedString<'gc>, is_static: bool) -> Result<(), VmError> {
1230 match *self.peek(1) {
1231 Value::Class(class) => {
1232 let mut c = class.borrow_mut(self.mc);
1233 if is_static {
1234 c.static_methods.insert(name, *self.peek(0));
1235 } else {
1236 c.methods.insert(name, *self.peek(0));
1237 }
1238 }
1239 Value::Enum(enum_) => {
1240 let mut e = enum_.borrow_mut(self.mc);
1241 if is_static {
1242 e.static_methods.insert(name, *self.peek(0));
1243 } else {
1244 e.methods.insert(name, *self.peek(0));
1245 }
1246 }
1247 _ => {
1248 return Err(self.runtime_error("Only class and enum support define method.".into()));
1249 }
1250 }
1251 // pop the closure since we’re done with it.
1252 self.pop_stack();
1253 Ok(())
1254 }
1255
1256 pub(crate) fn define_native_function(&mut self, name: &'static str, function: NativeFn<'gc>) {
1257 let s = self.intern_static(name);

Callers 1

dispatch_nextMethod · 0.80

Calls 4

runtime_errorMethod · 0.80
pop_stackMethod · 0.80
peekMethod · 0.45
borrow_mutMethod · 0.45

Tested by

no test coverage detected