Exemple #1
0
/**
	Demonstrate reading and saving a script.
**/
void
TestScript::DoScriptSaveTest()
{
	Script script;

	script.DoFile("ScriptSaveTest.scr");
	script.SaveText("ScriptSaveTest.dmp");
}
Exemple #2
0
/**
	Demonstrate registering callback functions for the Lua script.
**/
void
TestScript::DoScriptCallbackTest()
{
	Script script;

	script.Register("PrintNumber", Script_PrintNumber);
	script.Register("Add", Script_Add);

	script.DoFile("ScriptCallbackTest.scr");
}
Exemple #3
0
/**
	Demonstrate the use of the simple .ini script-like functions for reading
	values from a script.
**/
void
TestScript::DoScriptIniReadTest()
{
	Script script;

	script.DoFile("ScriptIniTest.dmp");

	float windSpeed = script.ConfigGetReal("Environment", "WindSpeed", 0.0);
	const char* typeStr = script.ConfigGetString("Environment", "TypeStr", "Clear");
	int integerValue = script.ConfigGetInteger("AnotherGroup", "IntegerValue");
	printf("windSpeed: %f, typeStr: %s, intValue: %d\n", windSpeed, typeStr, integerValue);
}
Exemple #4
0
/**
	Demonstrates walking an array table.
**/
void
TestScript::DoScriptArrayTest()
{
	Script script;
	script.DoFile("ScriptArrayTest.scr");
	Script::Object testTableObj = script.GetGlobals().GetByName("TestArray");
	// or							script.GetGlobal("TestArray");
	for (int i = 1; ; ++i)
	{
		Script::AutoBlock block(script);	// Automatic stack fixups.
		Script::Object entryObj = testTableObj.GetByIndex(i);
		if (entryObj.IsNil())
			break;
		if (entryObj.IsNumber())		// IsNumber() must ALWAYS come first.
			printf("%f\n", entryObj.GetNumber());
		else if (entryObj.IsString())	// IsString() returns true for a number or string.
			printf("%s\n", entryObj.GetString());
	}
}