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

Commit 0e2c878

Browse files
Vurv78Vurv78
authored andcommitted
0.2.0
CHANGELOG: * Docs are properly indented with tabs now. * Added a standard library and support for Haxe's Sys library. * Added CLIENT, SERVER and SHARED defines to make a chip target those and output the respective SF code (eg ``--@client``) * Added replacement functions for _hx_error and _hx_tostring since they are really bad.. (Currently don't know how to get rid of the original functions) * Functions are now separated by realm using compilation time definitions. (For example you won't see any wire functions if you only define CLIENT )
1 parent fa67bc8 commit 0e2c878

72 files changed

Lines changed: 1962 additions & 1679 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: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# SFHaxe
22
Proof of concept [Haxe](https://haxe.org) Library for the lua target that adds [StarfallEx](https://github.com/thegrb93/StarfallEx) bindings.
3-
This was autogenerated by a lua script I made.
3+
The bindings are autogenerated by a Haxe script made using SFHaxe.
44
If you want Haxe bindings for GLua to make addons instead of Starfall scripts, check out [gmodhaxe](https://github.com/ponobodod/gmodhaxe).
55

66
Hopefully will have the script in this repo as well, made in Haxe.
7-
https://lib.haxe.org/p/sfhaxe/0.1.0
7+
https://lib.haxe.org/p/sfhaxe
88

99
## What is haxe?
1010
See [what is haxe?](https://haxe.org/manual/introduction-what-is-haxe.html), a [code sample](https://try.haxe.org/embed/44ddE#code1) and [the power of haxe](#The-Power-of-Haxe)
@@ -24,9 +24,32 @@ See [what is haxe?](https://haxe.org/manual/introduction-what-is-haxe.html), a [
2424
## How to use:
2525
Look at the examples/Basic Full directory for a full example.
2626
First, download sfhaxe through haxelib by putting this in your command line.
27+
```hxml
28+
haxelib install sfhaxe
29+
```
2730
``haxelib install sfhaxe``
31+
2832
Make a haxe project, and in your ``build.hxml`` file put this:
29-
``-lib sfhaxe``
33+
```hxml
34+
# Optional, but I recommend this to make your project smaller. (Deletes any unused code from the final compiled result)
35+
-dce full
36+
37+
# Link to sfhaxe with the -lib command.
38+
--library sfhaxe
39+
40+
# Either you can define a single one of these, both of them, or SHARED depending on what you want the chip to be targeted for.
41+
--define SERVER
42+
--define CLIENT
43+
44+
# Set the haxe path to the current directory of the hxml + /src/
45+
-p src
46+
47+
# Tell the compiler to generate lua code at this directory.
48+
--lua bin/sfstuff.lua
49+
50+
# Set the main class to compile from. In this case, you have a file called Main.hx in /src/ that creates class Main.
51+
-main Main
52+
```
3053

3154
## What would you use this for?
3255
* If you wanted to have typed, neater code with all of the features that Haxe brings. See [The Power of Haxe](#The-Power-of-Haxe)

build.hxml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
--class-path src

extraParams.hxml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
-D lua-vanilla
22
# Don't try and require binary modules
33

4-
-D lua-ver 5.1
4+
-D lua-ver 5.1
5+
--macro sf.macros.Init.run()

haxelib.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
"name": "sfhaxe",
33
"url" : "https://github.com/Vurv78/SFHaxe",
44
"license": "MIT",
5-
"tags": ["lua", "garrysmod", "starfallex", "starfall", "extern"],
5+
"tags": ["lua", "garrysmod", "starfallex", "starfall", "extern", "gmod"],
66
"description": "Autogenerated bindings for StarfallEx functions for use in the Haxe lua target.",
7-
"version": "0.1.1",
7+
"version": "0.2.0",
88
"classPath": "src",
9-
"releasenote": "Added most metamethods / operator overloads. Still buggy with Haxe's type inferrence.",
9+
"releasenote": "Generator has been rewritten as SFHaxe code and released. Added a standard library, ability to define whether a chip is SERVER, CLIENT or SHARED. (Shared default). Also added Sys library, so you can Sys.print now and it will do the same as sf.library.Builtins.print.",
1010
"contributors": ["Vurv"],
11-
"main": "",
11+
"main": "sf.Run",
1212
"dependencies" : {}
1313
}

src/Sys.hx

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
2+
@:coreApi
3+
class Sys {
4+
/**
5+
SHARED
6+
Internally calls Builtins.print.
7+
**/
8+
public static inline function print(v:Dynamic):Void
9+
sf.library.Builtins.print(v);
10+
11+
/**
12+
SHARED
13+
Internally calls Builtins.print with a newline after
14+
**/
15+
public static inline function println(v:Dynamic):Void
16+
sf.library.Builtins.print('$v\n');
17+
18+
/**
19+
Simply returns "SF" since Starfall has no concept of OS.
20+
There's no reason to use this
21+
**/
22+
public static inline function systemName():String
23+
return "SF";
24+
25+
/**
26+
Returns an empty array, this isn't supported.
27+
**/
28+
public static inline function args():Array<String>
29+
return [];
30+
31+
// Can't just get an env variable from an SF chip.
32+
public static inline function getEnv(s:String):String
33+
return "";
34+
35+
public static inline function putEnv(s:String, v:String):Void {}
36+
37+
public static function environment():Map<String, String> {
38+
return new Map<String,String>();
39+
}
40+
41+
/**
42+
Always returns false as setting the time isn't supported.
43+
**/
44+
public inline static function setTimeLocale(loc:String):Bool
45+
return false;
46+
47+
/**
48+
SHARED
49+
Returns the same thing as doing debugGetInfo(1,"S").short_src.
50+
**/
51+
public inline static function getCwd():String {
52+
return untyped {
53+
sf.library.Builtins.debugGetInfo(1, "S").short_src;
54+
}
55+
}
56+
57+
/**
58+
Does nothing.
59+
**/
60+
public static inline function setCwd(s:String):Void {}
61+
62+
/**
63+
SHARED
64+
Does nothing. Returns Access denied error code.
65+
https://www.tutorialspoint.com/batch_script/batch_script_return_code.htm
66+
**/
67+
public static inline function command(cmd:String, ?args:Array<String>):Int {
68+
return 5;
69+
}
70+
71+
/**
72+
SHARED
73+
Just errors the chip with the message 'exit' at stack level 0.
74+
**/
75+
public static inline function exit(code:Int):Void {
76+
sf.library.Builtins.error("exit", 0);
77+
}
78+
79+
/**
80+
SHARED
81+
Returns the same thing as using Timer.systime()
82+
**/
83+
public static inline function time():Float
84+
return sf.library.Timer.systime();
85+
86+
/**
87+
SHARED
88+
Returns the same result as calling quotaTotalUsed()
89+
**/
90+
public static inline function cpuTime():Float {
91+
return sf.library.Builtins.quotaTotalUsed();
92+
}
93+
94+
/**
95+
SHARED
96+
Returns the same result as getCwd, which just returns the debugGetInfo short_src of stack level 1.
97+
**/
98+
public static inline function executablePath():String {
99+
return getCwd();
100+
}
101+
102+
/**
103+
SHARED
104+
Does the same thing as Sys.executablePath().
105+
**/
106+
public static inline function programPath():String {
107+
return executablePath();
108+
}
109+
110+
/**
111+
Don't use this. There is no std interface for starfall.
112+
**/
113+
public static function getChar(echo: Bool):Int {
114+
return throw "No stdin in SF";
115+
}
116+
117+
/**
118+
SHARED
119+
Just calls Coroutine.yield.
120+
Starfall doesn't run in a coroutine by default so make sure you're in a coroutine.
121+
**/
122+
public static function sleep(seconds: Float):Void {
123+
sf.library.Coroutine.yield();
124+
}
125+
126+
/**
127+
Don't use this. There is no std interface for starfall.
128+
**/
129+
public static inline function stdin():haxe.io.Input {
130+
return throw "No stdio in SF";
131+
}
132+
133+
/**
134+
Don't use this. There is no std interface for starfall.
135+
**/
136+
public static inline function stdout():haxe.io.Output {
137+
return throw "No stdio in SF";
138+
}
139+
140+
/**
141+
Don't use this. There is no std interface for starfall.
142+
**/
143+
public static inline function stderr():haxe.io.Output {
144+
return throw "No stdio in SF";
145+
}
146+
}

src/sf/Lib.hx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package sf;
2+
3+
// Main library for SFHaxe
4+
class Lib {
5+
// Todo
6+
}

src/sf/library/Bass.hx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
1+
// Generated by SFHaxe 0.2.0
12
package sf.library;
23
@:native("bass") extern class Bass {
34
/**
45
CLIENT
56
Loads a sound channel from an URL.
67
**/
7-
@:native("loadURL") public static function loadURL(path:Any,flags:Any,callback:Any):Void;
8+
#if CLIENT @:native("loadURL") public static function loadURL(path:Any, flags:Any, callback:Any):Void;#end
89
/**
910
CLIENT
1011
Loads a sound channel from a file.
1112
**/
12-
@:native("loadFile") public static function loadFile(path:Any,flags:Any,callback:Any):Void;
13+
#if CLIENT @:native("loadFile") public static function loadFile(path:Any, flags:Any, callback:Any):Void;#end
1314
/**
1415
CLIENT
1516
Returns the number of sounds left that can be created
1617
**/
17-
@:native("soundsLeft") public static function soundsLeft():Any;
18+
#if CLIENT @:native("soundsLeft") public static function soundsLeft():Any;#end
1819
}
1920

src/sf/library/Bit.hx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Generated by SFHaxe 0.2.0
12
package sf.library;
23
@:native("bit") extern class Bit {
34
/**
@@ -9,7 +10,7 @@ package sf.library;
910
SHARED
1011
1112
**/
12-
@:native("ror") public static function ror():Void;
13+
@:native("arshift") public static function arshift():Void;
1314
/**
1415
SHARED
1516
Compresses a string
@@ -27,9 +28,9 @@ package sf.library;
2728
@:native("lshift") public static function lshift():Void;
2829
/**
2930
SHARED
30-
31+
Creates a StringStream object
3132
**/
32-
@:native("tohex") public static function tohex():Void;
33+
@:native("stringstream") public static function stringstream(stream:Any, i:Any, endian:Any):Void;
3334
/**
3435
SHARED
3536
Converts serialized string data to table
@@ -59,7 +60,7 @@ package sf.library;
5960
SHARED
6061
6162
**/
62-
@:native("arshift") public static function arshift():Void;
63+
@:native("ror") public static function ror():Void;
6364
/**
6465
SHARED
6566
@@ -72,9 +73,9 @@ package sf.library;
7273
@:native("tobit") public static function tobit():Void;
7374
/**
7475
SHARED
75-
Creates a StringStream object
76+
7677
**/
77-
@:native("stringstream") public static function stringstream(stream:Any,i:Any,endian:Any):Void;
78+
@:native("tohex") public static function tohex():Void;
7879
/**
7980
SHARED
8081
Decompresses a string

0 commit comments

Comments
 (0)