luau types WIP

This commit is contained in:
Mikulas Florek 2023-09-12 23:12:00 +02:00
parent ac171e3e9e
commit af254f0c85
12 changed files with 353 additions and 217 deletions

View File

@ -115,23 +115,34 @@ end
declare class FunctionBase
end
declare class ModuleReflection
end
declare LumixReflection: {
getComponent : (number) -> ComponentBase,
getComponentName : (ComponentBase) -> string,
getNumComponents : () -> number,
getNumProperties : (ComponentBase) -> number,
getNumFunctions : (ComponentBase) -> number,
getNumComponentFunctions : (ComponentBase) -> number,
getProperty : (ComponentBase, number) -> PropertyBase,
getFunction : (ComponentBase, number) -> FunctionBase,
getComponentFunction : (ComponentBase, number) -> FunctionBase,
getFunctionName : (FunctionBase) -> string,
getFunctionArgCount : (FunctionBase) -> number,
getFunctionArgType : (FunctionBase, number) -> string,
getFunctionReturnType : (FunctionBase) -> string,
getPropertyType : (PropertyBase) -> number,
getPropertyName : (PropertyBase) -> string
getPropertyName : (PropertyBase) -> string,
getFirstModule : () -> ModuleReflection,
getNextModule : (ModuleReflection) -> ModuleReflection?,
getNumModuleFunctions : (ModuleReflection) -> number,
getModuleFunction : (ModuleReflection, number) -> FunctionBase,
getModuleName : (ModuleReflection) -> string,
getNumFunctions : () -> number,
getFunction : (number) -> FunctionBase,
getThisTypeName : (FunctionBase) -> string,
getReturnTypeName : (FunctionBase) -> string,
}
type InputDevice = {
type : "mouse" | "keyboard",
index : number
@ -174,22 +185,79 @@ export type InputEvent = ButtonInputEvent | AxisInputEvent
end
function toLuaType(ctype : string)
LumixAPI.logError(ctype)
if ctype == "int" then return "number" end
if ctype == "char const *" then return "string" end
if ctype == "i32" then return "number" end
if ctype == "u32" then return "number" end
if ctype == "float" then return "number" end
if ctype == "bool" then return "boolean" end
if ctype == "void" then return "()" end
return "any"
end
function writeFuncDecl(code : string, self_type : string, func : FunctionBase)
local func_name = LumixReflection.getFunctionName(func)
local arg_count = LumixReflection.getFunctionArgCount(func)
local ret_type = LumixReflection.getFunctionReturnType(func)
code = code .. `\t{func_name} : ({self_type}`
for i = 2, arg_count do
code = code .. ", " .. toLuaType(LumixReflection.getFunctionArgType(func, i - 1))
end
code = code .. `) -> {toLuaType(ret_type)}\n`
return code
end
function toLuaTypeName(name : string)
local t = name:match(".*::(%w*)")
if t:len() == 0 then return name end
return t
end
function refl()
local num_cmp = LumixReflection.getNumComponents()
local out = ""
local num_funcs = LumixReflection.getNumFunctions()
local objs = {}
for i = 1, num_funcs do
local fn = LumixReflection.getFunction(i - 1)
local this_type_name = toLuaTypeName(LumixReflection.getThisTypeName(fn))
if objs[this_type_name] == nil then
objs[this_type_name] = {}
end
table.insert(objs[this_type_name], fn)
--local func_name = LumixReflection.getFunctionName(fn)
--out = out .. `--{this_type_name} :: {func_name}\n`
end
for k, t in pairs(objs) do
out = out .. `declare class {k}\n`
for _, fn in ipairs(t) do
out = writeFuncDecl(out, k, fn)
end
out = out .. `end\n\n`
end
local module = LumixReflection.getFirstModule()
while module ~= nil do
local module_name = LumixReflection.getModuleName(module)
out = out .. `declare class {module_name}_module\n`
local num_fn = LumixReflection.getNumModuleFunctions(module)
for i = 1, num_fn do
local fn = LumixReflection.getModuleFunction(module, i - 1)
out = writeFuncDecl(out, module_name .. "_module", fn)
end
out = out .. "end\n\n"
module = LumixReflection.getNextModule(module)
end
local num_cmp = LumixReflection.getNumComponents()
local entity_src = ""
for i = 1, num_cmp do
local cmp = LumixReflection.getComponent(i - 1)
local name = LumixReflection.getComponentName(cmp)
local num_props = LumixReflection.getNumProperties(cmp)
out = out .. "declare class " .. name .. "\n"
entity_src = entity_src .. `\t{name}: {name}\n`
out = out .. `declare class {name}_component\n`
entity_src = entity_src .. `\t{name}: {name}_component\n`
for j = 1, num_props do
local prop = LumixReflection.getProperty(cmp, j - 1)
local prop_name = LumixReflection.getPropertyName(prop)
@ -197,17 +265,10 @@ export type InputEvent = ButtonInputEvent | AxisInputEvent
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 .. ", " .. toLuaType(LumixReflection.getFunctionArgType(func, i - 1))
end
out = out .. `) -> {toLuaType(ret_type)}\n`
local num_cmp_funcs = LumixReflection.getNumComponentFunctions(cmp)
for j = 1, num_cmp_funcs do
local func = LumixReflection.getComponentFunction(cmp, j - 1)
out = writeFuncDecl(out, name .. "_component", func)
end
out = out .. "end\n\n"
end
@ -217,12 +278,12 @@ export type InputEvent = ButtonInputEvent | AxisInputEvent
local type_defs = refl()
if false then
if true then
return {
name = "Lua type defs",
gui = function()
if ImGui.Begin("Lua type definitions") then
ImGui.InputTextMultiline("Types", type_defs)
ImGui.InputTextMultiline("##code", type_defs)
end
ImGui.End()
end

View File

@ -7,7 +7,7 @@ declare ImGui: {
CalcTextSize : (string) -> (number, number),
Checkbox : (string, boolean) -> (boolean, boolean),
CloseCurrentPopup : () -> (),
CollapsingHeader : (string) -> boolean,
CollapsingHeader : (string) -> boolean,
Columns : (number) -> (),
DragFloat : (string, number) -> (boolean, number),
DragInt : (string, number) -> (boolean, number),
@ -19,15 +19,15 @@ declare ImGui: {
GetColumnWidth : (number) -> number,
GetDisplayWidth : () -> number,
GetDisplayHeight : () -> number,
GetOsImePosRequest : () -> (number, number),
GetOsImePosRequest : () -> (number, number),
GetWindowWidth : () -> (),
GetWindowHeight : () -> (),
GetWindowPos : () -> any,
Indent : (number) -> (),
InputTextMultiline : (string, string) -> (boolean, string?),
InputTextMultilineWithCallback : (string, string, (string, number, boolean) -> ()) -> (boolean, string?),
IsItemHovered : () -> boolean,
IsKeyPressed : (number, boolean) -> boolean,
IsItemHovered : () -> boolean,
IsKeyPressed : (number, boolean) -> boolean,
IsMouseClicked : (number) -> boolean,
IsMouseDown : (number) -> boolean,
LabelText : (string, string) -> (),
@ -49,7 +49,7 @@ declare ImGui: {
Separator : () -> (),
SetCursorScreenPos : (number, number) -> (),
SetKeyboardFocusHere : (number) -> (),
SetNextWindowPos : (number, number) -> (),
SetNextWindowPos : (number, number) -> (),
SetNextWindowPosCenter : () -> (),
SetNextWindowSize : (number, number) -> (),
SetStyleColor : (number, any) -> (),
@ -70,10 +70,59 @@ declare class World
load : (World, string, any) -> ()
end
declare class spline
declare class GUISystem
enableCursor : (GUISystem) -> ()
end
declare class gui_rect
declare class Model
getBoneCount : (Model) -> number
getBoneName : (Model) -> string
getBoneParent : (Model) -> number
end
declare class core_module
end
declare class navigation_module
end
declare class animation_module
end
declare class gui_module
getRectAt : (gui_module) -> any
isOver : (gui_module, any) -> boolean
getSystem : (gui_module) -> any
end
declare class lua_script_module
end
declare class audio_module
setMasterVolume : (audio_module) -> ()
play : (audio_module, any, boolean) -> number
stop : (audio_module) -> ()
isEnd : (audio_module) -> boolean
setFrequency : (audio_module, number) -> ()
setVolume : (audio_module, number) -> ()
setEcho : (audio_module, number, number, number, number) -> ()
end
declare class renderer_module
addDebugCross : (renderer_module, number, any) -> ()
addDebugLine : (renderer_module, any, any) -> ()
addDebugTriangle : (renderer_module, any, any, any) -> ()
setActiveCamera : (renderer_module) -> ()
end
declare class physics_module
raycast : (physics_module, any, any) -> any
end
declare class spline_component
end
declare class gui_rect_component
enabled: boolean
clip_content: boolean
top_points: number
@ -86,28 +135,28 @@ declare class gui_rect
left_relative: number
end
declare class gui_canvas
declare class gui_canvas_component
orient_to_camera: boolean
virtual_size: any
end
declare class particle_emitter
declare class particle_emitter_component
autodestroy: boolean
source: string
end
declare class terrain
declare class terrain_component
material: string
xz_scale: number
height_scale: number
tesselation: number
grid_resolution: number
grass: any
getTerrainNormalAt : (terrain, number, number) -> any
getTerrainHeightAt : (terrain, number, number) -> number
getTerrainNormalAt : (terrain_component, number, number) -> any
getTerrainHeightAt : (terrain_component, number, number) -> number
end
declare class camera
declare class camera_component
fov: number
near: number
far: number
@ -115,19 +164,19 @@ declare class camera
orthographic_size: number
end
declare class decal
declare class decal_component
material: string
half_extents: any
uv_scale: any
end
declare class curve_decal
declare class curve_decal_component
material: string
half_extents: number
uv_scale: any
end
declare class point_light
declare class point_light_component
cast_shadows: boolean
dynamic: boolean
intensity: number
@ -137,7 +186,7 @@ declare class point_light
range: number
end
declare class environment
declare class environment_component
color: any
intensity: number
indirect_intensity: number
@ -145,49 +194,49 @@ declare class environment
cast_shadows: boolean
end
declare class instanced_model
declare class instanced_model_component
model: string
blob: any
end
declare class model_instance
declare class model_instance_component
enabled: boolean
material: string
source: string
getModel : (model_instance) -> any
getModel : (model_instance_component) -> any
end
declare class environment_probe
declare class environment_probe_component
enabled: boolean
inner_range: any
outer_range: any
end
declare class reflection_probe
declare class reflection_probe_component
enabled: boolean
size: number
half_extents: any
end
declare class fur
declare class fur_component
layers: number
scale: number
gravity: number
enabled: boolean
end
declare class procedural_geom
declare class procedural_geom_component
material: string
end
declare class bone_attachment
declare class bone_attachment_component
parent: Entity
relative_position: any
relative_rotation: any
bone: number
end
declare class rigid_actor
declare class rigid_actor_component
layer: number
dynamic: number
trigger: boolean
@ -195,48 +244,44 @@ declare class rigid_actor
sphere_geometry: any
mesh: string
material: string
putToSleep : (rigid_actor) -> ()
getSpeed : (rigid_actor) -> number
getVelocity : (rigid_actor) -> any
applyForce : (rigid_actor, any) -> ()
applyImpulse : (rigid_actor, any) -> ()
addForceAtPos : (rigid_actor, any, any) -> ()
putToSleep : (rigid_actor_component) -> ()
getSpeed : (rigid_actor_component) -> number
getVelocity : (rigid_actor_component) -> any
applyForce : (rigid_actor_component, any) -> ()
applyImpulse : (rigid_actor_component, any) -> ()
addForceAtPos : (rigid_actor_component, any, any) -> ()
end
declare class physical_heightfield
declare class physical_heightfield_component
layer: number
heightmap: string
y_scale: number
xz_scale: number
end
declare class physical_controller
declare class physical_controller_component
radius: number
height: number
layer: number
use_root_motion: boolean
use_custom_gravity: boolean
custom_gravity_acceleration: number
move : (physical_controller, any) -> ()
isCollisionDown : (physical_controller) -> boolean
getGravitySpeed : (physical_controller) -> number
move : (physical_controller_component, any) -> ()
isCollisionDown : (physical_controller_component) -> boolean
getGravitySpeed : (physical_controller_component) -> number
end
declare class js_script
declare class lua_script_component
scripts: any
end
declare class lua_script
scripts: any
end
declare class gui_image
declare class gui_image_component
enabled: boolean
color: any
sprite: string
end
declare class gui_text
declare class gui_text_component
text: string
font: string
font_size: number
@ -245,19 +290,19 @@ declare class gui_text
color: any
end
declare class gui_button
declare class gui_button_component
hovered_color: any
cursor: number
end
declare class gui_render_target
declare class gui_render_target_component
end
declare class animable
declare class animable_component
animation: string
end
declare class distance_joint
declare class distance_joint_component
connected_body: Entity
axis_position: any
damping: number
@ -266,7 +311,7 @@ declare class distance_joint
limits: any
end
declare class hinge_joint
declare class hinge_joint_component
connected_body: Entity
axis_position: any
axis_direction: any
@ -276,7 +321,7 @@ declare class hinge_joint
limit: any
end
declare class spherical_joint
declare class spherical_joint_component
connected_body: Entity
axis_position: any
axis_direction: any
@ -284,7 +329,7 @@ declare class spherical_joint
limit: any
end
declare class d6_joint
declare class d6_joint_component
connected_body: Entity
axis_position: any
axis_direction: any
@ -300,7 +345,7 @@ declare class d6_joint
restitution: number
end
declare class vehicle
declare class vehicle_component
speed: number
current_gear: number
rpm: number
@ -310,12 +355,12 @@ declare class vehicle
chassis: string
chassis_layer: number
wheels_layer: number
setAccel : (vehicle, number) -> ()
setSteer : (vehicle, number) -> ()
setBrake : (vehicle, number) -> ()
setAccel : (vehicle_component, number) -> ()
setSteer : (vehicle_component, number) -> ()
setBrake : (vehicle_component, number) -> ()
end
declare class wheel
declare class wheel_component
radius: number
width: number
mass: number
@ -328,18 +373,18 @@ declare class wheel
rpm: number
end
declare class navmesh_agent
declare class navmesh_agent_component
radius: number
height: number
move_entity: boolean
speed: number
setActive : (navmesh_agent, boolean) -> ()
navigate : (navmesh_agent, any, number, number) -> boolean
cancelNavigation : (navmesh_agent) -> ()
drawPath : (navmesh_agent) -> ()
setActive : (navmesh_agent_component, boolean) -> ()
navigate : (navmesh_agent_component, any, number, number) -> boolean
cancelNavigation : (navmesh_agent_component) -> ()
drawPath : (navmesh_agent_component) -> ()
end
declare class navmesh_zone
declare class navmesh_zone_component
extents: any
agent_height: number
agent_radius: number
@ -349,64 +394,60 @@ declare class navmesh_zone
max_climb: number
autoload: boolean
detailed: boolean
load : (navmesh_zone) -> boolean
drawContours : (navmesh_zone) -> ()
drawNavmesh : (navmesh_zone, any, boolean, boolean, boolean) -> ()
drawCompactHeightfield : (navmesh_zone) -> ()
drawHeightfield : (navmesh_zone) -> ()
generateNavmesh : (navmesh_zone) -> any
load : (navmesh_zone_component) -> boolean
drawContours : (navmesh_zone_component) -> ()
drawNavmesh : (navmesh_zone_component, any, boolean, boolean, boolean) -> ()
drawCompactHeightfield : (navmesh_zone_component) -> ()
drawHeightfield : (navmesh_zone_component) -> ()
generateNavmesh : (navmesh_zone_component) -> any
end
declare class script
script: string
end
declare class lua_script_inline
declare class lua_script_inline_component
code: string
end
declare class gui_input_field
declare class gui_input_field_component
end
declare class property_animator
declare class property_animator_component
animation: string
enabled: boolean
end
declare class animator
declare class animator_component
source: string
default_set: number
use_root_motion: boolean
setFloatInput : (animator, any, number) -> ()
setBoolInput : (animator, any, boolean) -> ()
getInputIndex : (animator, any) -> any
setFloatInput : (animator_component, number, number) -> ()
setBoolInput : (animator_component, number, boolean) -> ()
getInputIndex : (animator_component, any) -> number
end
declare class physical_instanced_cube
declare class physical_instanced_cube_component
half_extents: any
layer: number
end
declare class physical_instanced_mesh
declare class physical_instanced_mesh_component
mesh: string
layer: number
end
declare class audio_listener
declare class audio_listener_component
end
declare class ambient_sound
declare class ambient_sound_component
sound: string
pause : (ambient_sound) -> ()
resume : (ambient_sound) -> ()
pause : (ambient_sound_component) -> ()
resume : (ambient_sound_component) -> ()
end
declare class echo_zone
declare class echo_zone_component
radius: number
delay__ms_: number
end
declare class chorus_zone
declare class chorus_zone_component
radius: number
delay__ms_: number
end
@ -424,52 +465,50 @@ declare class Entity
getComponent : (Entity, any) -> any
destroy : (Entity) -> ()
createComponent : (Entity, any) -> any
spline: spline
gui_rect: gui_rect
gui_canvas: gui_canvas
particle_emitter: particle_emitter
terrain: terrain
camera: camera
decal: decal
curve_decal: curve_decal
point_light: point_light
environment: environment
instanced_model: instanced_model
model_instance: model_instance
environment_probe: environment_probe
reflection_probe: reflection_probe
fur: fur
procedural_geom: procedural_geom
bone_attachment: bone_attachment
rigid_actor: rigid_actor
physical_heightfield: physical_heightfield
physical_controller: physical_controller
js_script: js_script
lua_script: lua_script
gui_image: gui_image
gui_text: gui_text
gui_button: gui_button
gui_render_target: gui_render_target
animable: animable
distance_joint: distance_joint
hinge_joint: hinge_joint
spherical_joint: spherical_joint
d6_joint: d6_joint
vehicle: vehicle
wheel: wheel
navmesh_agent: navmesh_agent
navmesh_zone: navmesh_zone
script: script
lua_script_inline: lua_script_inline
gui_input_field: gui_input_field
property_animator: property_animator
animator: animator
physical_instanced_cube: physical_instanced_cube
physical_instanced_mesh: physical_instanced_mesh
audio_listener: audio_listener
ambient_sound: ambient_sound
echo_zone: echo_zone
chorus_zone: chorus_zone
spline: spline_component
gui_rect: gui_rect_component
gui_canvas: gui_canvas_component
particle_emitter: particle_emitter_component
terrain: terrain_component
camera: camera_component
decal: decal_component
curve_decal: curve_decal_component
point_light: point_light_component
environment: environment_component
instanced_model: instanced_model_component
model_instance: model_instance_component
environment_probe: environment_probe_component
reflection_probe: reflection_probe_component
fur: fur_component
procedural_geom: procedural_geom_component
bone_attachment: bone_attachment_component
rigid_actor: rigid_actor_component
physical_heightfield: physical_heightfield_component
physical_controller: physical_controller_component
lua_script: lua_script_component
gui_image: gui_image_component
gui_text: gui_text_component
gui_button: gui_button_component
gui_render_target: gui_render_target_component
animable: animable_component
distance_joint: distance_joint_component
hinge_joint: hinge_joint_component
spherical_joint: spherical_joint_component
d6_joint: d6_joint_component
vehicle: vehicle_component
wheel: wheel_component
navmesh_agent: navmesh_agent_component
navmesh_zone: navmesh_zone_component
lua_script_inline: lua_script_inline_component
gui_input_field: gui_input_field_component
property_animator: property_animator_component
animator: animator_component
physical_instanced_cube: physical_instanced_cube_component
physical_instanced_mesh: physical_instanced_mesh_component
audio_listener: audio_listener_component
ambient_sound: ambient_sound_component
echo_zone: echo_zone_component
chorus_zone: chorus_zone_component
end
@ -501,23 +540,34 @@ end
declare class FunctionBase
end
declare class ModuleReflection
end
declare LumixReflection: {
getComponent : (number) -> ComponentBase,
getComponentName : (ComponentBase) -> string,
getNumComponents : () -> number,
getNumProperties : (ComponentBase) -> number,
getNumFunctions : (ComponentBase) -> number,
getNumComponentFunctions : (ComponentBase) -> number,
getProperty : (ComponentBase, number) -> PropertyBase,
getFunction : (ComponentBase, number) -> FunctionBase,
getComponentFunction : (ComponentBase, number) -> FunctionBase,
getFunctionName : (FunctionBase) -> string,
getFunctionArgCount : (FunctionBase) -> number,
getFunctionArgType : (FunctionBase, number) -> string,
getFunctionReturnType : (FunctionBase) -> string,
getPropertyType : (PropertyBase) -> number,
getPropertyName : (PropertyBase) -> string
getPropertyName : (PropertyBase) -> string,
getFirstModule : () -> ModuleReflection,
getNextModule : (ModuleReflection) -> ModuleReflection?,
getNumModuleFunctions : (ModuleReflection) -> number,
getModuleFunction : (ModuleReflection, number) -> FunctionBase,
getModuleName : (ModuleReflection) -> string,
getNumFunctions : () -> number,
getFunction : (number) -> FunctionBase,
getThisTypeName : (FunctionBase) -> string,
getReturnTypeName : (FunctionBase) -> string,
}
type InputDevice = {
type : "mouse" | "keyboard",
index : number
@ -543,3 +593,4 @@ type ButtonInputEvent = {
}
export type InputEvent = ButtonInputEvent | AxisInputEvent

View File

@ -500,13 +500,13 @@ UniquePtr<AudioModule> AudioModule::createInstance(AudioSystem& system,
void AudioModule::reflect(Engine& engine) {
LUMIX_MODULE(AudioModuleImpl, "audio")
.LUMIX_FUNC(AudioModule::setMasterVolume)
.LUMIX_FUNC(setMasterVolume)
.function<(SoundHandle (AudioModule::*)(EntityRef, const Path&, bool))&AudioModule::play>("play", "AudioModule::play")
.LUMIX_FUNC(AudioModule::stop)
.LUMIX_FUNC(AudioModule::isEnd)
.LUMIX_FUNC(AudioModule::setFrequency)
.LUMIX_FUNC(AudioModule::setVolume)
.LUMIX_FUNC(AudioModule::setEcho)
.LUMIX_FUNC(stop)
.LUMIX_FUNC(isEnd)
.LUMIX_FUNC(setFrequency)
.LUMIX_FUNC(setVolume)
.LUMIX_FUNC(setEcho)
.LUMIX_CMP(AmbientSound, "ambient_sound", "Audio / Ambient sound")
.LUMIX_FUNC_EX(AudioModule::pauseAmbientSound, "pause")
.LUMIX_FUNC_EX(AudioModule::resumeAmbientSound, "resume")

View File

@ -415,10 +415,51 @@ static i32 LUA_getNumProperties(reflection::ComponentBase* cmp) {
return cmp->props.size();
}
static i32 LUA_getNumFunctions(reflection::ComponentBase* cmp) {
static i32 LUA_getNumComponentFunctions(reflection::ComponentBase* cmp) {
return cmp->functions.size();
}
static i32 LUA_getNumFunctions() {
return reflection::allFunctions().size();
}
static reflection::FunctionBase* LUA_getFunction(i32 idx) {
return reflection::allFunctions()[idx];
}
static i32 LUA_getNextModule(lua_State* L) {
reflection::Module* module = LuaWrapper::checkArg<reflection::Module*>(L, 1);
if (module->next) lua_pushlightuserdata(L, module->next);
else lua_pushnil(L);
return 1;
}
i32 LUA_getThisTypeName(lua_State* L) {
reflection::FunctionBase* fn = LuaWrapper::checkArg<reflection::FunctionBase*>(L, 1);
StringView sv = fn->getThisTypeName();
lua_pushlstring(L, sv.begin, sv.size());
return 1;
}
i32 LUA_getReturnTypeName(lua_State* L) {
reflection::FunctionBase* fn = LuaWrapper::checkArg<reflection::FunctionBase*>(L, 1);
StringView sv = fn->getReturnTypeName();
lua_pushlstring(L, sv.begin, sv.size());
return 1;
}
static i32 LUA_getNumModuleFunctions(reflection::Module* module) {
return module->functions.size();
}
static reflection::FunctionBase* LUA_getModuleFunction(reflection::Module* module, i32 idx) {
return module->functions[idx];
}
static const char* LUA_getModuleName(reflection::Module* module) {
return module->name;
}
static i32 LUA_getPropertyType(reflection::PropertyBase* property) {
enum class PropertyType {
FLOAT,
@ -474,7 +515,7 @@ static reflection::PropertyBase* LUA_getProperty(reflection::ComponentBase* cmp,
return cmp->props[index];
}
static reflection::FunctionBase* LUA_getFunction(reflection::ComponentBase* cmp, u32 index) {
static reflection::FunctionBase* LUA_getComponentFunction(reflection::ComponentBase* cmp, u32 index) {
return cmp->functions[index];
}
@ -899,12 +940,12 @@ void registerEngineAPI(lua_State* L, Engine* engine)
LuaWrapper::createSystemFunction(L, "LumixReflection", "getComponent", &LuaWrapper::wrap<LUA_getComponent>);
LuaWrapper::createSystemFunction(L, "LumixReflection", "getNumComponents", &LuaWrapper::wrap<LUA_getNumComponents>);
LuaWrapper::createSystemFunction(L, "LumixReflection", "getNumProperties", &LuaWrapper::wrap<LUA_getNumProperties>);
LuaWrapper::createSystemFunction(L, "LumixReflection", "getNumFunctions", &LuaWrapper::wrap<LUA_getNumFunctions>);
LuaWrapper::createSystemFunction(L, "LumixReflection", "getNumComponentFunctions", &LuaWrapper::wrap<LUA_getNumComponentFunctions>);
LuaWrapper::createSystemFunction(L, "LumixReflection", "getComponentName", &LuaWrapper::wrap<LUA_getComponentName>);
LuaWrapper::createSystemFunction(L, "LumixReflection", "getComponentLabel", &LuaWrapper::wrap<LUA_getComponentLabel>);
LuaWrapper::createSystemFunction(L, "LumixReflection", "getComponentIcon", &LuaWrapper::wrap<LUA_getComponentIcon>);
LuaWrapper::createSystemFunction(L, "LumixReflection", "getProperty", &LuaWrapper::wrap<LUA_getProperty>);
LuaWrapper::createSystemFunction(L, "LumixReflection", "getFunction", &LuaWrapper::wrap<LUA_getFunction>);
LuaWrapper::createSystemFunction(L, "LumixReflection", "getComponentFunction", &LuaWrapper::wrap<LUA_getComponentFunction>);
LuaWrapper::createSystemFunction(L, "LumixReflection", "getFunctionName", &LuaWrapper::wrap<LUA_getFunctionName>);
LuaWrapper::createSystemFunction(L, "LumixReflection", "getFunctionArgCount", &LuaWrapper::wrap<LUA_getFunctionArgCount>);
LuaWrapper::createSystemFunction(L, "LumixReflection", "getFunctionReturnType", &LUA_getFunctionReturnType);
@ -912,6 +953,17 @@ void registerEngineAPI(lua_State* L, Engine* engine)
LuaWrapper::createSystemFunction(L, "LumixReflection", "getPropertyType", &LuaWrapper::wrap<LUA_getPropertyType>);
LuaWrapper::createSystemFunction(L, "LumixReflection", "getPropertyName", &LuaWrapper::wrap<LUA_getPropertyName>);
LuaWrapper::createSystemFunction(L, "LumixReflection", "getFirstModule", &LuaWrapper::wrap<reflection::getFirstModule>);
LuaWrapper::createSystemFunction(L, "LumixReflection", "getNextModule", &LUA_getNextModule);
LuaWrapper::createSystemFunction(L, "LumixReflection", "getThisTypeName", &LUA_getThisTypeName);
LuaWrapper::createSystemFunction(L, "LumixReflection", "getReturnTypeName", &LUA_getReturnTypeName);
LuaWrapper::createSystemFunction(L, "LumixReflection", "getNumModuleFunctions", &LuaWrapper::wrap<LUA_getNumModuleFunctions>);
LuaWrapper::createSystemFunction(L, "LumixReflection", "getModuleFunction", &LuaWrapper::wrap<LUA_getModuleFunction>);
LuaWrapper::createSystemFunction(L, "LumixReflection", "getModuleName", &LuaWrapper::wrap<LUA_getModuleName>);
LuaWrapper::createSystemFunction(L, "LumixReflection", "getNumFunctions", &LuaWrapper::wrap<LUA_getNumFunctions>);
LuaWrapper::createSystemFunction(L, "LumixReflection", "getFunction", &LuaWrapper::wrap<LUA_getFunction>);
LuaWrapper::createSystemFunction(L, "LumixAPI", "networkRead", &LUA_networkRead);
LuaWrapper::createSystemFunction(L, "LumixAPI", "packU32", &LUA_packU32);
LuaWrapper::createSystemFunction(L, "LumixAPI", "unpackU32", &LUA_unpackU32);

View File

@ -25,6 +25,14 @@ static Context& getContext() {
return ctx;
}
const char* declCodeToName(const char* decl_code) {
const char* c = decl_code;
while (*c) ++c;
while (*c != ':' && c > decl_code) --c;
if (*c == ':') ++c;
return c;
}
Array<FunctionBase*>& allFunctions() {
static Array<FunctionBase*> fncs(getGlobalAllocator());
return fncs;

View File

@ -70,6 +70,7 @@ LUMIX_ENGINE_API StableHash getPropertyHash(ComponentType cmp, const char* prope
LUMIX_ENGINE_API bool componentTypeExists(const char* id);
LUMIX_ENGINE_API ComponentType getComponentType(const char* id);
LUMIX_ENGINE_API ComponentType getComponentTypeFromHash(RuntimeHash hash);
LUMIX_ENGINE_API const char* declCodeToName(const char* decl_code);
struct ResourceAttribute : IAttribute
{
@ -568,7 +569,7 @@ auto& function(F func, const char* decl_code, const char* name)
allFunctions().push(&ret);
ret.function = func;
ret.decl_code = decl_code;
ret.name = name;
ret.name = name && name[0] ? name : declCodeToName(decl_code);
return ret;
}
@ -827,7 +828,7 @@ struct LUMIX_ENGINE_API builder {
builder& function(const char* name, const char* decl_code) {
auto* f = LUMIX_NEW(allocator, Function<decltype(F)>);
f->function = F;
f->name = name;
f->name = name && name[0] ? name : declCodeToName(decl_code);
f->decl_code = decl_code;
if (module->cmps.empty()) {
module->functions.push(f);

View File

@ -1314,8 +1314,8 @@ void GUIModule::reflect() {
.LUMIX_EVENT(GUIModule::rectHoveredOut)
.LUMIX_EVENT(GUIModule::rectMouseDown)
.LUMIX_EVENT(GUIModule::mousedButtonUnhandled)
.LUMIX_FUNC(GUIModule::getRectAt)
.LUMIX_FUNC(GUIModule::isOver)
.LUMIX_FUNC(getRectAt)
.LUMIX_FUNC(isOver)
.function<&GUIModuleImpl::getSystemPtr>("getSystem", "GUIModule::getSystem")
.LUMIX_CMP(RenderTarget, "gui_render_target", "GUI / Render taget")
.LUMIX_CMP(Text, "gui_text", "GUI / Text")

View File

@ -215,17 +215,8 @@ static void createClasses(lua_State* L) {
lua_setfield(L, -2, "__index"); // [LumixAPI, obj]
}
lua_pushlightuserdata(L, f); // [LumixAPI, obj, f]
if (f->name) {
lua_pushcclosure(L, luaMethodClosure, f->name, 1); // [LumixAPI, obj, closure]
lua_setfield(L, -2, f->name);
} else {
const char* fn_name = f->decl_code + strlen(f->decl_code);
while (*fn_name != ':' && fn_name != f->decl_code) --fn_name;
if (*fn_name == ':') ++fn_name;
lua_pushcclosure(L, luaMethodClosure, fn_name, 1); // [LumixAPI, obj, closure]
lua_setfield(L, -2, fn_name);
}
lua_pushcclosure(L, luaMethodClosure, f->name, 1); // [LumixAPI, obj, closure]
lua_setfield(L, -2, f->name);
lua_pop(L, 1);
}
lua_pop(L, 1);

View File

@ -3926,7 +3926,7 @@ void PhysicsModule::reflect() {
};
LUMIX_MODULE(PhysicsModuleImpl, "physics")
.LUMIX_FUNC(PhysicsModule::raycast)
.LUMIX_FUNC(raycast)
.LUMIX_CMP(D6Joint, "d6_joint", "Physics / Joint / D6")
.LUMIX_PROP(JointConnectedBody, "Connected body")
.LUMIX_PROP(JointAxisPosition, "Axis position")

View File

@ -50,7 +50,6 @@ GameView::GameView(StudioApp& app)
, m_is_mouse_captured(false)
, m_is_ingame_cursor(false)
, m_time_multiplier(1.0f)
, m_show_stats(false)
{
Engine& engine = app.getEngine();
auto f = &LuaWrapper::wrapMethodClosure<&GameView::forceViewport>;
@ -199,28 +198,6 @@ void GameView::setFullscreen(bool fullscreen)
m_is_fullscreen = fullscreen;
}
void GameView::onStatsGUI(const ImVec2& view_pos)
{
if (!m_show_stats || !m_is_open) return;
float toolbar_height = 24 + ImGui::GetStyle().FramePadding.y * 2;
ImVec2 v = view_pos;
v.x += ImGui::GetStyle().FramePadding.x;
v.y += ImGui::GetStyle().FramePadding.y + toolbar_height;
ImGui::SetNextWindowPos(v);
auto col = ImGui::GetStyle().Colors[ImGuiCol_WindowBg];
col.w = 0.3f;
ImGui::PushStyleColor(ImGuiCol_WindowBg, col);
ImGuiWindowFlags flags = ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoSavedSettings;
if (ImGui::Begin("###stats_overlay", nullptr, flags)) {
ImGui::LabelText("Resolution", "%dx%d", (int)m_size.x, (int)m_size.y);
}
ImGui::End();
ImGui::PopStyleColor();
}
void GameView::forceViewport(bool enable, int w, int h)
{
m_forced_viewport.enabled = enable;
@ -249,9 +226,6 @@ void GameView::controlsGUI(WorldEditor& editor) {
ImGui::SameLine();
if (ImGui::Button("Fullscreen")) setFullscreen(true);
}
ImGui::SameLine();
ImGui::Checkbox("Stats", &m_show_stats);
ImGui::SameLine();
m_pipeline->callLuaFunction("onGUI");
}
@ -327,6 +301,8 @@ void GameView::onGUI()
m_pipeline->setViewport(vp);
m_pipeline->render(false);
const gpu::TextureHandle texture_handle = m_pipeline->getOutput();
controlsGUI(editor);
if (texture_handle) {
if (gpu::isOriginBottomLeft()) {
@ -345,7 +321,6 @@ void GameView::onGUI()
m_size = ImGui::GetItemRectSize();
processInputEvents();
controlsGUI(editor);
}
}
@ -356,7 +331,6 @@ void GameView::onGUI()
}
ImGui::End();
ImGui::PopStyleVar();
if (is_game_view_visible) onStatsGUI(view_pos);
}

View File

@ -52,7 +52,6 @@ private:
void processInputEvents();
void onFullscreenGUI(WorldEditor& editor);
void setFullscreen(bool fullscreen);
void onStatsGUI(const ImVec2& view_pos);
void controlsGUI(WorldEditor& editor);
private:
@ -65,7 +64,6 @@ private:
bool m_is_mouse_captured;
bool m_is_ingame_cursor;
bool m_is_fullscreen;
bool m_show_stats;
bool m_was_game_mode = false;
os::CursorType m_cursor_type = os::CursorType::DEFAULT;
struct

View File

@ -3342,10 +3342,10 @@ void RenderModule::reflect() {
};
LUMIX_MODULE(RenderModuleImpl, "renderer")
.LUMIX_FUNC(RenderModule::addDebugCross)
.LUMIX_FUNC(RenderModule::addDebugLine)
.LUMIX_FUNC(RenderModule::addDebugTriangle)
.LUMIX_FUNC(RenderModule::setActiveCamera)
.LUMIX_FUNC(addDebugCross)
.LUMIX_FUNC(addDebugLine)
.LUMIX_FUNC(addDebugTriangle)
.LUMIX_FUNC(setActiveCamera)
.LUMIX_CMP(ProceduralGeometry, "procedural_geom", "Render / Procedural geometry")
.LUMIX_PROP(ProceduralGeometryMaterial, "Material").resourceAttribute(Material::TYPE)
.LUMIX_CMP(BoneAttachment, "bone_attachment", "Render / Bone attachment")