package org.luaj.vm;

import java.io.IOException;

import junit.framework.TestCase;

import org.luaj.TestPlatform;

public class LuaStateTest extends TestCase {
	LuaState vm;

	protected void setUp() throws Exception {
        Platform.setInstance(new TestPlatform());
		vm = Platform.newLuaState();		
	}
	
	public void testPushnilReplaceSettop() throws IOException {
		vm.pushnil();
		vm.replace(1);
		vm.settop(1);
		assertEquals( 1, vm.gettop() );
		assertEquals( LNil.NIL, vm.topointer(1) );
		assertEquals( LNil.NIL, vm.topointer(-1) );
	}
}

@@ -538,10 +538,1002 @@
 ) );%0A%09%7D%0A
+%09%0A%09public void testFuncCall() throws IOException %7B%0A%09%09vm.pushstring(%22bogus%22);%0A%09%09vm.pushjavafunction(new SomeFunc( %22arg%22 ));%0A%09%09vm.pushstring(%22arg%22);%0A%09%09vm.call(1, 1);%0A%09%09assertEquals( 2, vm.gettop() );%0A%09%09assertEquals( %22bogus%22, vm.tostring(1) );%0A%09%09assertEquals( LNil.NIL, vm.topointer(2) );%0A%09%09assertEquals( LNil.NIL, vm.topointer(-1) );%0A%09%7D%0A%09%09%0A%09public void testFuncCall2() throws IOException %7B%0A%09%09vm.pushstring(%22bogus%22);%0A%09%09vm.pushjavafunction(new SomeFunc( %22nil%22 ));%0A%09%09vm.call(0, 1);%0A%09%09assertEquals( 2, vm.gettop() );%0A%09%09assertEquals( %22bogus%22, vm.tostring(1) );%0A%09%09assertEquals( LNil.NIL, vm.topointer(2) );%0A%09%09assertEquals( LNil.NIL, vm.topointer(-1) );%0A%09%7D%0A%09%0A%09private static final class SomeFunc extends LFunction %7B%0A%09%09private String expected;%0A%09%09public SomeFunc(String expected) %7B%0A%09%09%09this.expected = expected;%0A%09%09%7D%0A%09%09public boolean luaStackCall(LuaState vm) %7B%0A%09%09%09String arg = vm.tostring(2);%0A%09%09%09assertEquals(expected, arg);%0A%09%09%09vm.pushnil();%0A%09%09%09vm.replace(1);%0A%09%09%09vm.settop(1);%0A%09%09%09return false;%0A%09%09%7D%0A%09%09%0A%09%7D%0A
 %7D%0A

extend vm test