premake5 adding new complex fields - premake

I am trying to add a new premake5 field in my premake5 script but am having trouble understanding how to specify the field.kind .
I want to add a field that contains a list of (path, string ) pairs but can't work out how to specify the kind spec .
The documentation and examples are not particularly clear.
This is how I have registered my new field
premake.api.register( {
name = "mypathmappings",
scope = "config",
kind = "list:path:string", or "list:keyed:path:string"
}
)
and inside of a config scope I declare the field item like so
project myproject
mypathmappings { ["path/to/file1"] = "stringvalue1", ["path/to/file2"] = "stringvalue2"}
However when it comes to processing time I don't get what I'm expecting in the field:
function processpathmappings(cfg)
local pathmappings = cfg.mypathmappings
for path, value in pairs(pathmappings) do
--do something with the path and value but
--value is not a string as expected
end
end
Can someone explain how the complex kinds can be built up correctly from the field kinds registered in api.lua?
I get that "list:integer" specifies a list of integers but don't know how the "keyed" element works for example.

Right now, it is not possible to control the "kind" of the keys in a keyed value. The best you will be able to get with the current system is kind="keyed:string", which should give you the values (the strings) that you want, but the paths will not be processed by Premake (made absolute, etc.)
If it is feasible, you might want to flip it around to kind="keyed:path" and set the values like this:
mypathmappings { ["stringvalue1"] = "path/to/file1" }
But that relies on your string values being unique within a map.
In theory, Premake's field API could be extended to support kinds of keys; feel free to open a ticket or submit a pull request.

Related

Drupal 9 Computed Fields Module

I installed the computed fields modules and I'm trying to make a computed field hook for the below.
But I am not sure whether I put the code in the right place.
I just added the code below to the existing compute_field_api.php that comes with the compute field module. Is this the correct place to put this hook?
It doesn't seem to work and it doesn't display.
function computed_field_field_rating_average_compute($entity_type_manager, $entity, $fields, $delta)
{
// Get rating fields to compute
$facilities_and_services = $entity->field_facilities_and_services->value;
$fairway_rating = $entity->field_fairway_rating->value;
$recommendable_to_friends_rating = $entity->field_recommendable_to_friends->value;
$food_rating = $entity->field_food_rating->value;
$value_rating = $entity->field_value_rating->value;
$english_rating = $entity->field_english_rating->value;
$layout_rating = $entity->field_layout_rating->value;
$quality_rating = $entity->field_quality_rating->value;
$greens_rating = $entity->field_greens_rating->value;
$length_rating = $entity->field_length_rating->value;
// Set Computed field value
$value = ($facilities_and_services + $fairway_rating + $recommendable_to_friends_rating + $food_rating + $value_rating + $english_rating + $layout_rating + $quality_rating + $greens_rating + $length_rating) / 10;
return $value;
}
I tried to clear all the caches after adding this code. But it doesn't seem to work.
Had the same issue. Had to do the following:
Installed the module per the readme instructions (follow those).
Create the computed field function as you have above inside an enabled module (you may need to create a custom module for that). Note that the name of your custom module should not precede the function name (so it shouldn't be mymodule_computed_field_field_rating_average_compute, but rather as you have it above - i.e., how you've written your function is fine).
Flushed all caches.
Edit and save the node(s) where the new value should appear. That causes it to create a row in the field table.
After that, the computed value should appear in the saved content, and in views for that resaved content.
Note that it doesn't seem to be dynamic (like the old dynamic fields in D6 used to be), so it won't just magically appear for all existing content. To achieve that en-mass, I had to do a bit of back-end SQL to avoid having to manually re-save every entity (didn't want to do that for over 120 of 'em). Still figuring out if I have to do some other trickery to keep the field up-to-date despite my cache settings, as the value I'm attempting to display is dynamic, and not dependent upon the node in which the field exists...

Error during compiling: `identifier not found` (code C3861)

I have a field in my acore_characters table named 'rank' with a tinyint which ranges from 0 to 3 inclusive, based on player's progression. I need to read that value at both login and at certain specific circumstances.
I wrote the following PreparedStatement: "SELECT rank FROM acore_characters WHERE guid = ?" and then the code which is supposed to read that value:
uint16 GetCharactersRank(uint64 guid) {
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(mystatement);
stmt->setUInt32(0, GetGUID());
PreparedQueryResult result = CharacterDatabase.Query(stmt);
if (result) {
[...truncated]
and then fetching the result and so on, but then I get a code C8361 when compiling because 'GetGUID':identifier not found in Player.cpp file...what goes wrong? The other GetGUID calls throughout the file dont give this result. I'm not very fond of c++, any help is very appreciated.
It's not recommended to directly patch the core to add customisations to it. Instead, use modules.
An example can be found here: Is it possible to turn a core patch into a module for AzerothCore?
You can have a look and copy the skeleton-module and start modifying it to create your own.
In your case, you probably want to use the OnLogin player hook.

How to filter options in app maker's SuggestBox

I need to implement filtering for options in SuggestBox.
I've tried to do it differently, but none of my attempts worked out:
Using Model instead of Options/Value; Create calculated SQL model and pass the parameter for filtration:
Didn't work: suggestBox doesn't have event or anything to call before it loads data, so if you pass param for query before typing anything in -- it is not seen an you get an error:
Please provide value for the parameter ":Param" used in the query Error: Please provide value for the parameter ":Param" used in the query
Query for record suggest oracle: (Error) : Please provide value for the parameter ":Param" used in the query
Query for record suggest oracle failed.
Using Options/Value
It seems that it is impossible to have different properties of an object when passing it to Suggest Box. For example, I want user to see an user-friendly field Name and work with a record or at least record's Id, but if you specify Name as an option and Id as a value, Name is being written to a SuggestBox and now we get a validation error because Name is a string and Id is a Number.
Please help me realize where I'm wrong or show me a workaround for this.
Thanks!
I had the same issue as well. I gave up on the suggest box and created a pop up form. With a query builder model for the data source. The only thing i don't like is that it seems to be case sensitive.
something like:
YourFilterColumn startsWith? :Param
Add a table view and then you can add a text box and set the oninputchange event to:
widget.datasource.query.parameters.Param = widget.value;
widget.datasource.load();
Then you can start typing select the record you want and pass it back to your form with a button.
like this if it is a relational field:
app.pages.YourPage.children.YourForm.datasource.item.YourItem =
widget.datasource.item;
or something like this if you just need a value (haven't tested this):
app.pages.YourPage.children.YourForm.datasource.item.YourItem =
widget.datasource.item.YourValue;
Probably add a couple lines to clear the form out:
widget.root.descendants.TextBox1.value = "";
widget.datasource.query.parameters.Param = "";
widget.datasource.load();

Trying to figure out what this line of code means

This code is from a program I use to enter and track information. Numbers are entered as work orders (WO) to track clients. But one of the tables is duplicating the WO information. So I was trying to figure out a general outline of what this code is saying so that the problem can be fixed.
Here is the original line:
wc.dll?x3~emproc~datarecord~&ACTION=DISPLAY&TABLE+WORK&KEYVALUE=<%work.wo%&KEYFIELD=WO
What I think I understand of it so far, and I could be very wrong, is:
wc.dll?x3~emproc~datarecord~&ACTION
//No clue because don't know ~ means or using & (connects?Action)
=DISPLAY&TABLE+WORK&KEYVALUE
//Display of contents(what makes it pretty) and the value inside the table at that slot
=<work.wo%&KEYFIELD
//Calling the work from the WO object
=WO
//is Assigning whatever was placed into the WO field into the left side of the statement
I'll do my best to interpret the statement, with the limited information you've provided:
wc.dll is an instruction to invoke a DLL
? is introducing a list of parameters (like a query string in HTTP)
x3~emproc~datarecord~ seems like a reference to a function in the dll
& parameter separator
ACTION=DISPLAY set the ACTION parameter to the value DISPLAY
TABLE+WORK perhaps sets a couple of flags
KEYVALUE=<%work.wo% set the KEYVALUE parameter to the value of <%work.wo%
KEYFIELD=WO set the KEYFIELD parameter to the value WO
Hope that helps.

Extracting Requirements folder Tree structure from QC using API

I am trying to extract requirements from QC Requirement module. i could extract all requirements of a QC project but i would like to extract selected requirements only. So i need to give folder path and extract requirements accordingly.
Currently i use ReqFactory to extract Reqs from QC. Could you please help me or give me idea to extract requirmeents from selected folder path.
I tried Req Path and father id, but still it does not fulfill my need as some may have multiple sub folders under parent folders.
I assume you like to get all the child requirements of a requirement using the OTA API? The only solution I can offer is a bit clumsy. First you have to get the requirement where you want to start, e.g. "Requirements\Projects\ProjectX". How to achieve that is described in the OTA API Reference as an example of the ReqFactory object ("Find a specified requirement in a specified folder"). Or it is posted in this forum. If you know the ID of the start-requirement you can simply get the requirement with req_factory.Item(id).
When you have your requirement where you want to start, you can use the Find-method of the ReqFactory to get all its children, resp. all Requirement objects starting with the same path as the start-requirement. Here is an example-method in Ruby:
def list_all_child_requirements(start_req)
req_factory = #tdc.ReqFactory
req_path_strange_format = start_req.Field("RQ_REQ_PATH")
child_req_list = req_factory.Find(start_req.ID, "RQ_REQ_PATH", req_path_strange_format, 8)
child_req_list.each do |list_req|
puts list_req
end
end
The req_path_strange_format contains a String in the strange Quality Center notation like "AAAAAB". The Find-method starts from the start-requirement and searches all requirements which path starts with the same path as the path of the start-requirement. The parameter 8 means "starts with pattern" (described in the API Reference, Enum tagTDAPI_REQMODE). I just don't know how to access the Enum using Ruby, thats why the magic 8 is used... The Find-method returns a list with format "ID,NAME". From there it should be no problem to extract the requirements.
Doing the same directly in QC with a VAPI-XP-TEST and VB looks like that:
TDOutput.Clear
Dim reqPathStrangeFormat
Set reqF = tdConnection.ReqFactory
Set startReq = reqF.Item(14) ' ID of parent requirement
reqPathStrangeFormat = startReq.Field("RQ_REQ_PATH")
TDOutput.Print reqPathStrangeFormat
Set childReqList = reqF.Find(startReq.ID, "RQ_REQ_PATH", reqPathStrangeFormat, TDREQMODE_FIND_START_WITH)
For Each childReq in childReqList
TDOutput.Print childReq
Next
This code first prints some strange string "AAAAAB" or something similiar, then a list with "ID,NAME" of the requirements.

Resources