issue #126 add a couple of simple hello world examples
parent
340e2f1769
commit
1a26a5d43b
@ -0,0 +1,38 @@
|
||||
-- Print anything - including nested tables
|
||||
local function table_print (tt, indent, done)
|
||||
done = done or {}
|
||||
indent = indent or 0
|
||||
if type(tt) == "table" then
|
||||
for key, value in pairs (tt) do
|
||||
io.write(string.rep (" ", indent)) -- indent it
|
||||
if type (value) == "table" and not done [value] then
|
||||
done [value] = true
|
||||
io.write(string.format("[%s] => table\n", tostring (key)));
|
||||
io.write(string.rep (" ", indent+4)) -- indent it
|
||||
io.write("(\n");
|
||||
table_print (value, indent + 7, done)
|
||||
io.write(string.rep (" ", indent+4)) -- indent it
|
||||
io.write(")\n");
|
||||
else
|
||||
io.write(string.format("[%s] => %s\n",
|
||||
tostring (key), tostring(value)))
|
||||
end
|
||||
end
|
||||
else
|
||||
io.write(tostring(tt) .. "\n")
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
local somecode = [[
|
||||
extern int adder(int a, int b);
|
||||
|
||||
int adder(int a, int b)
|
||||
{
|
||||
return a+b;
|
||||
}
|
||||
]]
|
||||
|
||||
local symbols = dmrc.getsymbols(somecode)
|
||||
|
||||
table_print(symbols)
|
@ -0,0 +1,20 @@
|
||||
local testfunc = [[
|
||||
struct lua_State;
|
||||
extern int puts(const char *);
|
||||
extern int TestFunc(struct lua_State *L);
|
||||
|
||||
int TestFunc(struct lua_State *L)
|
||||
{
|
||||
puts("hello world!\n");
|
||||
return 0;
|
||||
}
|
||||
]]
|
||||
|
||||
|
||||
local ctx = llvm.context()
|
||||
local m = ctx:newmodule()
|
||||
m:compileC(testfunc)
|
||||
local f = m:getfunction("TestFunc")
|
||||
local callable = f:compile()
|
||||
|
||||
callable()
|
Loading…
Reference in new issue