Java Code Examples for org.luaj.vm2.LuaValue#setmetatable()

The following examples show how to use org.luaj.vm2.LuaValue#setmetatable() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DebugLib.java    From VideoOS-Android-SDK with GNU General Public License v3.0 6 votes vote down vote up
public LuaValue call(LuaValue value, LuaValue table) {
    LuaValue mt = table.opttable(null);
    switch (value.type()) {
        case TNIL:
            LuaNil.s_metatable = mt;
            break;
        case TNUMBER:
            LuaNumber.s_metatable = mt;
            break;
        case TBOOLEAN:
            LuaBoolean.s_metatable = mt;
            break;
        case TSTRING:
            LuaString.s_metatable = mt;
            break;
        case TFUNCTION:
            LuaFunction.s_metatable = mt;
            break;
        case TTHREAD:
            LuaThread.s_metatable = mt;
            break;
        default:
            value.setmetatable(mt);
    }
    return value;
}
 
Example 2
Source File: DebugLib.java    From XPrivacyLua with GNU General Public License v3.0 5 votes vote down vote up
public LuaValue call(LuaValue value, LuaValue table) {
	LuaValue mt = table.opttable(null);
	switch ( value.type() ) {
		case TNIL:      LuaNil.s_metatable      = mt; break;
		case TNUMBER:   LuaNumber.s_metatable   = mt; break;
		case TBOOLEAN:  LuaBoolean.s_metatable  = mt; break;
		case TSTRING:   LuaString.s_metatable   = mt; break;
		case TFUNCTION: LuaFunction.s_metatable = mt; break;
		case TTHREAD:   LuaThread.s_metatable   = mt; break;
		default: value.setmetatable( mt );
	}
	return value;
}
 
Example 3
Source File: DebugLib.java    From HtmlNative with Apache License 2.0 5 votes vote down vote up
public LuaValue call(LuaValue value, LuaValue table) {
	LuaValue mt = table.opttable(null);
	switch ( value.type() ) {
		case TNIL:      LuaNil.s_metatable      = mt; break;
		case TNUMBER:   LuaNumber.s_metatable   = mt; break;
		case TBOOLEAN:  LuaBoolean.s_metatable  = mt; break;
		case TSTRING:   LuaString.s_metatable   = mt; break;
		case TFUNCTION: LuaFunction.s_metatable = mt; break;
		case TTHREAD:   LuaThread.s_metatable   = mt; break;
		default: value.setmetatable( mt );
	}
	return value;
}
 
Example 4
Source File: BaseLib.java    From HtmlNative with Apache License 2.0 5 votes vote down vote up
public LuaValue call(LuaValue table, LuaValue metatable) {
    final LuaValue mt0 = table.checktable().getmetatable();
    if (mt0 != null && !mt0.rawget(METATABLE).isnil()) {
        error("cannot change a protected metatable");
    }
    return table.setmetatable(metatable.isnil() ? null : metatable.checktable());
}
 
Example 5
Source File: DebugLib.java    From luaj with MIT License 5 votes vote down vote up
public LuaValue call(LuaValue value, LuaValue table) {
	LuaValue mt = table.opttable(null);
	switch ( value.type() ) {
		case TNIL:      LuaNil.s_metatable      = mt; break;
		case TNUMBER:   LuaNumber.s_metatable   = mt; break;
		case TBOOLEAN:  LuaBoolean.s_metatable  = mt; break;
		case TSTRING:   LuaString.s_metatable   = mt; break;
		case TFUNCTION: LuaFunction.s_metatable = mt; break;
		case TTHREAD:   LuaThread.s_metatable   = mt; break;
		default: value.setmetatable( mt );
	}
	return value;
}
 
Example 6
Source File: BaseLib.java    From VideoOS-Android-SDK with GNU General Public License v3.0 4 votes vote down vote up
public LuaValue call(LuaValue table, LuaValue metatable) {
     LuaValue mt0 = table.getmetatable();
    if (mt0 != null && !mt0.rawget(METATABLE).isnil())
        error("cannot change a protected metatable");
    return table.setmetatable(metatable.isnil() ? null : metatable.checktable());
}
 
Example 7
Source File: BaseLib.java    From XPrivacyLua with GNU General Public License v3.0 4 votes vote down vote up
public LuaValue call(LuaValue table, LuaValue metatable) {
	final LuaValue mt0 = table.checktable().getmetatable();
	if ( mt0!=null && !mt0.rawget(METATABLE).isnil() )
		error("cannot change a protected metatable");
	return table.setmetatable(metatable.isnil()? null: metatable.checktable());
}
 
Example 8
Source File: BaseLib.java    From luaj with MIT License 4 votes vote down vote up
public LuaValue call(LuaValue table, LuaValue metatable) {
	final LuaValue mt0 = table.checktable().getmetatable();
	if ( mt0!=null && !mt0.rawget(METATABLE).isnil() )
		error("cannot change a protected metatable");
	return table.setmetatable(metatable.isnil()? null: metatable.checktable());
}