Skip to content

Commit

Permalink
Add some additional testing to the test app
Browse files Browse the repository at this point in the history
  • Loading branch information
LauraRozier committed Nov 9, 2020
1 parent 799f42d commit 9a1c585
Show file tree
Hide file tree
Showing 12 changed files with 113 additions and 20 deletions.
26 changes: 16 additions & 10 deletions lua-beef-test/BeefProj.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,28 @@ Name = "lua-beef-test"
StartupObject = "lua_beef_test.Program"

[Configs.Debug.Win32]
PostBuildCmds = ["CopyFilesIfNewer(\"$(ProjectDir)/test.lua\", \"$(TargetDir)\")"]
PostBuildCmds = ["CopyFilesIfNewer(\"$(ProjectDir)/assets/test.lua\", \"$(TargetDir)\")", "CopyFilesIfNewer(\"$(ProjectDir)/assets/*.luac\", \"$(TargetDir)\")"]

[Configs.Debug.Win64]
PostBuildCmds = ["CopyFilesIfNewer(\"$(ProjectDir)/test.lua\", \"$(TargetDir)\")"]
PostBuildCmds = ["CopyFilesIfNewer(\"$(ProjectDir)/assets/test.lua\", \"$(TargetDir)\")", "CopyFilesIfNewer(\"$(ProjectDir)/assets/*.luac\", \"$(TargetDir)\")"]

[Configs.Debug.Linux64]
PostBuildCmds = ["CopyFilesIfNewer(\"$(ProjectDir)/test.lua\", \"$(TargetDir)\")"]
PostBuildCmds = ["CopyFilesIfNewer(\"$(ProjectDir)/assets/test.lua\", \"$(TargetDir)\")", "CopyFilesIfNewer(\"$(ProjectDir)/assets/*.luac\", \"$(TargetDir)\")"]

[Configs.Release.Win32]
PostBuildCmds = ["CopyFilesIfNewer(\"$(ProjectDir)/test.lua\", \"$(TargetDir)\")"]
OptimizationLevel = "O2"
PostBuildCmds = ["CopyFilesIfNewer(\"$(ProjectDir)/assets/test.lua\", \"$(TargetDir)\")", "CopyFilesIfNewer(\"$(ProjectDir)/assets/*.luac\", \"$(TargetDir)\")"]

[Configs.Release.Win64]
PostBuildCmds = ["CopyFilesIfNewer(\"$(ProjectDir)/test.lua\", \"$(TargetDir)\")"]
OptimizationLevel = "O2"
PostBuildCmds = ["CopyFilesIfNewer(\"$(ProjectDir)/assets/test.lua\", \"$(TargetDir)\")", "CopyFilesIfNewer(\"$(ProjectDir)/assets/*.luac\", \"$(TargetDir)\")"]

[Configs.Release.Linux64]
PostBuildCmds = ["CopyFilesIfNewer(\"$(ProjectDir)/test.lua\", \"$(TargetDir)\")"]
OptimizationLevel = "O2"
[Configs.Paranoid.Win32]
PostBuildCmds = ["CopyFilesIfNewer(\"$(ProjectDir)/assets/test.lua\", \"$(TargetDir)\")", "CopyFilesIfNewer(\"$(ProjectDir)/assets/*.luac\", \"$(TargetDir)\")"]

[Configs.Paranoid.Win64]
PostBuildCmds = ["CopyFilesIfNewer(\"$(ProjectDir)/assets/test.lua\", \"$(TargetDir)\")", "CopyFilesIfNewer(\"$(ProjectDir)/assets/*.luac\", \"$(TargetDir)\")"]

[Configs.Test.Win32]
PostBuildCmds = ["CopyFilesIfNewer(\"$(ProjectDir)/assets/test.lua\", \"$(TargetDir)\")", "CopyFilesIfNewer(\"$(ProjectDir)/assets/*.luac\", \"$(TargetDir)\")"]

[Configs.Test.Win64]
PostBuildCmds = ["CopyFilesIfNewer(\"$(ProjectDir)/assets/test.lua\", \"$(TargetDir)\")", "CopyFilesIfNewer(\"$(ProjectDir)/assets/*.luac\", \"$(TargetDir)\")"]
6 changes: 6 additions & 0 deletions lua-beef-test/assets/compile_example.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@ECHO OFF
luac53.exe -o compiledLua_d.53.luac compiledLua.lua
luac53.exe -s -o compiledLua.53.luac compiledLua.lua

luac54.exe -o compiledLua_d.54.luac compiledLua.lua
luac54.exe -s -o compiledLua.54.luac compiledLua.lua
Binary file added lua-beef-test/assets/compiledLua.53.luac
Binary file not shown.
Binary file added lua-beef-test/assets/compiledLua.54.luac
Binary file not shown.
15 changes: 15 additions & 0 deletions lua-beef-test/assets/compiledLua.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
--lua5.4
-- compiledLua.lua

function TestPrint(val)
print('Hello World from a compiles script running in ' .. LUA_RELEASE .. val)

print(debug.traceback("Stack trace"))
print("Stack trace end")
end

function Run(val)
TestPrint(val)
local tmp = 1 + 500 * 99
print('1 + 500 * 99 = ' .. tmp)
end
Binary file added lua-beef-test/assets/compiledLua_d.53.luac
Binary file not shown.
Binary file added lua-beef-test/assets/compiledLua_d.54.luac
Binary file not shown.
Binary file added lua-beef-test/assets/luac53.exe
Binary file not shown.
Binary file added lua-beef-test/assets/luac54.exe
Binary file not shown.
2 changes: 1 addition & 1 deletion lua-beef-test/test.lua → lua-beef-test/assets/test.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
--lua 5.3
--lua 5.4
-- test.lua

function Run(val)
Expand Down
77 changes: 68 additions & 9 deletions lua-beef-test/src/Program.bf
Original file line number Diff line number Diff line change
@@ -1,14 +1,28 @@
// NOTE : If you change this, first clean, then build.
#define USE_LUA54

using System;
using System.IO;
using lua54_beef;
#if USE_LUA54
using lua54_beef;
#else
using lua53_beef;
#endif

namespace lua_beef_test
{
class Program
{
private static lua_State* fLuaState;
private static String fExeDir = new .() ~ delete _;
private const String TEST_SCRIPT = "test.lua";
private static String fExeDir = new .() ~ delete _;
private const String TEST_SCRIPT = "test.lua";
#if USE_LUA54
private const String TEST_SCRIPT_COMPILED = "compiledLua.54.luac";
private const String TEST_SCRIPT_COMPILED_DEBUG = "compiledLua_d.54.luac";
#else
private const String TEST_SCRIPT_COMPILED = "compiledLua.53.luac";
private const String TEST_SCRIPT_COMPILED_DEBUG = "compiledLua_d.53.luac";
#endif

static void Main()
{
Expand All @@ -18,6 +32,11 @@ namespace lua_beef_test
Path.GetDirectoryPath(tmp, fExeDir);
delete tmp;

/*---------------------------------------------------------------------------
** Lua from a text file
*/

Console.WriteLine("DEBUG > Running LUA script using run-time compiler\n");
/** Initialize the Lua library and create the main Lua thread **/
fLuaState = lauxlib.newstate();
/* TODO: Custom alloc is broken, needs a working implementation. Throws "EXCEPTION_ACCESS_VIOLATION reading from 0xFFFFFFFF'FFFFFFFF" */
Expand All @@ -28,20 +47,54 @@ namespace lua_beef_test
/* Overwrite the built-in print(..) method */
lua.register(fLuaState, "print", => l_print);

RunScript();
RunScript(TEST_SCRIPT, "World");

/** Stop the main thread, perform last remaining cleanups and destruct the Lua library **/
lua.close(fLuaState);

Console.WriteLine("\nPress Enter to exit");
/*---------------------------------------------------------------------------
** Lua from a compiled script with debug symbols
*/

Console.WriteLine("DEBUG > Running pre-compiled (using luac.exe) LUA script with debug symbols\n");
/** Initialize the Lua library and create the main Lua thread **/
fLuaState = lauxlib.newstate();
PushModules();
PushGlobals();
/* Overwrite the built-in print(..) method */
lua.register(fLuaState, "print", => l_print);

RunScript(TEST_SCRIPT_COMPILED_DEBUG, " with debug symbols");

/** Stop the main thread, perform last remaining cleanups and destruct the Lua library **/
lua.close(fLuaState);

/*---------------------------------------------------------------------------
** Lua from a compiled script
*/

Console.WriteLine("DEBUG > Running pre-compiled (using luac.exe) LUA script without debug symbols\n");
/** Initialize the Lua library and create the main Lua thread **/
fLuaState = lauxlib.newstate();
PushModules();
PushGlobals();
/* Overwrite the built-in print(..) method */
lua.register(fLuaState, "print", => l_print);

RunScript(TEST_SCRIPT_COMPILED, "");

/** Stop the main thread, perform last remaining cleanups and destruct the Lua library **/
lua.close(fLuaState);

Console.WriteLine("Press Enter to exit");
Console.In.Read();
}

private static void RunScript()
private static void RunScript(String file, String val)
{
String errorStr = new .("Error: ");
String scriptFile = new .(fExeDir);
scriptFile.AppendF("{}{}", Path.DirectorySeparatorChar, TEST_SCRIPT);
scriptFile.AppendF("{}{}", Path.DirectorySeparatorChar, file);

/* Save ourselves some typing work and just make use of the wonderfull mixins */
mixin exit() {
Expand Down Expand Up @@ -75,13 +128,19 @@ namespace lua_beef_test

Console.WriteLine("DEBUG > Found the 'Run' function\n");
/** Push a variable onto the stack, this is how we provide arguments for the function we're about to call **/
lua.pushstring(fLuaState, "World");
lua.pushstring(fLuaState, val.CStr());

if (lua.pcall(fLuaState, 1, 0, 0) != lua.OK) { // Call the "Run" function
errorOut!();
}

Console.WriteLine("\nDEBUG > 'Run' method ran OK");
Console.WriteLine("""
DEBUG > 'Run' method ran OK
<=======================================================================================>
""");
exit!();
}

Expand Down
7 changes: 7 additions & 0 deletions lua-beef-test/src/TestModule.bf
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
// NOTE : If you change this, first clean, then build.
#define USE_LUA54

#if USE_LUA54
using lua54_beef;
#else
using lua53_beef;
#endif

namespace lua_beef_test
{
Expand Down

0 comments on commit 9a1c585

Please sign in to comment.