<commit_before>package net.sandius.rembulan.core;

import net.sandius.rembulan.util.Check;

public class Metatables {

	public static final String MT_ADD = "__add";
	public static final String MT_SUB = "__sub";
	public static final String MT_MUL = "__mul";
	public static final String MT_DIV = "__div";
	public static final String MT_MOD = "__mod";
	public static final String MT_POW = "__pow";
	public static final String MT_UNM = "__unm";
	public static final String MT_IDIV = "__idiv";

	public static final String MT_BAND = "__band";
	public static final String MT_BOR = "__bor";
	public static final String MT_BXOR = "__bxor";
	public static final String MT_BNOT = "__bnot";
	public static final String MT_SHL = "__shl";
	public static final String MT_SHR = "__shr";

	public static final String MT_CONCAT = "__concat";
	public static final String MT_LEN = "__len";

	public static final String MT_EQ = "__eq";
	public static final String MT_LT = "__lt";
	public static final String MT_LE = "__le";

	public static final String MT_INDEX = "__index";
	public static final String MT_NEWINDEX = "__newindex";

	public static final String MT_CALL = "__call";


	public static Table getMetatable(Object o) {
		if (o instanceof LuaObject) {
			return ((LuaObject) o).getMetatable();
		}
		else {
			LuaState lst = LuaState.getCurrentState();
			LuaType tpe = LuaType.typeOf(o);
			switch (tpe) {
				case NIL: return lst.nilMetatable();
				case BOOLEAN: return lst.booleanMetatable();
				case LIGHTUSERDATA: return lst.lightuserdataMetatable();
				case NUMBER: return lst.numberMetatable();
				case STRING: return lst.stringMetatable();
				case FUNCTION: return lst.functionMetatable();
				case THREAD: return lst.threadMetatable();
				default: throw new IllegalStateException("Illegal type: " + tpe);
			}
		}
	}

	public static Object getMetamethod(Object o, String event) {
		// o can be null
		Check.notNull(event);

		Table mt = getMetatable(o);
		if (mt != null) {
			return mt.rawget(event);
		}
		else {
			return null;
		}
	}

	public static Object binaryHandlerFor(String event, Object a, Object b) {
		Object ma = Metatables.getMetamethod(a, event);
		return ma != null ? ma : Metatables.getMetamethod(b, event);
	}

}<commit_msg>Passing Lua state explicitly as a parameter.<commit_after>package net.sandius.rembulan.core;

import net.sandius.rembulan.util.Check;

public class Metatables {

	public static final String MT_ADD = "__add";
	public static final String MT_SUB = "__sub";
	public static final String MT_MUL = "__mul";
	public static final String MT_DIV = "__div";
	public static final String MT_MOD = "__mod";
	public static final String MT_POW = "__pow";
	public static final String MT_UNM = "__unm";
	public static final String MT_IDIV = "__idiv";

	public static final String MT_BAND = "__band";
	public static final String MT_BOR = "__bor";
	public static final String MT_BXOR = "__bxor";
	public static final String MT_BNOT = "__bnot";
	public static final String MT_SHL = "__shl";
	public static final String MT_SHR = "__shr";

	public static final String MT_CONCAT = "__concat";
	public static final String MT_LEN = "__len";

	public static final String MT_EQ = "__eq";
	public static final String MT_LT = "__lt";
	public static final String MT_LE = "__le";

	public static final String MT_INDEX = "__index";
	public static final String MT_NEWINDEX = "__newindex";

	public static final String MT_CALL = "__call";

	public static Table getMetatable(LuaState state, Object o) {
		Check.notNull(state);
		// o can be null

		if (o instanceof LuaObject) {
			return ((LuaObject) o).getMetatable();
		}
		else {
			LuaType tpe = LuaType.typeOf(o);
			switch (tpe) {
				case NIL: return state.nilMetatable();
				case BOOLEAN: return state.booleanMetatable();
				case LIGHTUSERDATA: return state.lightuserdataMetatable();
				case NUMBER: return state.numberMetatable();
				case STRING: return state.stringMetatable();
				case FUNCTION: return state.functionMetatable();
				case THREAD: return state.threadMetatable();
				default: throw new IllegalStateException("Illegal type: " + tpe);
			}
		}
	}

	public static Object getMetamethod(LuaState state, String event, Object o) {
		// o can be null
		Check.notNull(event);

		Table mt = getMetatable(state, o);
		if (mt != null) {
			return mt.rawget(event);
		}
		else {
			return null;
		}
	}

	@Deprecated
	public static Object getMetamethod(Object o, String event) {
		return getMetamethod(LuaState.getCurrentState(), event, o);
	}

	public static Object binaryHandlerFor(LuaState state, String event, Object a, Object b) {
		Object ma = Metatables.getMetamethod(state, event, a);
		return ma != null ? ma : Metatables.getMetamethod(state, event, b);
	}

	@Deprecated
	public static Object binaryHandlerFor(String event, Object a, Object b) {
		return binaryHandlerFor(LuaState.getCurrentState(), event, a, b);
	}

}
{'fraction_non_alphanumeric': 0.09987770077456176, 'fraction_numerical': 0.0, 'mean_word_length': 4.293419633225459, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4671008', 'n_tokens_mistral': 1679, 'n_tokens_neox': 1586, 'n_words': 516}