News for hackers. Stuff that matters.
Re:PH7 – An Embedded Implementation of PHP (C Library) by Touche on Wednesday February 19, 2014 @11:21AM (#7264323)
> gcc -W -Wall -O6 -o ph7_test ph7_intro.c ph7.c

Nice! I wish creating Lua executables were this easy. With Lua you have to create a wrapper C file, use squishy to combine multiple lua files into one, and finally a script to turn the lua script into a C byte array. I have a boilerplate project that I use so that I just have to run `make`, that avoids the need to ever touch C for the most part. But it would be nicer if luac and luajit did this automatically.

Re:PH7 – An Embedded Implementation of PHP (C Library) by aktau on Wednesday February 19, 2014 @11:35AM (#7264418)
You mean so you can distribute a standalone binary that is actually just a bunch of lua? Do you do this so that the users have a harder time modifying the code (just curious)? I'm supposing that this is the case otherwise it would work pretty well with by using the lua or luajit interpreter and some wrapper bash/cmd.exe script to run your lua file(s).
Re:PH7 – An Embedded Implementation of PHP (C Library) by Touche on Wednesday February 19, 2014 @11:43AM (#7264463)
> You mean so you can distribute a standalone binary that is actually just a bunch of lua?

No, I'm saying that you can't. You create a wrapper main.c file that loads and executes the lua. I use a script that tranlates the lua into a C byte array so that I can avoid loading the external lua scripts.

> Do you do this so that the users have a harder time modifying the code (just curious)? I'm supposing that this is the case otherwise it would work pretty well with by using the lua or luajit interpreter and some wrapper bash/cmd.exe script to run your lua file(s).

No, I do it to avoid having to worry about where the .lua scripts are located. Having a single binary is nicety, not required of course.

Re:PH7 – An Embedded Implementation of PHP (C Library) by fsniper on Wednesday February 19, 2014 @12:35PM (#7264806)
I think what you are looking is called a packager. I left The Windows world and scene long time ago but t was very popular in scenes.

With a little search I found out UPX and it seems to be working with many unix binary formats too.. http://upx.sourceforge.net/

Re:PH7 – An Embedded Implementation of PHP (C Library) by coldtea on Wednesday February 19, 2014 @12:20PM (#7264686)
>No, I'm saying that you can't. You create a wrapper main.c file that loads and executes the lua. I use a script that tranlates the lua into a C byte array so that I can avoid loading the external lua scripts.

I think that's what he meant -- that ignoring the small wrapper part --which is boilerplate--, you can deliver a binary that's basically lua.

Re:PH7 – An Embedded Implementation of PHP (C Library) by justincormack on Wednesday February 19, 2014 @12:04PM (#7264587)
LuaJIT can output bytecode as .o files that you can just link. It is not very well documented but its pretty easy once you get the hang of it.
Re:PH7 – An Embedded Implementation of PHP (C Library) by Touche on Wednesday February 19, 2014 @12:29PM (#7264758)
.o files are not executable. You still have to link it to something that executes, and that something isn't Lua.
Re:PH7 – An Embedded Implementation of PHP (C Library) by oscargrouch on Wednesday February 19, 2014 @02:53PM (#7265796)
.o files are executable code.. they are just not a native file executable (elf, coff, mach-o) = headers + .o files
Re:PH7 – An Embedded Implementation of PHP (C Library) by justincormack on Wednesday February 19, 2014 @05:44PM (#7267022)
yeah, you link to lua.a or lua.so and a very small stub to run the code. There is an example here https://github.com/justincormack/ljsyscall/blob/master/examp...
Re:PH7 – An Embedded Implementation of PHP (C Library) by ygra on Wednesday February 19, 2014 @01:30PM (#7265192)
Couldn't you tell the linker to use one of the functions in the .o as entry point?
Re:PH7 – An Embedded Implementation of PHP (C Library) by oscargrouch on Wednesday February 19, 2014 @02:31PM (#7265658)
yes..

1 - create the object files (with luajit?)

2 - create a main() in c.. use "extern" to reference the external symbol in the .o files and call it from main.

The symbols in the object files produced by luajit or whatever need to be exported/ visible.. (are they mangled?)

3 - create a object file for main.c

4 - link the .o created from luajit(or whatever, dart?) and main.o together

If the linker cant find the external symbol it wont link to a binary (so you need to know how, in what names they are exported.. use objdump to lookup for symbols)

Re:PH7 – An Embedded Implementation of PHP (C Library) by Touche on Wednesday February 19, 2014 @01:46PM (#7265317)
Code example?

edit: If so I've been doing it wrong for years.

Re:PH7 – An Embedded Implementation of PHP (C Library) by stephan10h on Wednesday February 19, 2014 @05:37PM (#7266950)
Re:PH7 – An Embedded Implementation of PHP (C Library) by ygra on Thursday February 20, 2014 @12:52AM (#7269131)
ld has a -e argument [−4] (and MSVC's link has /ENTRY [37]). Otherwise, if there is a function with the expected name, calling convention and arguments in the object file I doubt the linker will complain.

[−4] ftp://ftp.gnu.org/old-gnu/Manuals/ld-2.9.1/html_node/ld_24.html

[37] http://msdn.microsoft.com/library/f9t8842e.aspx

Re:PH7 – An Embedded Implementation of PHP (C Library) by unwind on Wednesday February 19, 2014 @11:23AM (#7264337)
On the other hand, the single-source engine is so large, GitHub won't display it on the web. :/
Re:PH7 – An Embedded Implementation of PHP (C Library) by eksith on Wednesday February 19, 2014 @11:36AM (#7264424)
I was curious why they did that. Just looked at the source and came across this :

  This file is an amalgamation of many separate C source files from PH7 version 2.1.
  By combining all the individual C code files into this single large file, the entire code
  can be compiled as a single translation unit.This allows many compilers to do optimization's
  that would not be possible if the files were compiled separately.Performance improvements
  are commonly seen when PH7 is compiled as a single translation unit.
The target does say for embedded so I guess that's from experience running this on very small resources.
Re:PH7 – An Embedded Implementation of PHP (C Library) by unwind on Wednesday February 19, 2014 @11:41AM (#7264450)
But the glueing together destroys any modularization they had going on, making the code way harder for anyone else to understand and read.

The "typical" solution to that very valid problem is to use the preprocessor, i.e. create a "ph7-master.c" file that simply includes all the real C files.

The comparative overhead of should be negligble, but then the modularization survives.

Re:PH7 – An Embedded Implementation of PHP (C Library) by Touche on Wednesday February 19, 2014 @11:44AM (#7264470)
Or use cat to combine the files prior to compiling.
Re:PH7 – An Embedded Implementation of PHP (C Library) by symisc_devel on Wednesday February 19, 2014 @11:31AM (#7264394)
SQLite style: The amalgamation is a single C code file, that contains all C code for the core. With one big unit, the compiler can perform several smart optimizations that cannot be done if the source code was split between different C files.
Re:PH7 – An Embedded Implementation of PHP (C Library) by 72deluxe on Wednesday February 19, 2014 @11:49AM (#7264504)
Also makes it dead easy to download and embed into projects! Hurray for single source files.