diff --git a/lua-beef-test/BeefProj.toml b/lua-beef-test/BeefProj.toml index 7681f4b..efb31af 100644 --- a/lua-beef-test/BeefProj.toml +++ b/lua-beef-test/BeefProj.toml @@ -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)\")"] diff --git a/lua-beef-test/assets/compile_example.bat b/lua-beef-test/assets/compile_example.bat new file mode 100644 index 0000000..bfb503d --- /dev/null +++ b/lua-beef-test/assets/compile_example.bat @@ -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 diff --git a/lua-beef-test/assets/compiledLua.53.luac b/lua-beef-test/assets/compiledLua.53.luac new file mode 100644 index 0000000..b79bc9c Binary files /dev/null and b/lua-beef-test/assets/compiledLua.53.luac differ diff --git a/lua-beef-test/assets/compiledLua.54.luac b/lua-beef-test/assets/compiledLua.54.luac new file mode 100644 index 0000000..affc5a3 Binary files /dev/null and b/lua-beef-test/assets/compiledLua.54.luac differ diff --git a/lua-beef-test/assets/compiledLua.lua b/lua-beef-test/assets/compiledLua.lua new file mode 100644 index 0000000..2cf8bdc --- /dev/null +++ b/lua-beef-test/assets/compiledLua.lua @@ -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 diff --git a/lua-beef-test/assets/compiledLua_d.53.luac b/lua-beef-test/assets/compiledLua_d.53.luac new file mode 100644 index 0000000..5f691a8 Binary files /dev/null and b/lua-beef-test/assets/compiledLua_d.53.luac differ diff --git a/lua-beef-test/assets/compiledLua_d.54.luac b/lua-beef-test/assets/compiledLua_d.54.luac new file mode 100644 index 0000000..037590e Binary files /dev/null and b/lua-beef-test/assets/compiledLua_d.54.luac differ diff --git a/lua-beef-test/assets/luac53.exe b/lua-beef-test/assets/luac53.exe new file mode 100644 index 0000000..bf42f08 Binary files /dev/null and b/lua-beef-test/assets/luac53.exe differ diff --git a/lua-beef-test/assets/luac54.exe b/lua-beef-test/assets/luac54.exe new file mode 100644 index 0000000..3a7e36c Binary files /dev/null and b/lua-beef-test/assets/luac54.exe differ diff --git a/lua-beef-test/test.lua b/lua-beef-test/assets/test.lua similarity index 89% rename from lua-beef-test/test.lua rename to lua-beef-test/assets/test.lua index 4416220..6c50e99 100644 --- a/lua-beef-test/test.lua +++ b/lua-beef-test/assets/test.lua @@ -1,4 +1,4 @@ ---lua 5.3 +--lua 5.4 -- test.lua function Run(val) diff --git a/lua-beef-test/src/Program.bf b/lua-beef-test/src/Program.bf index 5ca4ea9..1a78b0c 100644 --- a/lua-beef-test/src/Program.bf +++ b/lua-beef-test/src/Program.bf @@ -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() { @@ -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" */ @@ -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() { @@ -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!(); } diff --git a/lua-beef-test/src/TestModule.bf b/lua-beef-test/src/TestModule.bf index b5af824..87e4b60 100644 --- a/lua-beef-test/src/TestModule.bf +++ b/lua-beef-test/src/TestModule.bf @@ -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 {