Skip to content
This repository was archived by the owner on Nov 14, 2025. It is now read-only.

Commit e87f071

Browse files
Vurv78Vurv78
authored andcommitted
Publish on haxelib, 0.1.0
It's now on haxelib, so it is much easier to install and use in your projects. See examples/Basic Full. Also moved everything to /src/ Documentation is now in Haxe format, so you can see it inside vshaxe / your editor. Timer.systime, curtime, realtime and frametime have been fixed through me committing to SF.
1 parent dbd85d7 commit e87f071

94 files changed

Lines changed: 6601 additions & 3737 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
Proof of concept [Haxe](https://github.com/HaxeFoundation/haxe) Library for the lua target that adds [StarfallEx](https://github.com/thegrb93/StarfallEx) bindings.
33
This was autogenerated by a lua script I made.
44
Hopefully will have the script in this repo as well, made in Haxe.
5+
https://lib.haxe.org/p/sfhaxe/0.1.0
56

67
## Features:
78
* Bindings for every Library and Type in StarfallEx.
89
* Bindings are autogenerated, so it can be updated incredibly easily.
9-
* ...?
10+
* Published on lib.haxe.org
1011

1112
## Todos:
1213
* Publish the autogeneration script
@@ -15,7 +16,11 @@ Hopefully will have the script in this repo as well, made in Haxe.
1516
* Add a standard library that assists with the stuff that can't be autogenerated (Std.print uses io which starfall doesn't have.)
1617

1718
## How to use:
18-
Just make a Haxe project, put this into your src folder or whatever, and use it as ``Example.hx`` does.
19+
Look at the examples/Basic Full directory for a full example.
20+
First, download sfhaxe through haxelib by putting this in your command line.
21+
``haxelib install sfhaxe``
22+
Make a haxe project, and in your ``build.hxml`` file put this:
23+
``-lib sfhaxe``
1924

2025
## What would you use this for?
2126
* If you wanted to have typed, (maybe neater) code.

examples/Basic Full/Basic.hxml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
-lib sfhaxe
3+
# Do haxelib install sfhaxe before this.
4+
5+
-cp src
6+
-main Basic
7+
-lua basic.lua

Example.hx renamed to examples/Basic Full/src/Basic.hx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import sf.library.Builtins.Angle;
33
import sf.type.Angle;
44
import sf.type.Coroutine;
55

6-
class Main {
6+
class Basic {
77
static function main(){
88
var co: Coroutine = Coroutine.create((a:Int) -> {
99
trace('Thanks for the number, $a');

examples/Raytracer.hx

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import sf.library.*;
2+
import sf.library.Builtins.*;
3+
import sf.type.*;
4+
5+
final RES = 64;
6+
final FILTER = [chip()];
7+
8+
typedef TraceResult = {
9+
HitNormal: Vector
10+
// Hopefully will have these return values in a standard library at some point.
11+
}
12+
13+
function canRun() {
14+
// Using cast here, you can also just define the function returns up here.
15+
return cast(quotaTotalAverage(),Int) < cast(quotaMax(),Int)*0.5;
16+
}
17+
18+
function loadRender() {
19+
var chip = cast(chip(), Entity);
20+
var sundir: Vector = Game.getSunInfo();
21+
22+
var cam_pos: Vector = chip.getPos();
23+
var cam_angle: Angle = chip.getAngles();
24+
25+
var bench: Int = Timer.curtime();
26+
27+
var scr_res = RES-1; // Since we start at 0, subtract the resolution by one.
28+
for (Y in 0...scr_res) {
29+
for (X in 0...scr_res) {
30+
trace(X,Y);
31+
var dir = cast(Vector(1,1-(X/scr_res)-0.5,1-(Y/scr_res)-0.5), Vector).getRotated(cam_angle);
32+
var trace: TraceResult = Trace.trace( cam_pos, cam_pos.__add(dir), FILTER, null, null, null );
33+
var shading = trace.HitNormal;
34+
var col: Color = Color(255, 255, 255, 255);
35+
col = col.__mul(shading);
36+
untyped{ col[4] = 255; } // The fields of a color aren't documented, so they aren't defined, so we don't have array access, etc...
37+
Render.selectRenderTarget("rt");
38+
Render.setColor( col );
39+
Render.drawRectFast(X, Y, 1, 1);
40+
Render.selectRenderTarget(null);
41+
if(!canRun()) // Cool syntax from C/C++
42+
Coroutine.yield();
43+
}
44+
}
45+
trace('Finished render in ${bench - cast Timer.curtime()} seconds!');
46+
return true;
47+
}
48+
49+
class Main {
50+
static function main(){
51+
Render.createRenderTarget("rt");
52+
var coro: Coroutine = Coroutine.create( loadRender );
53+
54+
Hook.add("renderoffscreen","",function() { // Another way to have an anonymous function
55+
if (Coroutine.status(coro) != "dead"){
56+
if(canRun())
57+
Coroutine.resume(coro);
58+
}else{
59+
Hook.remove("renderoffscreen","");
60+
}
61+
});
62+
var scale_matrix: sf.type.Vmatrix.VMatrix = Matrix();
63+
var i = 1024/RES;
64+
scale_matrix.setScale( Vector(i, i, i) );
65+
66+
Hook.add("render","",function() {
67+
Render.setFilterMag(1);
68+
Render.pushMatrix(scale_matrix, false);
69+
Render.setRenderTargetTexture("rt");
70+
Render.drawTexturedRect(0, 0, 512, 512);
71+
});
72+
}
73+
}
74+
75+
// Supercool hidden comment that lua won't see ever

extraParams.hxml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
-D lua-vanilla
2+
# Don't try and require binary modules
3+
4+
-D lua-ver 5.1

haxelib.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name": "sfhaxe",
3+
"url" : "https://github.com/Vurv78/SFHaxe",
4+
"license": "MIT",
5+
"tags": ["lua", "garrysmod", "starfallex", "starfall", "extern"],
6+
"description": "Autogenerated bindings for StarfallEx functions for use in the Haxe lua target.",
7+
"version": "0.1.0",
8+
"classPath": "src",
9+
"releasenote": "",
10+
"contributors": ["Vurv"],
11+
"main": "",
12+
"dependencies" : {}
13+
}

sf/library/Builtins.hx

Lines changed: 0 additions & 236 deletions
This file was deleted.

0 commit comments

Comments
 (0)