Skip to content

Commit

Permalink
lua api
Browse files Browse the repository at this point in the history
  • Loading branch information
nem0 committed Sep 9, 2023
1 parent 5f41aaa commit 735a417
Show file tree
Hide file tree
Showing 3 changed files with 201 additions and 137 deletions.
70 changes: 63 additions & 7 deletions data/scripts/editor_main.lua
Original file line number Diff line number Diff line change
@@ -1,11 +1,57 @@
local tpl = [[
declare ImGui: {
AlignTextToFramePadding : () -> (),
Begin : (string) -> boolean,
End : () -> (),
Text : (string) -> (),
BeginChildFrame : (string, number, number) -> boolean,
BeginPopup : (string) -> boolean,
Button : (string) -> boolean,
CalcTextSize : (string) -> (number, number),
Checkbox : (string, boolean) -> (boolean, boolean),
CollapsingHeader : (string) -> boolean,
Columns : (number) -> (),
DragFloat : (string, number) -> (boolean, number),
DragInt : (string, number) -> (boolean, number),
Dummy : (number, number) -> (),
End : () -> (),
EndChildFrame : () -> (),
EndCombo : () -> (),
EndPopup : () -> (),
GetColumnWidth : (number) -> number,
GetDisplayWidth : () -> number,
GetDisplayHeight : () -> number,
GetWindowWidth : () -> (),
GetWindowHeight : () -> (),
GetWindowPos : () -> any,
Indent : (number) -> (),
InputTextMultiline : (string, string) -> (boolean, string),
IsItemHovered : () -> boolean,
IsMouseClicked : (number) -> boolean,
IsMouseDown : (number) -> boolean,
LabelText : (string, string) -> (),
NewLine : () -> (),
NextColumn : () -> (),
OpenPopup : (string) -> (),
PopItemWidth : () -> (),
PopID : () -> (),
PopStyleColor : (number) -> (),
PopStyleVar : (number) -> (),
PopItemWidth : () -> (),
PushItemWidth : (number) -> (),
PushID : (number) -> (),
PushStyleColor : (number, any) -> (),
PushStyleVar : (number, number, number) -> () | (number, number) -> () ,
Rect : (number, number, number) -> (),
SameLine : () -> (),
InputTextMultiline : (string, string) -> (boolean, string)
Selectable : (string, boolean) -> boolean | (string) -> boolean,
Separator : () -> (),
SetCursorScreenPos : (number, number) -> (),
SetNextWindowPos : (number, number) -> (),
SetNextWindowPosCenter : () -> (),
SetNextWindowSize : (number, number) -> (),
SetStyleColor : (number, any) -> (),
SliderFloat : (string, number, number, number) -> (boolean, number),
Text : (string) -> (),
Unindent : (number) -> (),
}
declare class World
Expand Down Expand Up @@ -67,6 +113,8 @@ declare LumixReflection: {
getFunction : (ComponentBase, number) -> FunctionBase,
getFunctionName : (FunctionBase) -> string,
getFunctionArgCount : (FunctionBase) -> number,
getFunctionArgType : (FunctionBase, number) -> string,
getFunctionReturnType : (FunctionBase) -> string,
getPropertyType : (PropertyBase) -> number,
getPropertyName : (PropertyBase) -> string
}
Expand Down Expand Up @@ -99,7 +147,7 @@ type ButtonInputEvent = {
export type InputEvent = ButtonInputEvent | AxisInputEvent
]]
if true then
if false then
function typeToString(type : number) : string
if type < 3 then return "number" end
if type == 3 then return "Entity" end
Expand All @@ -114,6 +162,13 @@ if true then
return string.lower(s)
end

function toLuaType(ctype : string)
if ctype == "float" then return "number" end
if ctype == "bool" then return "boolean" end
if ctype == "void" then return "()" end
return "any"
end

function refl()
local num_cmp = LumixReflection.getNumComponents()
local out = ""
Expand All @@ -128,19 +183,20 @@ if true then
local prop = LumixReflection.getProperty(cmp, j - 1)
local prop_name = LumixReflection.getPropertyName(prop)
local prop_type = LumixReflection.getPropertyType(prop)
if prop_name:match("3.*") then continue end
if prop_name:match("[0-9].*") then continue end
out = out .. "\t" .. toLuaIdentifier(prop_name) .. ": " .. typeToString(prop_type) .. "\n"
end
local num_funcs = LumixReflection.getNumFunctions(cmp)
for j = 1, num_funcs do
local func = LumixReflection.getFunction(cmp, j - 1)
local func_name = LumixReflection.getFunctionName(func)
local arg_count = LumixReflection.getFunctionArgCount(func)
local ret_type = LumixReflection.getFunctionReturnType(func)
out = out .. `\t{func_name} : ({name}`
for i = 2, arg_count do
out = out .. ", any"
out = out .. ", " .. toLuaType(LumixReflection.getFunctionArgType(func, i - 1))
end
out = out .. ") -> any\n"
out = out .. `) -> {toLuaType(ret_type)}\n`
end
out = out .. "end\n\n"
end
Expand Down
111 changes: 77 additions & 34 deletions data/scripts/lumix.d.lua
Original file line number Diff line number Diff line change
@@ -1,10 +1,56 @@
declare ImGui: {
AlignTextToFramePadding : () -> (),
Begin : (string) -> boolean,
End : () -> (),
Text : (string) -> (),
BeginChildFrame : (string, number, number) -> boolean,
BeginPopup : (string) -> boolean,
Button : (string) -> boolean,
CalcTextSize : (string) -> (number, number),
Checkbox : (string, boolean) -> (boolean, boolean),
CollapsingHeader : (string) -> boolean,
Columns : (number) -> (),
DragFloat : (string, number) -> (boolean, number),
DragInt : (string, number) -> (boolean, number),
Dummy : (number, number) -> (),
End : () -> (),
EndChildFrame : () -> (),
EndCombo : () -> (),
EndPopup : () -> (),
GetColumnWidth : (number) -> number,
GetDisplayWidth : () -> number,
GetDisplayHeight : () -> number,
GetWindowWidth : () -> (),
GetWindowHeight : () -> (),
GetWindowPos : () -> any,
Indent : (number) -> (),
InputTextMultiline : (string, string) -> (boolean, string),
IsItemHovered : () -> boolean,
IsMouseClicked : (number) -> boolean,
IsMouseDown : (number) -> boolean,
LabelText : (string, string) -> (),
NewLine : () -> (),
NextColumn : () -> (),
OpenPopup : (string) -> (),
PopItemWidth : () -> (),
PopID : () -> (),
PopStyleColor : (number) -> (),
PopStyleVar : (number) -> (),
PopItemWidth : () -> (),
PushItemWidth : (number) -> (),
PushID : (number) -> (),
PushStyleColor : (number, any) -> (),
PushStyleVar : (number, number, number) -> () | (number, number) -> () ,
Rect : (number, number, number) -> (),
SameLine : () -> (),
InputTextMultiline : (string, string) -> (boolean, string)
Selectable : (string, boolean) -> boolean | (string) -> boolean,
Separator : () -> (),
SetCursorScreenPos : (number, number) -> (),
SetNextWindowPos : (number, number) -> (),
SetNextWindowPosCenter : () -> (),
SetNextWindowSize : (number, number) -> (),
SetStyleColor : (number, any) -> (),
SliderFloat : (string, number, number, number) -> (boolean, number),
Text : (string) -> (),
Unindent : (number) -> (),
}

declare class World
Expand Down Expand Up @@ -47,8 +93,8 @@ declare class terrain
tesselation: number
grid_resolution: number
grass: any
getTerrainNormalAt : (terrain, any, any) -> any
getTerrainHeightAt : (terrain, any, any) -> any
getTerrainNormalAt : (terrain, number, number) -> any
getTerrainHeightAt : (terrain, number, number) -> number
end

declare class camera
Expand All @@ -69,8 +115,6 @@ declare class curve_decal
material: string
half_extents: number
uv_scale: any
bezier_p0: any
bezier_p2: any
end

declare class point_light
Expand Down Expand Up @@ -141,12 +185,12 @@ declare class rigid_actor
sphere_geometry: any
mesh: string
material: string
putToSleep : (rigid_actor) -> any
getSpeed : (rigid_actor) -> any
putToSleep : (rigid_actor) -> ()
getSpeed : (rigid_actor) -> number
getVelocity : (rigid_actor) -> any
applyForce : (rigid_actor, any) -> any
applyImpulse : (rigid_actor, any) -> any
addForceAtPos : (rigid_actor, any, any) -> any
applyForce : (rigid_actor, any) -> ()
applyImpulse : (rigid_actor, any) -> ()
addForceAtPos : (rigid_actor, any, any) -> ()
end

declare class physical_heightfield
Expand All @@ -163,9 +207,9 @@ declare class physical_controller
use_root_motion: boolean
use_custom_gravity: boolean
custom_gravity_acceleration: number
move : (physical_controller, any) -> any
isCollisionDown : (physical_controller) -> any
getGravitySpeed : (physical_controller) -> any
move : (physical_controller, any) -> ()
isCollisionDown : (physical_controller) -> boolean
getGravitySpeed : (physical_controller) -> number
end

declare class js_script
Expand Down Expand Up @@ -237,8 +281,6 @@ declare class d6_joint
x_motion: number
y_motion: number
z_motion: number
swing_1: number
swing_2: number
twist: number
linear_limit: number
swing_limit: any
Expand All @@ -258,9 +300,9 @@ declare class vehicle
chassis: string
chassis_layer: number
wheels_layer: number
setAccel : (vehicle, any) -> any
setSteer : (vehicle, any) -> any
setBrake : (vehicle, any) -> any
setAccel : (vehicle, number) -> ()
setSteer : (vehicle, number) -> ()
setBrake : (vehicle, number) -> ()
end

declare class wheel
Expand All @@ -281,10 +323,10 @@ declare class navmesh_agent
height: number
move_entity: boolean
speed: number
setActive : (navmesh_agent, any) -> any
navigate : (navmesh_agent, any, any, any) -> any
cancelNavigation : (navmesh_agent) -> any
drawPath : (navmesh_agent) -> any
setActive : (navmesh_agent, boolean) -> ()
navigate : (navmesh_agent, any, number, number) -> boolean
cancelNavigation : (navmesh_agent) -> ()
drawPath : (navmesh_agent) -> ()
end

declare class navmesh_zone
Expand All @@ -297,11 +339,11 @@ declare class navmesh_zone
max_climb: number
autoload: boolean
detailed: boolean
load : (navmesh_zone) -> any
drawContours : (navmesh_zone) -> any
drawNavmesh : (navmesh_zone, any, any, any, any) -> any
drawCompactHeightfield : (navmesh_zone) -> any
drawHeightfield : (navmesh_zone) -> any
load : (navmesh_zone) -> boolean
drawContours : (navmesh_zone) -> ()
drawNavmesh : (navmesh_zone, any, boolean, boolean, boolean) -> ()
drawCompactHeightfield : (navmesh_zone) -> ()
drawHeightfield : (navmesh_zone) -> ()
generateNavmesh : (navmesh_zone) -> any
end

Expand All @@ -325,8 +367,8 @@ declare class animator
source: string
default_set: number
use_root_motion: boolean
setFloatInput : (animator, any, any) -> any
setBoolInput : (animator, any, any) -> any
setFloatInput : (animator, any, number) -> ()
setBoolInput : (animator, any, boolean) -> ()
getInputIndex : (animator, any) -> any
end

Expand All @@ -345,8 +387,8 @@ end

declare class ambient_sound
sound: string
pause : (ambient_sound) -> any
resume : (ambient_sound) -> any
pause : (ambient_sound) -> ()
resume : (ambient_sound) -> ()
end

declare class echo_zone
Expand Down Expand Up @@ -457,6 +499,8 @@ declare LumixReflection: {
getFunction : (ComponentBase, number) -> FunctionBase,
getFunctionName : (FunctionBase) -> string,
getFunctionArgCount : (FunctionBase) -> number,
getFunctionArgType : (FunctionBase, number) -> string,
getFunctionReturnType : (FunctionBase) -> string,
getPropertyType : (PropertyBase) -> number,
getPropertyName : (PropertyBase) -> string
}
Expand Down Expand Up @@ -487,4 +531,3 @@ type ButtonInputEvent = {
}

export type InputEvent = ButtonInputEvent | AxisInputEvent

Loading

0 comments on commit 735a417

Please sign in to comment.