lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


It was thus said that the Great Dibyendu Majumdar once stated:
> Hi,
> 
> Early days but have a look at this example snippet:
> 
> 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()

  Nice.  Are you planning on supporting?

	local testfunc = [[
	#include <stdio.h>
	#include <lua.h>
	
	int TestFunc(lua_State *L)
	{
	  puts("hello world!\n");
	  return 0;
	}
	]]

  That's something my own C compiler module [1] does:

	local cc = require "org.conman.cc"
	
	local CODE = [[
	#include <stdio.h>
	#include <lua.h>

	int TestFunc(lua_State *L)
	{
	  puts("hello world!\n");
	  return 0;
	}
	]]

	local f = cc.compile("TestFunc",CODE)
	f()

  -spc

[1]	https://github.com/spc476/lua-conmanorg/blob/master/lua/cc.lua [2]

[2]	It's based on TCC, not LLVM.  It also adds another loader to load
	lua modules written in C directly from C source code.