![]() |
|
[C++] [Release] Lua C API - Printing a string - Printable Version +- Sinisterly (https://sinister.ly) +-- Forum: Coding (https://sinister.ly/Forum-Coding) +--- Forum: C, C++, & Obj-C (https://sinister.ly/Forum-C-C-Obj-C) +--- Thread: [C++] [Release] Lua C API - Printing a string (/Thread-C-Release-Lua-C-API-Printing-a-string) |
[C++] [Release] Lua C API - Printing a string - Confidential - 04-29-2018 Download VirusTotal Spoiler: Lua Interpreter.cppCode: #pragma comment(lib, "lua5.1.lib")
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <Windows.h>
extern "C"
{
#include "lua.h"
#include "lauxlib.h"
#include "lualib.h"
}
using namespace std;
int main(void)
{
SetConsoleTitleA("Lua C API - Printing a string (Made by Confidential)");
lua_State *L = luaL_newstate(); // Creates our environment
luaL_openlibs(L); // Loads the libraries
luaL_dofile(L, "Test.lua"); // Runs the Lua file
lua_close(L); // Exits our environment
system("pause");
return 0;
}Spoiler: Test.luaCode: function infiniteLoop(time)
local second = tonumber(os.clock() + time)
while (os.clock() < second) do
print("This text was printed to the console using the Lua C API!")
end
end
infiniteLoop(5)RE: [C++] [Release] Lua C API - Printing a string - phyrrus9 - 04-29-2018 Why did you make this in C++ if you're writing C code? That's just bad practice. @"Ender" RE: [C++] [Release] Lua C API - Printing a string - Confidential - 04-29-2018 (04-29-2018, 05:26 AM)phyrrus9 Wrote: Why did you make this in C++ if you're writing C code? That's just bad practice. @"Ender" That's just straight up illogical. C++ was designed to be compatible with C. People mix the two languages all the time because of libraries. RE: [C++] [Release] Lua C API - Printing a string - Blink - 04-29-2018 There's no point in using C++ for this, just use C. Lua's neat in that it embeds really nicely into C programs, and it's really fast in comparison to other scripting languages (cough Python cough). You should make a tutorial on something more than just "hello world": Here's a link to the C API documentation: https://www.lua.org/pil/24.html And here's a link to a tutorial on calling C functions from Lua: http://www.troubleshooters.com/codecorn/lua/lua_lua_calls_c.htm RE: [C++] [Release] Lua C API - Printing a string - Blink - 04-29-2018 (04-29-2018, 05:32 AM)Confidential Wrote:(04-29-2018, 05:26 AM)phyrrus9 Wrote: Why did you make this in C++ if you're writing C code? That's just bad practice. @"Ender" Common advice: Just because it works doesn't mean it's good RE: [C++] [Release] Lua C API - Printing a string - mothered - 04-29-2018 (04-29-2018, 06:45 AM)Ender Wrote:(04-29-2018, 05:32 AM)Confidential Wrote:(04-29-2018, 05:26 AM)phyrrus9 Wrote: Why did you make this in C++ if you're writing C code? That's just bad practice. @"Ender" Agree. A simple example (on a different note) Is selecting the best pen testing tool. There's no purpose If the tool Is very user-friendly and pen tester has all the knowledge & skill set In how to use It, however the tool does not serve It's purpose In an efficient and effective manner. Reversing the role, there's no purpose If the tool scans the network & system accordingly, Identifies vulnerabilities, prioritizes them from the most critical to the least and generates a detailed report at the end of all findings, but It's so complex to use that the pen tester has very little knowledge of how to operate It. In this case, It "must" work both ways. Perhaps off-topic to some extent, but the analogy gives an Indication of what to look for when approaching a task at hand. |