Giter Site home page Giter Site logo

Comments (2)

Rochet2 avatar Rochet2 commented on June 14, 2024

It would be nice to know what you are actually trying with this. There might be alternate existing solutions to achieve what you want.

Some of the problems you are hitting may be the following:

_G
A global variable (not a function) that holds the global environment (see ยง2.2). Lua itself does not use this variable; changing its value does not affect any environment, nor vice versa.

__index: The indexing access operation table[key]. This event happens when table is not a table or when key is not present in table.

Additionally, you are trying to use an object as a metatable, which may not be supported.
So maybe avoid using the usertype completely. Simply use normal tables for everything.
For example, probably want to change globals[sol::metatable_key] = NoopMetatable{}; to actually refer to a table.
Could you maybe tell what kind of errors and issues you are getting? Maybe some examples of how you try to invoke things in the global environment?

from sol2.

GasimGasimzada avatar GasimGasimzada commented on June 14, 2024

It would be nice to know what you are actually trying with this. There might be alternate existing solutions to achieve what you want.

I have a method that I inject to my script:

local my_var = input_vars.register("My variable", input_vars.types.String);

During actual execution of script, this method will read the "My variable" from some place in my game engine and provide it to the script. However, I have another step that is before the execution of the script -- in my game engine's editor. The idea is that, if I load this script into my editor, my editor evaluates this script with a different logic for input_vars.register -- instead of reading the runtime data for the script, it will automatically create UI controls in the editor that allows the user of the editor to store variables for the script. For example, the following script:

local value = input_vars.register('name', input_vars.types.AssetPrefab)

Creates an input that allows drag and dropping an asset that is available from the script:

image

This part works great with no issues. But imagine a scenario where a script uses a lot of APIs:

local value = input_vars.register('name', input_vars.types.AssetPrefab)

entity.animator:trigger("RunAnimation")
logger.debug("Debug logs")
game.on_update:connect(function(dt)
  print('Update called')
end)

local command = entity.input:get_command("Jump")
local value = entity.input:get_value_boolean(command)

existing_entity = entity_query:get_first_entity_by_name("My entity name")
new_entity =  entity_spawner:spawn_empty()

The editor only needs to evaluate input_vars.register('name', input_vars.types.AssetPrefab) and ignore everything else. This is where I want to make it so that anything other than input_vars global variable returns an empty table where every function and value returns a recursive table that does nothing. This way, whatever the developer provides will not do anything. To achieve this, this is what I am currently doing:

sol::state state;

// Create usertypes
NoopMetatable::create(state);
InputVars::create(state);

state["entity"] = NoopMetatable{};
state["entity_query"] = NoopMetatable{};
state["entity_spawner"] = NoopMetatable{};
state["logger"] = NoopMetatable{};
state["ui"] = NoopMetatable{};
state["table"] = NoopMetatable{};
state["game"] = NoopMetatable{};
state["input_vars"] = InputVars{};

I want to automate this part in a way that any field that is not input_vars is always noop.


Could you maybe tell what kind of errors and issues you are getting? Maybe some examples of how you try to invoke things in the global environment?

I am getting no errors. It is just the environment data that I set just do not get applied.

from sol2.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.